[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 270/299: Manage auto insertion of labels.
From: |
Stefan Monnier |
Subject: |
[elpa] 270/299: Manage auto insertion of labels. |
Date: |
Sun, 02 Nov 2014 03:11:55 +0000 |
monnier pushed a commit to branch externals/auctex
in repository elpa.
commit 6da54fae3d0871c993a5d16b912b8b586e8770cb
Author: Mosè Giordano <address@hidden>
Date: Mon Aug 11 18:22:12 2014 +0200
Manage auto insertion of labels.
* latex.el (LaTeX-auto-insert-label): New customizable variable.
(LaTeX-label): Use it.
* doc/auctex.texi (Environments): Document
`LaTeX-auto-insert-label'.
* doc/changes.texi: Mention `LaTeX-auto-insert-label'. Fix a
couple of bad-boxes in the PDF output of the manual.
---
ChangeLog | 11 ++++++
doc/auctex.texi | 34 ++++++++++++++++++
doc/changes.texi | 13 +++++--
latex.el | 100 ++++++++++++++++++++++++++++++++++++------------------
4 files changed, 121 insertions(+), 37 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 2be1b61..dbd0e53 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2014-08-11 Mos� Giordano <address@hidden>
+
+ * latex.el (LaTeX-auto-insert-label): New customizable variable.
+ (LaTeX-label): Use it.
+
+ * doc/auctex.texi (Environments): Document
+ `LaTeX-auto-insert-label'.
+
+ * doc/changes.texi: Mention `LaTeX-auto-insert-label'. Fix a
+ couple of bad-boxes in the PDF output of the manual.
+
2014-07-25 Tassilo Horn <address@hidden>
* latex.el (LaTeX-largest-level-set): Adapt
diff --git a/doc/auctex.texi b/doc/auctex.texi
index 7261705..37c7366 100644
--- a/doc/auctex.texi
+++ b/doc/auctex.texi
@@ -848,6 +848,40 @@ prefix argument), the current environment is modified and
no new
environment is inserted.
@end deffn
address@hidden helps you adding labels to environments which use them, such
+as @samp{equation}, @samp{figure}, @samp{table}, address@hidden When you
+insert one of the supported environments with @kbd{C-c C-e}, you will be
+automatically prompted for a label. If you want to select the
+environments for which to automatically insert or not the label,
+customize the @code{LaTeX-auto-insert-label} variable.
address@hidden LaTeX-auto-insert-label
+Control whether @code{LaTeX-environment} (@kbd{C-c C-e}) should insert a
+label. If nil, never inserts a label, if t always inserts a label and
+this the default.
+
+This variable may also be a cons cell, to whitelist or blacklist the
+environments for which a label should or should not be inserted. The
+car can be either nil or t. In the former case,
address@hidden never inserts labels except for the
+environments listed in the cdr; in the latter case
address@hidden always inserts labels except for the
+environments listed in the cdr. In any cases, you can manually insert
+at point a label inside an environment with @kbd{C-c C-m label
address@hidden, as usual.
+
+For example, the value
address@hidden
+(t . "equation")
address@hidden lisp
+makes @AUCTeX{} always prompt you for a label except for the
address@hidden environment. Instead with the value
address@hidden
+(nil . "caption" "figure")
address@hidden lisp
+you will be prompted for a label only for @samp{caption} and
address@hidden environments.
address@hidden defopt
+
As a default selection, @AUCTeX{} will suggest the environment last
inserted or, as the first choice the value of the variable
@code{LaTeX-default-environment}.
diff --git a/doc/changes.texi b/doc/changes.texi
index b408b47..3ce9d34 100644
--- a/doc/changes.texi
+++ b/doc/changes.texi
@@ -26,7 +26,7 @@ by the TeX compiler can be opened with @kbd{M-x
TeX-error-overview
@item
Style file authors are encouraged to distinguish common from expert
-macros/environments, and mark the latter using
+macros and environments, and mark the latter using
@code{TeX-declare-expert-macros} and
@code{LaTeX-declare-expert-environments}.
@@ -53,9 +53,10 @@ non-nil. Completion for class options of the standard
@LaTeX{} classes
is provided as well.
@item
-New user options @code{LaTeX-default-author}, @code{TeX-date-format},
address@hidden, @code{LaTeX-fontspec-arg-font-search},
-and @code{LaTeX-fontspec-font-list-default}. A new possible value
+New user options @code{LaTeX-default-author},
address@hidden,
address@hidden, @code{TeX-date-format}, and
address@hidden A new possible value
(@code{show-all-optional-args}) for
@code{TeX-insert-macro-default-style} was added. The default value of
@code{TeX-source-correlate-method} has been changed.
@@ -127,6 +128,10 @@ per file basis using the @code{TeX-command-extra-options}
option.
@item
Now @kbd{C-c C-e document @key{RET}}, in an empty document, prompts for
@samp{\usepackage} macros in addition to @samp{\documentclass}.
+
address@hidden
+You can customize for which environments a label should be automatically
+inserted or not through the user option @code{LaTeX-auto-insert-label}.
@end itemize
@heading News since 11.87
diff --git a/latex.el b/latex.el
index c798cda..d1ac41f 100644
--- a/latex.el
+++ b/latex.el
@@ -835,6 +835,28 @@ the label inserted, or nil if no label was inserted."
:group 'LaTeX-label
:type 'function)
+(defcustom LaTeX-auto-insert-label t
+ "Control whether `LaTeX-label' function should insert a label.
+If nil, never inserts a label, if t always inserts a label.
+
+This variable may also be a cons cell, to whitelist or blacklist
+the environments for which a label should or should not be
+inserted. The CAR can be either nil or t. In the former case,
+`LaTeX-label' never inserts labels except for the environments
+listed in the CDR; in the latter case `LaTeX-label' always
+inserts labels except for the environments listed in the CDR."
+ :group 'LaTeX-label
+ :type '(choice (const :tag "Insert labels" t)
+ (const :tag "Do not insert labels" nil)
+ (cons :tag "Whitelist or blacklist environments"
+ (choice
+ (const
+ :tag "Insert labels except for environments..." t)
+ (const
+ :tag "Do not insert labels except for environments..."
+ nil))
+ (repeat (string :tag "Environment")))))
+
(defcustom LaTeX-figure-label "fig:"
"*Default prefix to figure labels."
:group 'LaTeX-label
@@ -923,39 +945,51 @@ either the prefix or a symbol referring to one."
(defun LaTeX-label (environment)
"Insert a label for ENVIRONMENT at point.
-If `LaTeX-label-function' is a valid function, LaTeX label will transfer the
-job to this function."
- (let (label)
- (if (and (boundp 'LaTeX-label-function)
- LaTeX-label-function
- (fboundp LaTeX-label-function))
-
- (setq label (funcall LaTeX-label-function environment))
- (let ((prefix
- (or (cdr (assoc environment LaTeX-label-alist))
- (if (assoc environment LaTeX-section-list)
- (if (stringp LaTeX-section-label)
- LaTeX-section-label
- (and (listp LaTeX-section-label)
- (cdr (assoc environment LaTeX-section-label))))
- ""))))
- (when prefix
- (when (symbolp prefix)
- (setq prefix (symbol-value prefix)))
- ;; 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))
- ;; No label or empty string entered?
- (if (or (string= prefix label)
- (string= "" label))
- (setq label nil)
- (insert TeX-esc "label" TeX-grop label TeX-grcl))))
- (if label
- (progn
- (LaTeX-add-labels label)
- label)
- nil))))
+`LaTeX-auto-insert-label' controls whether the label should
+actually be inserted. If `LaTeX-label-function' is a valid
+function, LaTeX label will transfer the job to this function."
+ (if (cond
+ ;; `LaTeX-auto-insert-label' is boolean.
+ ((booleanp LaTeX-auto-insert-label)
+ LaTeX-auto-insert-label)
+ ;; `LaTeX-auto-insert-label' is a whitelist or a blacklist.
+ ((consp LaTeX-auto-insert-label)
+ (if (member environment (cdr LaTeX-auto-insert-label))
+ (null (car LaTeX-auto-insert-label))
+ (car LaTeX-auto-insert-label)))
+ ;; In any other cases, insert the label.
+ (t))
+ (let (label)
+ (if (and (boundp 'LaTeX-label-function)
+ LaTeX-label-function
+ (fboundp LaTeX-label-function))
+
+ (setq label (funcall LaTeX-label-function environment))
+ (let ((prefix
+ (or (cdr (assoc environment LaTeX-label-alist))
+ (if (assoc environment LaTeX-section-list)
+ (if (stringp LaTeX-section-label)
+ LaTeX-section-label
+ (and (listp LaTeX-section-label)
+ (cdr (assoc environment LaTeX-section-label))))
+ ""))))
+ (when prefix
+ (when (symbolp prefix)
+ (setq prefix (symbol-value prefix)))
+ ;; 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))
+ ;; No label or empty string entered?
+ (if (or (string= prefix label)
+ (string= "" label))
+ (setq label nil)
+ (insert TeX-esc "label" TeX-grop label TeX-grcl))))
+ (if label
+ (progn
+ (LaTeX-add-labels label)
+ label)
+ nil)))))
(defun LaTeX-env-figure (environment)
"Create ENVIRONMENT with \\caption and \\label commands."
- [elpa] 264/299: Fix some runtime issues in XEmacs., (continued)
- [elpa] 264/299: Fix some runtime issues in XEmacs., Stefan Monnier, 2014/11/01
- [elpa] 248/299: Implement TeX-previous-error., Stefan Monnier, 2014/11/01
- [elpa] 267/299: Remove .cvsignore and tests from the release tarball., Stefan Monnier, 2014/11/01
- [elpa] 265/299: Fix other runtime issues in XEmacs and Emacs 21., Stefan Monnier, 2014/11/01
- [elpa] 269/299: Fix outline promotion/demotion., Stefan Monnier, 2014/11/01
- [elpa] 261/299: Hide some entries of the Command menu when not available., Stefan Monnier, 2014/11/01
- [elpa] 256/299: Implement error overview., Stefan Monnier, 2014/11/01
- [elpa] 271/299: Keep error overview window if View command is run., Stefan Monnier, 2014/11/01
- [elpa] 275/299: Font-lock fix for verbatim environment args., Stefan Monnier, 2014/11/01
- [elpa] 274/299: Adapt mathtools.el to latest amsmath.el changes., Stefan Monnier, 2014/11/01
- [elpa] 270/299: Manage auto insertion of labels.,
Stefan Monnier <=
- [elpa] 272/299: Rename LaTeX-auto-insert-label and document its use for sections., Stefan Monnier, 2014/11/01
- [elpa] 277/299: Change Vincent's email address in ChangeLog., Stefan Monnier, 2014/11/01
- [elpa] 268/299: Add customizable option for default date format., Stefan Monnier, 2014/11/01
- [elpa] 273/299: Change again method to determine whether a label should be inserted., Stefan Monnier, 2014/11/01
- [elpa] 266/299: Auto insertion of ampersands., Stefan Monnier, 2014/11/01
- [elpa] 280/299: Bugfix in file name expansion., Stefan Monnier, 2014/11/01
- [elpa] 283/299: Document TeX-add-style-hook's new 3rd argument., Stefan Monnier, 2014/11/01
- [elpa] 279/299: Add test for the %` expander., Stefan Monnier, 2014/11/01
- [elpa] 281/299: Remove defalias docstring arg., Stefan Monnier, 2014/11/01
- [elpa] 278/299: Fix the expansion of %' in TeX-expand-list., Stefan Monnier, 2014/11/01