branch: externals/auctex
commit 7da1860c2a8cf7a2eb8f1596bf51af5532aa949b
Author: Ikumi Keita <ik...@ikumi.que.jp>
Commit: Ikumi Keita <ik...@ikumi.que.jp>

    Support starred section names
    
    * latex.el (LaTeX-section-level): Accept starred section names.
    Simplify.
    (LaTeX-section-name): Simplify.
    (LaTeX-section-heading): Include starred variants in completion
    candidates.
    * tex.el (LaTeX-command-section-boundaries): Arrange regexp to
    accept starred section names.
    Simplify.
    (LaTeX-command-section-change-level): Simplify.
    (): Arrange cookies for silencing compiler.
    * context.el (ConTeXt-numbered-section-name)
    (ConTeXt-unnumbered-section-name,ConTeXt-numbered-section-level)
    (ConTeXt-unnumbered-section-level):
    Simplify.
---
 context.el | 24 ++++--------------------
 latex.el   | 25 ++++++++++++-------------
 tex.el     | 20 ++++++++------------
 3 files changed, 24 insertions(+), 45 deletions(-)

diff --git a/context.el b/context.el
index c8a99b94c6..1eeda6a9ea 100644
--- a/context.el
+++ b/context.el
@@ -363,35 +363,19 @@ section."
 
 (defun ConTeXt-numbered-section-name (level)
   "Return the name of the section corresponding to LEVEL."
-  (let ((entry (TeX-member level ConTeXt-numbered-section-list
-                           (function (lambda (a b) (equal a (nth 1 b)))))))
-    (if entry
-        (nth 0 entry)
-      nil)))
+  (car (rassoc (list level) ConTeXt-numbered-section-list)))
 
 (defun ConTeXt-unnumbered-section-name (level)
   "Return the name of the section corresponding to LEVEL."
-  (let ((entry (TeX-member level ConTeXt-unnumbered-section-list
-                           (function (lambda (a b) (equal a (nth 1 b)))))))
-    (if entry
-        (nth 0 entry)
-      nil)))
+  (car (rassoc (list level) ConTeXt-unnumbered-section-list)))
 
 (defun ConTeXt-numbered-section-level (name)
   "Return the level of the section NAME."
-  (let ((entry (TeX-member name ConTeXt-numbered-section-list
-                           (function (lambda (a b) (equal a (nth 0 b)))))))
-    (if entry
-        (nth 1 entry)
-      nil)))
+  (cadr (assoc name ConTeXt-numbered-section-list)))
 
 (defun ConTeXt-unnumbered-section-level (name)
   "Return the level of the section NAME."
-  (let ((entry (TeX-member name ConTeXt-unnumbered-section-list
-                           (function (lambda (a b) (equal a (nth 0 b)))))))
-    (if entry
-        (nth 1 entry)
-      nil)))
+  (cadr (assoc name ConTeXt-unnumbered-section-list)))
 
 
 ;;; Section Hooks.
diff --git a/latex.el b/latex.el
index 01436f53bd..ac900673dd 100644
--- a/latex.el
+++ b/latex.el
@@ -259,20 +259,14 @@ used in style files."
 
 (defun LaTeX-section-name (level)
   "Return the name of the section corresponding to LEVEL."
-  (let ((entry (TeX-member level LaTeX-section-list
-                           (lambda (a b) (equal a (nth 1 b))))))
-    (if entry
-        (nth 0 entry)
-      nil)))
+  (car (rassoc (list level) LaTeX-section-list)))
 
 (defun LaTeX-section-level (name)
-  "Return the level of the section NAME."
-  (let ((entry (TeX-member name LaTeX-section-list
-                           (lambda (a b) (equal a (nth 0 b))))))
-
-    (if entry
-        (nth 1 entry)
-      nil)))
+  "Return the level of the section NAME.
+NAME can be starred variant."
+  (if (string-suffix-p "*" name)
+      (setq name (substring-no-properties name 0 -1)))
+  (cadr (assoc name LaTeX-section-list)))
 
 (defcustom TeX-outline-extra nil
   "List of extra TeX outline levels.
@@ -474,7 +468,12 @@ Insert this hook into `LaTeX-section-hook' to allow the 
user to change
 the name of the sectioning command inserted with \\[LaTeX-section]."
   (let ((string (completing-read
                  (concat "Level (default " LaTeX-name "): ")
-                 LaTeX-section-list
+                 (append
+                  ;; Include starred variants in candidates.
+                  (mapcar (lambda (sct)
+                            (list (concat (car sct) "*")))
+                          LaTeX-section-list)
+                  LaTeX-section-list)
                  nil nil nil nil LaTeX-name)))
     ;; Update LaTeX-name
     (if (not (zerop (length string)))
diff --git a/tex.el b/tex.el
index 2dfb7a7654..f7b822f5f2 100644
--- a/tex.el
+++ b/tex.el
@@ -56,6 +56,7 @@
                   (bus service path interface signal handler &rest args))
 (declare-function LaTeX-environment-list "latex" nil)
 (declare-function LaTeX-bibliography-list "latex" nil)
+(declare-function LaTeX-section-name "latex" (level))
 (declare-function comint-exec "ext:comint"
                   (buffer name command startfile switches))
 (declare-function comint-mode "ext:comint" nil)
@@ -91,7 +92,6 @@
 (defvar LaTeX-optcl)
 (defvar LaTeX-optop)
 (defvar LaTeX-largest-level)
-(defvar LaTeX-section-list)
 ;; tex-ispell.el
 (defvar TeX-ispell-verb-delimiters)
 ;; Others:
@@ -9077,8 +9077,7 @@ Initialize it to `LaTeX-largest-level' if needed."
 determine the current section by `LaTeX-command-section'.
 The levels are defined by `LaTeX-section-list'."
   (interactive "p")
-  (let ((old-level (car (rassoc (list (LaTeX-command-section-level))
-                                LaTeX-section-list))))
+  (let ((old-level (LaTeX-section-name (LaTeX-command-section-level))))
     (setq LaTeX-command-section-level (+ LaTeX-command-section-level arg))
     (cond
      ((> LaTeX-command-section-level 6)
@@ -9088,8 +9087,8 @@ The levels are defined by `LaTeX-section-list'."
       (setq LaTeX-command-section-level 0)
       (message "Cannot enlarge LaTeX-command-section-level above part."))
      (t (message "Changed level from %s to %s."
-                 old-level (car (rassoc (list LaTeX-command-section-level)
-                                        LaTeX-section-list)))))))
+                 old-level (LaTeX-section-name
+                            LaTeX-command-section-level))))))
 
 (defun LaTeX-command-section-boundaries ()
   "Return the boundaries of the current section as (start . end).
@@ -9097,13 +9096,10 @@ The section is determined by 
`LaTeX-command-section-level'."
   (let* ((case-fold-search nil)
          (rx (concat "\\\\" (regexp-opt
                              (mapcar
-                              (lambda (level)
-                                (car (rassoc (list level) LaTeX-section-list)))
-                              (let (r)
-                                (dotimes (i (1+ (LaTeX-command-section-level)))
-                                  (push i r))
-                                r)))
-                     "{")))
+                              #'LaTeX-section-name
+                              (number-sequence
+                               0 (LaTeX-command-section-level))))
+                     "\\*?{")))
     (cons (save-excursion
             (re-search-backward rx nil t)
             (point))


Reply via email to