monnier pushed a commit to branch externals/auctex
in repository elpa.
commit 1a6bb00615641a41db4036e760fe87f623164863
Author: Mosè Giordano <[email protected]>
Date: Tue Jun 11 00:17:43 2013 +0200
New hooks TeX-after-document-hook and LaTeX-after-usepackage-hook.
* latex.el (TeX-after-document-hook): New hook.
(TeX-arg-document): Use it.
(LaTeX-after-usepackage-hook): New hook.
(LaTeX-arg-usepackage): Use it, remove babel specific code.
* style/babel.el: Update copyright years.
(LaTeX-env-babel-lang): New function.
("babel"): Add `LaTeX-env-babel-lang' to
`LaTeX-after-usepackage-hook'.
---
ChangeLog | 12 ++++++++++++
latex.el | 25 +++++++++++++++++++------
style/babel.el | 15 ++++++++++-----
3 files changed, 41 insertions(+), 11 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index e1659a8..7cff52a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2013-06-11 Mos� Giordano <[email protected]>
+
+ * latex.el (TeX-after-document-hook): New hook.
+ (TeX-arg-document): Use it.
+ (LaTeX-after-usepackage-hook): New hook.
+ (LaTeX-arg-usepackage): Use it, remove babel specific code.
+
+ * style/babel.el: Update copyright years.
+ (LaTeX-env-babel-lang): New function.
+ ("babel"): Add `LaTeX-env-babel-lang' to
+ `LaTeX-after-usepackage-hook'.
+
2013-06-08 Mos� Giordano <[email protected]>
* tex.el (TeX-math-close-double-dollar): Remove.
diff --git a/latex.el b/latex.el
index 5795307..0051004 100644
--- a/latex.el
+++ b/latex.el
@@ -1776,6 +1776,11 @@ and this variable will be ignored."
Initialized once at the first time you prompt for a LaTeX class.
May be reset with `\\[universal-argument] \\[TeX-normal-mode]'.")
+(defvar TeX-after-document-hook nil
+ "List of functions to be run at the end of `TeX-arg-document'.
+
+To insert a hook here, you must insert it in the appropiate style file.")
+
(defun TeX-arg-document (optional &optional ignore)
"Insert arguments to documentclass.
OPTIONAL and IGNORE are ignored."
@@ -1796,6 +1801,8 @@ OPTIONAL and IGNORE are ignored."
LaTeX-global-class-files))
(if (zerop (length style))
(setq style LaTeX-default-style))
+ ;; Clean up hook before use.
+ (setq TeX-after-document-hook nil)
(TeX-run-style-hooks style)
(setq var (intern (format "LaTeX-%s-class-options" style)))
(if (or (and (boundp var)
@@ -1824,7 +1831,13 @@ OPTIONAL and IGNORE are ignored."
(TeX-remove-style)
;; defined in individual style hooks
- (TeX-update-style))
+ (TeX-update-style)
+ (run-hooks 'TeX-after-document-hook))
+
+(defvar LaTeX-after-usepackage-hook nil
+ "List of functions to be run at the end of `LaTeX-arg-usepackage'.
+
+To insert a hook here, you must insert it in the appropiate style file.")
(defun LaTeX-arg-usepackage (optional)
"Insert arguments to usepackage.
@@ -1843,6 +1856,8 @@ OPTIONAL is ignored."
'texinputs 'global t t))))))
(setq packages (TeX-completing-read-multiple
"Packages: " TeX-global-input-files))
+ ;; Clean up hook before use.
+ (setq LaTeX-after-usepackage-hook nil)
(mapc 'TeX-run-style-hooks packages)
(setq var (if (= 1 (length packages))
(intern (format "LaTeX-%s-package-options" (car packages)))
@@ -1869,11 +1884,9 @@ OPTIONAL is ignored."
(TeX-add-to-alist 'LaTeX-provided-package-options
(list (cons elt opts))))
packages))
- (insert LaTeX-optop options LaTeX-optcl)
- ;; When `babel' is loaded with options, load also language style files.
- (when (member "babel" packages)
- (mapc 'TeX-run-style-hooks (LaTeX-babel-active-languages))))
- (insert TeX-grop (mapconcat 'identity packages ",") TeX-grcl)))
+ (insert LaTeX-optop options LaTeX-optcl))
+ (insert TeX-grop (mapconcat 'identity packages ",") TeX-grcl)
+ (run-hooks 'LaTeX-after-usepackage-hook)))
(defcustom LaTeX-search-files-type-alist
'((texinputs "${TEXINPUTS.latex}" ("tex/generic/" "tex/latex/")
diff --git a/style/babel.el b/style/babel.el
index cd97038..784732d 100755
--- a/style/babel.el
+++ b/style/babel.el
@@ -1,6 +1,6 @@
;;; babel.el --- AUCTeX style for `babel.sty'
-;; Copyright (C) 2005 Free Software Foundation, Inc.
+;; Copyright (C) 2005, 2007, 2013 Free Software Foundation, Inc.
;; Author: Ralf Angeli <[email protected]>
;; Maintainer: [email protected]
@@ -63,7 +63,7 @@
;; Append element to `active-languages' to respect loading order.
;; `babel' package uses as default language the last loaded one.
(add-to-list 'active-languages elt t)))
- active-languages))
+ active-languages))
(defun TeX-arg-babel-lang (optional &optional prompt)
"Prompt for a language with completion and insert it as an argument."
@@ -76,12 +76,17 @@
env (format "{%s}" (completing-read "Language: "
(LaTeX-babel-active-languages)))))
+(defun LaTeX-babel-load-languages ()
+ "Load style files of babel active languages."
+ ;; Run style hooks for every active language in loading order, so
+ ;; `TeX-quote-language' will be correctly set.
+ (mapc 'TeX-run-style-hooks (LaTeX-babel-active-languages)))
+
(TeX-add-style-hook
"babel"
(lambda ()
- ;; Run style hooks for every active language in loading order, so
- ;; `TeX-quote-language' will be correctly set.
- (mapc 'TeX-run-style-hooks (LaTeX-babel-active-languages))
+ (LaTeX-babel-load-languages)
+ (add-hook 'LaTeX-after-usepackage-hook 'LaTeX-babel-load-languages nil t)
;; New symbols
(TeX-add-symbols
'("selectlanguage" TeX-arg-babel-lang)