branch: main commit 3d14ff325f4e0159e2f1fb54079ff5e4078c87f6 Merge: 3242bb7a a4a8140a Author: Tassilo Horn <t...@gnu.org> Commit: Tassilo Horn <t...@gnu.org>
Merge branch 'master' into externals/auctex --- font-latex.el | 24 +++++- latex.el | 7 ++ style/natbib.el | 242 ++++++++++++++++++++++++++++++++++---------------------- tex.el | 10 +++ 4 files changed, 188 insertions(+), 95 deletions(-) diff --git a/font-latex.el b/font-latex.el index fb7f8d6f..a7982c58 100644 --- a/font-latex.el +++ b/font-latex.el @@ -1258,7 +1258,11 @@ triggers Font Lock to recognize the change." (set (make-local-variable 'lookup-syntax-properties) t)) (setq defaults (append defaults variables))) ;; Set the defaults. - (setq font-lock-defaults defaults))) + (setq font-lock-defaults defaults)) + + ;; Make sure fontification will be refreshed if a user sets variables + ;; influencing fontification in her file-local variables section. + (add-hook 'hack-local-variables-hook #'font-latex-after-hacking-local-variables t t)) (defun font-latex-jit-lock-force-redisplay (buf start end) "Compatibility for Emacsen not offering `jit-lock-force-redisplay'." @@ -1343,6 +1347,24 @@ fontification facilities like `font-lock-multiline' itself." (when (numberp ad-end) (ad-set-arg 1 ad-end))))))) +(defun font-latex-after-hacking-local-variables () + "Refresh fontification if required by updates of file-local variables. +This function is added to `hack-local-variables-hook' and +recomputes fontification if variables affecting fontification are +modified. Such variables include +`LaTeX-verbatim-environments-local', +`LaTeX-verbatim-macros-with-braces-local', +`LaTeX-verbatim-macros-with-delims-local'." + ;; Note to self: directory-local variables are also added to + ;; file-local-variables-alist. + (let ((hacked-local-vars (mapcar #'car file-local-variables-alist))) + (when (or (memq 'LaTeX-verbatim-environments-local hacked-local-vars) + (memq 'LaTeX-verbatim-macros-with-braces-local hacked-local-vars) + (memq 'LaTeX-verbatim-macros-with-delims-local hacked-local-vars)) + ;; Ok, we need to refresh fontification. + (font-latex-set-syntactic-keywords) + (setq font-lock-set-defaults nil) + (font-lock-set-defaults)))) ;;; Utility functions diff --git a/latex.el b/latex.el index c21699da..56cb4915 100644 --- a/latex.el +++ b/latex.el @@ -2785,6 +2785,9 @@ Programs should not use this variable directly but the function including values of the variable `LaTeX-verbatim-macros-with-delims' as well.") (make-variable-buffer-local 'LaTeX-verbatim-macros-with-delims-local) +(put 'LaTeX-verbatim-macros-with-delims-local 'safe-local-variable + #'TeX--list-of-string-p) + (defcustom LaTeX-verbatim-macros-with-braces nil "Macros for inline verbatim with arguments in braces, like \\foo{...}. @@ -2807,6 +2810,8 @@ Programs should not use this variable directly but the function including values of the variable `LaTeX-verbatim-macros-with-braces' as well.") (make-variable-buffer-local 'LaTeX-verbatim-macros-with-braces-local) +(put 'LaTeX-verbatim-macros-with-braces-local 'safe-local-variable + #'TeX--list-of-string-p) (defcustom LaTeX-verbatim-environments '("verbatim" "verbatim*") @@ -2829,6 +2834,8 @@ Programs should not use this variable directly but the function `LaTeX-verbatim-environments' which returns a value including values of the variable `LaTeX-verbatim-environments' as well.") (make-variable-buffer-local 'LaTeX-verbatim-environments-local) +(put 'LaTeX-verbatim-environments-local 'safe-local-variable + #'TeX--list-of-string-p) (defun LaTeX-verbatim-macros-with-delims () "Return list of verbatim macros with delimiters." diff --git a/style/natbib.el b/style/natbib.el index d56642c2..2bad5002 100644 --- a/style/natbib.el +++ b/style/natbib.el @@ -1,6 +1,6 @@ -;;; natbib.el --- Style hook for the natbib package +;;; natbib.el --- AUCTeX style for `natbib.sty' version 8.31b -;; Copyright (C) 1997, 1998, 2004, 2007, 2014 Free Software Foundation, Inc. +;; Copyright (C) 1997, 1998, 2004, 2007, 2014, 2016 Free Software Foundation, Inc. ;; Authors: Berwin Turlach <sta...@nus.edu.sg> ;; Carsten Dominik <domi...@strw.leidenuniv.nl> @@ -26,104 +26,158 @@ ;;; Code: -(TeX-add-style-hook "natbib" - (function - (lambda () - ;; The number in the cdr of the following list indicates how many - ;; optional note arguments we consider useful. Prompting for those - ;; arguments will still depend upon `TeX-arg-cite-note-p'. - (let ((citecmds - '(("cite" . 0) - ("citet" . 1) ("citet*" . 1) ("citealt" . 1) ("citealt*" . 1) - ("citep" . 2) ("citep*" . 2) ("citealp" . 2) ("citealp*" . 2) - ("citeauthor" . 0) ("citeauthor*" . 0) ("citefullauthor" . 0) - ("citeyear" . 0) ("citeyearpar" . 0) - ("shortcites" . 0)))) - - ;; Add these symbols - (apply - 'TeX-add-symbols - (mapcar - (lambda (cmd) - (cond - ((= (cdr cmd) 0) - ;; No optional arguments - (list (car cmd) 'TeX-arg-cite)) - ((= (cdr cmd) 1) - ;; Just one optional argument, the post note - (list - (car cmd) - '(TeX-arg-conditional TeX-arg-cite-note-p (["Post-note"]) nil) - 'TeX-arg-cite)) - ((= (cdr cmd) 2) - ;; Pre and post notes - (list - (car cmd) - '(TeX-arg-conditional TeX-arg-cite-note-p ([LaTeX-arg-natbib-notes]) nil) - 'TeX-arg-cite)))) - citecmds)) - - ;; Add the other symbols - (TeX-add-symbols - '("citetext" "Text") - '("bibpunct" ["Post note separator"] - "Opening bracket" - "Closing bracket" - "Punctuation between multiple citations" - "style [n]umeric [s]uperscript [a]uthor-year" - "Punctuation between author and year" - "Punctuation between years for common authors") - '("citestyle" "Style") - '("citeindextrue") - '("citeindexfalse") - '("citeindextype")) - - ;; Make an entry in TeX-complete-list - (add-to-list - 'TeX-complete-list - (list - (concat "\\\\\\(" - (mapconcat (lambda (x) (regexp-quote (car x))) - citecmds "\\|") - "\\)\\(\\[[^]\n\r\\%]*\\]\\)*{\\([^{}\n\r\\%,]*,\\)*\\([^{}\n\r\\%,]*\\)") - 4 'LaTeX-bibitem-list "}"))) - - ;; Fontification - (when (and (fboundp 'font-latex-add-keywords) - (eq TeX-install-font-lock 'font-latex-setup)) - (font-latex-add-keywords '(("cite" "*[[{") - ("citet" "*[[{") - ("citealt" "*[[{") - ("citep" "*[[{") - ("citealp" "*[[{") - ("citeauthor" "*[[{") - ("citefullauthor" "[[{") - ("citeyear" "[[{") - ("citeyearpar" "[[{") - ("shortcites" "{")) - 'reference)) - - ;; Tell RefTeX - (if (fboundp 'reftex-set-cite-format) - (reftex-set-cite-format 'natbib)))) +(TeX-add-style-hook + "natbib" + (lambda () + ;; The number in the cdr of the following list indicates how many + ;; optional note arguments we consider useful. Prompting for those + ;; arguments will still depend upon `TeX-arg-cite-note-p'. + (let ((citecmds + '(("cite" . 0) + ("citet" . 1) ("citet*" . 1) ("citealt" . 1) ("citealt*" . 1) + ("citep" . 2) ("citep*" . 2) ("citealp" . 2) ("citealp*" . 2) + ("citeauthor" . 0) ("citeauthor*" . 0) ("citefullauthor" . 0) + ("citeyear" . 0) ("citeyearpar" . 0) + ("shortcites" . 0) + ;; 2.4 Extended Citation Commands + ("citenum" . 0) + ;; 2.5 Forcing Upper Cased Name + ("Citet" . 1) ("Citet*" . 1) ("Citealt" . 1) ("Citealt*" . 1) + ("Citep" . 2) ("Citep*" . 2) ("Citealp" . 2) ("Citealp*" . 2) + ;; 2.6 Citation Aliasing + ("citetalias" . 1) ("citepalias" . 2)))) + + ;; Add these symbols + (apply + #'TeX-add-symbols + (mapcar + (lambda (cmd) + (cond + ((= (cdr cmd) 0) + ;; No optional arguments + (list (car cmd) 'TeX-arg-cite)) + ((= (cdr cmd) 1) + ;; Just one optional argument, the post note + (list + (car cmd) + '(TeX-arg-conditional TeX-arg-cite-note-p (["Post-note"]) nil) + 'TeX-arg-cite)) + ((= (cdr cmd) 2) + ;; Pre and post notes + (list + (car cmd) + '(TeX-arg-conditional TeX-arg-cite-note-p ([LaTeX-arg-natbib-notes]) nil) + 'TeX-arg-cite)))) + citecmds)) + + ;; Make an entry in TeX-complete-list + (add-to-list + 'TeX-complete-list + (list + (concat "\\\\\\(" + (mapconcat (lambda (x) (regexp-quote (car x))) + citecmds "\\|") + "\\)\\(\\[[^]\n\r\\%]*\\]\\)*{\\([^{}\n\r\\%,]*,\\)*\\([^{}\n\r\\%,]*\\)") + 4 'LaTeX-bibitem-list "}"))) + + ;; Add the other symbols + (TeX-add-symbols + ;; 2.4 Extended Citation Commands + '("citetext" "Text") + + ;; 2.6 Citation Aliasing + '("defcitealias" TeX-arg-cite "Alias") + + ;; 2.9 Selecting Citation Punctuation + '("setcitestyle" (TeX-arg-key-val + (;; Citation mode (fourth argument of \bibpunct): + ("authoryear") ("numbers") ("super") + ;; Braces (first and second arguments of \bibpunct): + ("round") ("square") ("open") ("close") + ;; Between citations (third argument of \bibpunct): + ("semicolon") ("comma") ("citesep") + ;; Between author and year (fifth argument of \bibpunct): + ("aysep") + ;; Between years with common author (sixth argument of \bibpunct): + ("yysep") + ;; Text before post-note (optional argument of \bibpunct): + ("notesep")))) + '("bibpunct" ["Post note separator"] + "Opening bracket" + "Closing bracket" + "Punctuation between multiple citations" + "style [n]umeric [s]uperscript [a]uthor-year" + "Punctuation between author and year" + "Punctuation between years for common authors") + + '("citestyle" (TeX-arg-eval completing-read + (TeX-argument-prompt optional nil "Style") + '("plain" "plainnat" "agu" "egu" + "agms" "dcu" "kluwer" "cospar" "nature"))) + + ;; 2.12 Other Formatting Options + "bibsection" + "bibpreamble" + "bibfont" + "citenumfont" + "bibnumfmt" + + ;; 2.13 Automatic Indexing of Citations + '("citeindextrue") + '("citeindexfalse") + '("citeindextype")) + + ;; 2.12 Other Formatting Options + (LaTeX-add-lengths "bibhang" "bibsep") + + ;; Fontification + (when (and (fboundp 'font-latex-add-keywords) + (eq TeX-install-font-lock 'font-latex-setup)) + (font-latex-add-keywords '(("cite" "*[[{") + ("citet" "*[[{") + ("citealt" "*[[{") + ("citep" "*[[{") + ("citealp" "*[[{") + ("citeauthor" "*[[{") + ("citefullauthor" "[[{") + ("citeyear" "[[{") + ("citeyearpar" "[[{") + ("shortcites" "{") + ("citenum" "{") + ("Citet" "*[[{") + ("Citealt" "*[[{") + ("Citep" "*[[{") + ("Citealp" "*[[{") + ("Citeauthor" "*[[{") + ("citetalias" "*[[{") + ("citepalias" "*[[{")) + 'reference) + (font-latex-add-keywords '(("defcitealias" "{{") + ("bibpunct" "[{{{{{{") + ("setcitestyle" "{") + ("citestyle" "{")) + 'function)) + + ;; Tell RefTeX + (if (fboundp 'reftex-set-cite-format) + (reftex-set-cite-format 'natbib))) LaTeX-dialect) (defun LaTeX-arg-natbib-notes (optional) "Prompt for two note arguments a natbib citation command. If OPTIONAL is non-nil, insert them in brackets, otherwise in braces." - (if TeX-arg-cite-note-p - (let ((pre (TeX-read-string - (TeX-argument-prompt optional nil "Pre-note"))) - (post (TeX-read-string - (TeX-argument-prompt optional nil "Post-note")))) - (TeX-argument-insert pre optional) - (TeX-argument-insert post optional) - ;; pre is given, post is empty: Make sure that we insert an - ;; extra pair of `[]', otherwise pre becomes post - (when (and pre (not (string= pre "")) - (string= post "")) - (insert LaTeX-optop LaTeX-optcl))))) + (let ((pre (TeX-read-string + (TeX-argument-prompt optional nil "Pre-note"))) + (post (TeX-read-string + (TeX-argument-prompt optional nil "Post-note")))) + (TeX-argument-insert pre optional) + (TeX-argument-insert post optional) + ;; pre is given, post is empty: Make sure that we insert an + ;; extra pair of `[]', otherwise pre becomes post + (when (and pre (not (string= pre "")) + (string= post "")) + (insert LaTeX-optop LaTeX-optcl)))) (defvar LaTeX-natbib-package-options '("numbers" "super" "authoryear" "round" "square" "angle" "curly" diff --git a/tex.el b/tex.el index 1836f66f..e1928994 100644 --- a/tex.el +++ b/tex.el @@ -6665,6 +6665,16 @@ Emacs 21." (string-to-number (replace-match "\\1" nil nil string)) 0)))) +(defun TeX--list-of-string-p (lst) + "Return non-nil iff `LST' is a list of strings. +Used as function for validating a variable's `safe-local-variable' property." + (and (listp lst) + (let ((all-strings t)) + (while (and all-strings lst) + (setq all-strings (stringp (car lst))) + (setq lst (cdr lst))) + all-strings))) + (provide 'tex) ;; Local Variables: