monnier pushed a commit to branch externals/auctex in repository elpa. commit 9a09a35edf990d718c34da756f12df5a967aa6d3 Author: Mosè Giordano <giordano.m...@libero.it> Date: Sun Oct 6 20:40:47 2013 +0200
Add new customizable variable TeX-insert-braces-alist. * tex.el (TeX-insert-braces-alist): New customizable variable. (TeX-insert-braces): Mention it in doc-string. (TeX-parse-macro): Use `TeX-insert-braces-alist'. * style/booktabs.el: Update copyright years. (LaTeX-booktabs-arg-paren): Let-bind `TeX-arg-opening-brace' and `TeX-arg-closing-brace' instead of `<' and `>'. ("booktabs"): Add `toprule', `midrule', and `bottomrule' macros to `TeX-insert-braces-alist'. ("booktabs"): Add a dummy `ignore' in `cmidrule' macro in order to reset `last-optional-rejected' to nil. * doc/auctex.texi (Completion): Document `TeX-insert-braces-alist'. * doc/changes.texi: Mention `TeX-insert-braces-alist'. --- ChangeLog | 19 +++++++++++++++++++ doc/auctex.texi | 13 +++++++++++++ doc/changes.texi | 4 ++-- style/booktabs.el | 22 +++++++++++++--------- tex.el | 39 +++++++++++++++++++++++++++++++-------- 5 files changed, 78 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3ef787e..4093ce3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2013-10-06 Mos� Giordano <giordano.m...@libero.it> + + * tex.el (TeX-insert-braces-alist): New customizable variable. + (TeX-insert-braces): Mention it in doc-string. + (TeX-parse-macro): Use `TeX-insert-braces-alist'. + + * style/booktabs.el: Update copyright years. + (LaTeX-booktabs-arg-paren): Let-bind `TeX-arg-opening-brace' and + `TeX-arg-closing-brace' instead of `<' and `>'. + ("booktabs"): Add `toprule', `midrule', and `bottomrule' macros to + `TeX-insert-braces-alist'. + ("booktabs"): Add a dummy `ignore' in `cmidrule' macro in order to + reset `last-optional-rejected' to nil. + + * doc/auctex.texi (Completion): Document + `TeX-insert-braces-alist'. + + * doc/changes.texi: Mention `TeX-insert-braces-alist'. + 2013-09-27 Mos� Giordano <giordano.m...@libero.it> * latex.el (TeX-arg-insert-braces): : Move diff --git a/doc/auctex.texi b/doc/auctex.texi index 8a1fc1a..4156a0b 100644 --- a/doc/auctex.texi +++ b/doc/auctex.texi @@ -1107,6 +1107,19 @@ This can be stopped by entering @code{LaTeX-math-mode}, If non-nil, append a empty pair of braces after inserting a macro. @end defopt +@defopt TeX-insert-braces-alist +Control the insertion of a pair of braces after a macro on a per macro +basis. + +This variable is an alist. Each element is a cons cell, whose car is +the macro name, and the cdr is non-nil or nil, depending on whether a +pair of braces should be, respectively, appended or not to the macro. + +If a macro has an element in this variable, @code{TeX-parse-macro} will +use its value to decided what to do, whatever the value of the variable +@code{TeX-insert-braces}. +@end defopt + Completions work because @AUCTeX{} can analyze @TeX{} files, and store symbols in Emacs Lisp files for later retrieval. @xref{Automatic}, for more information. diff --git a/doc/changes.texi b/doc/changes.texi index a7ed8db..df69cb4 100644 --- a/doc/changes.texi +++ b/doc/changes.texi @@ -30,8 +30,8 @@ Completion for class options of the standard @LaTeX{} classes is provided as well. @item -New user option @code{LaTeX-default-author}. It is used as initial -input to @kbd{C-c RET author RET}. +New user options @code{LaTeX-default-author} and +@code{TeX-insert-braces-alist}. @item @samp{biblatex} support was greatly expanded. If parsing is enabled, diff --git a/style/booktabs.el b/style/booktabs.el index e126872..ee19459 100644 --- a/style/booktabs.el +++ b/style/booktabs.el @@ -1,6 +1,6 @@ ;;; booktabs.el -- AUCTeX style for booktabs.sty -;; Copyright (C) 2003, 2004 Free Software Foundation, Inc. +;; Copyright (C) 2003, 2004, 2013 Free Software Foundation, Inc. ;; Author: Ralf Angeli <ang...@iwi.uni-sb.de> ;; Maintainer: auctex-de...@gnu.org @@ -34,23 +34,27 @@ "Prompt for a value and use parentheses when it is inserted. If OPTIONAL is non-nil the parameter is labeled as optional. PROMPT is the value of the prompt to be shown." - (let ((< "\(") - (> "\)")) + (let ((TeX-arg-opening-brace "\(") + (TeX-arg-closing-brace "\)")) (TeX-parse-argument optional prompt))) (TeX-add-style-hook "booktabs" (lambda () - + ;; Do not append an empty group to toprule, midrule, and bottomrule macros, + ;; otherwise one gets a wrong spacing in the table. + (setq TeX-insert-braces-alist (append TeX-insert-braces-alist + '(("toprule" . nil) + ("midrule" . nil) + ("bottomrule" . nil)))) ;; New symbols (TeX-add-symbols '("toprule" [ "Thickness" ]) '("midrule" [ "Thickness" ]) '("bottomrule" [ "Thickness" ]) - ;; FIXME: The qestion for the trim parameter will only be asked if - ;; a value for the thickness parameter was given. Is this a - ;; feature of `TeX-parse-arguments'? - '("cmidrule" [ "Thickness" ] [ LaTeX-booktabs-arg-paren "Trim" ] + ;; The `ignore' resets `last-optional-rejected' to nil so that the trim + ;; argument is prompted also when the thickness is skipped. + '("cmidrule" [ "Thickness" ] (ignore) [ LaTeX-booktabs-arg-paren "Trim" ] "Column(s)") '("addlinespace" [ "Height" ]) '("morecmidrules") @@ -69,6 +73,6 @@ PROMPT is the value of the prompt to be shown." 'function)))) (defvar LaTeX-booktabs-package-options nil - "Package options for the booktabs package.") + "Package options for the booktabs package.") ;;; booktabs.el ends here diff --git a/tex.el b/tex.el index 66e22cd..1ab9647 100644 --- a/tex.el +++ b/tex.el @@ -2587,10 +2587,27 @@ Or alternatively: (make-variable-buffer-local 'TeX-default-macro) (defcustom TeX-insert-braces t - "*If non-nil, append a empty pair of braces after inserting a macro." + "*If non-nil, append a empty pair of braces after inserting a macro. + +See also `TeX-insert-braces-alist'." :group 'TeX-macro :type 'boolean) +(defcustom TeX-insert-braces-alist nil + "Alist of macros to which braces should or should not be appended. + +Each element is a cons cell, whose CAR is the macro name, and the +CDR is non-nil or nil, depending on whether a pair of braces +should be, respectively, appended or not to the macro. + +If a macro has an element in this variable, `TeX-parse-macro' +will use its value to decided what to do, whatever the value of +the variable `TeX-insert-braces'." + :group 'TeX-macro + :type '(repeat (cons (string :tag "Macro name") + (boolean :tag "Append braces?")))) +(make-variable-buffer-local 'TeX-insert-braces-alist) + (defcustom TeX-insert-macro-default-style 'show-optional-args "Specifies whether `TeX-insert-macro' will ask for all optional arguments. @@ -2713,13 +2730,19 @@ type of ARGS: (cond ((marker-position exit-mark) (goto-char (marker-position exit-mark)) (set-marker exit-mark nil)) - ((and TeX-insert-braces - ;; Do not add braces if the argument is 0 or -1. - (not (and (= (safe-length args) 1) - (numberp (car args)) - (<= (car args) 0))) - (equal position (point)) - (string-match "[a-zA-Z]+" symbol)) + ((let ((element (assoc symbol TeX-insert-braces-alist))) + ;; If in `TeX-insert-braces-alist' there is an element associated + ;; to the current macro, use its value to decide whether inserting + ;; a pair of braces, otherwise use the standard criterion. + (if element + (cdr element) + (and TeX-insert-braces + ;; Do not add braces if the argument is 0 or -1. + (not (and (= (safe-length args) 1) + (numberp (car args)) + (<= (car args) 0))) + (equal position (point)) + (string-match "[a-zA-Z]+" symbol)))) (if (texmathp) (when (TeX-active-mark) (insert TeX-grop)