emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/auctex a770edc 06/10: New function to read labels.


From: Tassilo Horn
Subject: [elpa] externals/auctex a770edc 06/10: New function to read labels.
Date: Fri, 28 Aug 2015 08:54:52 +0000

branch: externals/auctex
commit a770edca8be6f36584e013e5f2f6a151da1328a7
Author: Mosè Giordano <address@hidden>
Commit: Tassilo Horn <address@hidden>

    New function to read labels.
    
    * latex.el (LaTeX-label): Mention in the docstring the returned
    value.  Let-bind `TeX-read-label-prefix' and use `TeX-read-label'
    to read the label.
    (TeX-read-label-prefix): New variable.
    (TeX-read-label): New function.
    (TeX-arg-label): Use `TeX-read-label' and mention
    `TeX-read-label-prefix' in docstring.
    (TeX-arg-define-label): Mention `TeX-read-label-prefix' in
    docstring.
---
 ChangeLog |   12 +++++++++
 latex.el  |   75 +++++++++++++++++++++++++++++++++++++-----------------------
 2 files changed, 58 insertions(+), 29 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 3785df4..8d3293f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2015-08-19  Mos� Giordano  <address@hidden>
+
+       * latex.el (LaTeX-label): Mention in the docstring the returned
+       value.  Let-bind `TeX-read-label-prefix' and use `TeX-read-label'
+       to read the label.
+       (TeX-read-label-prefix): New variable.
+       (TeX-read-label): New function.
+       (TeX-arg-label): Use `TeX-read-label' and mention
+       `TeX-read-label-prefix' in docstring.
+       (TeX-arg-define-label): Mention `TeX-read-label-prefix' in
+       docstring.
+
 2015-08-14  Arash Esbati  <address@hidden>
 
        * latex.el (LaTeX-common-initialization): Fix the subgroup number
diff --git a/latex.el b/latex.el
index 8561535..8f613c2 100644
--- a/latex.el
+++ b/latex.el
@@ -993,35 +993,36 @@ you will be always prompted for a label, with an empty 
default
 prefix.
 
 If `LaTeX-label-function' is a valid function, LaTeX label will
-transfer the job to this function."
-  (let ((prefix (cond
-                ((eq type 'environment)
-                 (cdr (assoc name LaTeX-label-alist)))
-                ((eq type 'section)
-                 (if (assoc name LaTeX-section-list)
-                     (if (stringp LaTeX-section-label)
-                         LaTeX-section-label
-                       (and (listp LaTeX-section-label)
-                            (cdr (assoc name LaTeX-section-label))))
-                   ""))
-                ((null type)
-                 "")
-                (t
-                 nil)))
+transfer the job to this function.
+
+The inserted label is returned, nil if it is empty."
+  (let ((TeX-read-label-prefix
+        (cond
+         ((eq type 'environment)
+          (cdr (assoc name LaTeX-label-alist)))
+         ((eq type 'section)
+          (if (assoc name LaTeX-section-list)
+              (if (stringp LaTeX-section-label)
+                  LaTeX-section-label
+                (and (listp LaTeX-section-label)
+                     (cdr (assoc name LaTeX-section-label))))
+            ""))
+         ((null type)
+          "")
+         (t
+          nil)))
        label)
-    (when (symbolp prefix)
-      (setq prefix (symbol-value prefix)))
-    (when prefix
+    (when (symbolp TeX-read-label-prefix)
+      (setq TeX-read-label-prefix (symbol-value TeX-read-label-prefix)))
+    (when TeX-read-label-prefix
       (if (and (boundp 'LaTeX-label-function)
               LaTeX-label-function
               (fboundp LaTeX-label-function))
          (setq label (funcall LaTeX-label-function name))
        ;; Use completing-read as we do with `C-c C-m \label RET'
-       (setq label (completing-read
-                    (TeX-argument-prompt t nil "What label")
-                    (LaTeX-label-list) nil nil prefix))
+       (setq label (TeX-read-label t "What label" t))
        ;; No label or empty string entered?
-       (if (or (string= prefix label)
+       (if (or (string= TeX-read-label-prefix label)
                (string= "" label))
            (setq label nil)
          (insert TeX-esc "label" TeX-grop label TeX-grcl))
@@ -1773,17 +1774,32 @@ If OPTIONAL is non-nil, insert the resulting value as 
an optional
 argument, otherwise as a mandatory one."
   (TeX-argument-insert (eval args) optional))
 
-(defun TeX-arg-label (optional &optional prompt definition)
-  "Prompt for a label completing with known labels.
+(defvar TeX-read-label-prefix nil
+  "Initial input for the label in `TeX-read-label.'")
+
+(defun TeX-read-label (optional &optional prompt definition)
+  "Prompt for a label completing with known labels and return it.
 If OPTIONAL is non-nil, insert the resulting value as an optional
 argument, otherwise as a mandatory one.  Use PROMPT as the prompt
 string.  If DEFINITION is non-nil, add the chosen label to the
-list of defined labels."
-  (let ((label (completing-read (TeX-argument-prompt optional prompt "Key")
-                               (LaTeX-label-list))))
+list of defined labels.  `TeX-read-label-prefix' is used as
+initial input for the label."
+  (let ((label (completing-read
+               (TeX-argument-prompt optional prompt "Key")
+               (LaTeX-label-list) nil nil TeX-read-label-prefix)))
     (if (and definition (not (string-equal "" label)))
        (LaTeX-add-labels label))
-    (TeX-argument-insert label optional optional)))
+    label))
+
+(defun TeX-arg-label (optional &optional prompt definition)
+  "Prompt for a label completing with known labels.
+If OPTIONAL is non-nil, insert the resulting value as an optional
+argument, otherwise as a mandatory one.  Use PROMPT as the prompt
+string.  If DEFINITION is non-nil, add the chosen label to the
+list of defined labels.  `TeX-read-label-prefix' is used as
+initial input for the label."
+  (TeX-argument-insert
+   (TeX-read-label optional prompt definition) optional optional))
 
 (defvar reftex-ref-macro-prompt)
 
@@ -1948,7 +1964,8 @@ string."
   "Prompt for a label completing with known labels.
 If OPTIONAL is non-nil, insert the resulting value as an optional
 argument, otherwise as a mandatory one.  Use PROMPT as the prompt
-string."
+string.  `TeX-read-label-prefix' is used as initial input for the
+label."
   (TeX-arg-label optional prompt t))
 
 (defun TeX-arg-define-macro (optional &optional prompt)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]