branch: externals/auctex commit 86f4a1ecc37a8a9a5ce396f592557b9ddf224b77 Author: Tassilo Horn <t...@gnu.org> Commit: Tassilo Horn <t...@gnu.org>
Add a hook that's run after an environment is modified * latex.el (LaTeX-after-insert-env-hook): Rename from `LaTeX-after-insert-env-hooks' which is now an obsolete variable alias. (LaTeX-after-modify-env-hook): New hook. (LaTeX-modify-environment): Run `LaTeX-after-modify-env-hook'. --- ChangeLog | 8 ++++++ latex.el | 74 +++++++++++++++++++++++++++++++++++++++++------------------- 2 files changed, 58 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1a4d561..d3ba7df 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2015-02-17 Tassilo Horn <t...@gnu.org> + + * latex.el (LaTeX-after-insert-env-hook): Rename from + `LaTeX-after-insert-env-hooks' which is now an obsolete variable + alias. + (LaTeX-after-modify-env-hook): New hook. + (LaTeX-modify-environment): Run `LaTeX-after-modify-env-hook'. + 2015-02-13 Tassilo Horn <t...@gnu.org> * tex.el (TeX-pdf-tools-sync-view, TeX-PDF-mode): Move addition of diff --git a/latex.el b/latex.el index 8409690..9c2646f 100644 --- a/latex.el +++ b/latex.el @@ -644,7 +644,11 @@ With prefix-argument, reopen environment afterwards." marker)) (move-marker marker nil))))) -(defvar LaTeX-after-insert-env-hooks nil +(if (featurep 'xemacs) + (define-obsolete-variable-alias 'LaTeX-after-insert-env-hooks 'LaTeX-after-insert-env-hook) + (define-obsolete-variable-alias 'LaTeX-after-insert-env-hooks 'LaTeX-after-insert-env-hook "11.89")) + +(defvar LaTeX-after-insert-env-hook nil "List of functions to be run at the end of `LaTeX-insert-environment'. Each function is called with three arguments: the name of the environment just inserted, the buffer position just before @@ -738,26 +742,48 @@ allowing one level of TeX group braces." (regexp-quote TeX-grop) "]*" (regexp-quote TeX-grcl) "\\)*[^" (regexp-quote TeX-grcl) (regexp-quote TeX-grop) "]*\\)")) +(defvar LaTeX-after-modify-env-hook nil + "List of functions to be run at the end of `LaTeX-modify-environment'. +Each function is called with four arguments: the new name of the +environment, the former name of the environment, the buffer +position just before \\begin and the position just before +\\end.") + (defun LaTeX-modify-environment (environment) "Modify current ENVIRONMENT." - (save-excursion - (LaTeX-find-matching-end) - (re-search-backward (concat (regexp-quote TeX-esc) - "end" - (regexp-quote TeX-grop) - (LaTeX-environment-name-regexp) - (regexp-quote TeX-grcl)) - (save-excursion (beginning-of-line 1) (point))) - (replace-match (concat TeX-esc "end" TeX-grop environment TeX-grcl) t t) - (beginning-of-line 1) - (LaTeX-find-matching-begin) - (re-search-forward (concat (regexp-quote TeX-esc) - "begin" - (regexp-quote TeX-grop) - (LaTeX-environment-name-regexp) - (regexp-quote TeX-grcl)) - (save-excursion (end-of-line 1) (point))) - (replace-match (concat TeX-esc "begin" TeX-grop environment TeX-grcl) t t))) + (let ((goto-end (lambda () + (LaTeX-find-matching-end) + (re-search-backward (concat (regexp-quote TeX-esc) + "end" + (regexp-quote TeX-grop) + "\\(" + (LaTeX-environment-name-regexp) + "\\)" + (regexp-quote TeX-grcl)) + (save-excursion (beginning-of-line 1) (point))))) + (goto-begin (lambda () + (LaTeX-find-matching-begin) + (prog1 (point) + (re-search-forward (concat (regexp-quote TeX-esc) + "begin" + (regexp-quote TeX-grop) + "\\(" + (LaTeX-environment-name-regexp) + "\\)" + (regexp-quote TeX-grcl)) + (save-excursion (end-of-line 1) (point))))))) + (save-excursion + (funcall goto-end) + (let ((old-env (match-string 1))) + (replace-match environment t t nil 1) + (beginning-of-line 1) + (funcall goto-begin) + (replace-match environment t t nil 1) + (end-of-line 1) + (run-hook-with-args 'LaTeX-after-modify-env-hook + environment old-env + (save-excursion (funcall goto-begin)) + (progn (funcall goto-end) (point))))))) (defun LaTeX-current-environment (&optional arg) "Return the name (a string) of the enclosing LaTeX environment. @@ -5847,7 +5873,7 @@ i.e. you do _not_ have to cater for this yourself by adding \\\\' or $." LaTeX-section-list))) (set (make-local-variable 'TeX-auto-full-regexp-list) - (append LaTeX-auto-regexp-list plain-TeX-auto-regexp-list)) + (append LaTeX-auto-regexp-list plain-TeX-auto-regexp-list)) (LaTeX-set-paragraph-start) (setq paragraph-separate @@ -5863,10 +5889,10 @@ i.e. you do _not_ have to cater for this yourself by adding \\\\' or $." LaTeX-search-files-type-alist) (set (make-local-variable 'LaTeX-item-list) '(("description" . LaTeX-item-argument) - ("thebibliography" . LaTeX-item-bib) - ("array" . LaTeX-item-array) - ("tabular" . LaTeX-item-array) - ("tabular*" . LaTeX-item-tabular*))) + ("thebibliography" . LaTeX-item-bib) + ("array" . LaTeX-item-array) + ("tabular" . LaTeX-item-array) + ("tabular*" . LaTeX-item-tabular*))) (setq TeX-complete-list (append '(("\\\\cite\\[[^]\n\r\\%]*\\]{\\([^{}\n\r\\%,]*\\)"