Hi all,
In order to reduce byte compile warnings, I'm examining the usage of
`TeX-auto-update'. I came to think, as discussed below, that we can get
rid of `TeX-auto-update' variable, so I share my idea as the attached
patch so that others can discuss it and find possible shortcomings.
I think that we can regard `TeX-auto-update' as an indicator whether it
is AUCTeX document buffer because it is set in
`VirTeX-common-initialization' and `TeX-texinfo-mode'. For that purpose
we can use `TeX-mode-p' instead.
In addition, `BibTeX-auto-store' also sets `TeX-auto-update' to `BibTeX'.
`BibTeX-auto-store' is only called in 'bibtex-mode-hook', so I think it
is only in bibtex mode buffer that `TeX-auto-update' can be `BibTeX'.
AUCTeX refers to `TeX-auto-update' only at the following two pieces of
code, except bib-cite.el:
---- (1) -------------------------------------------------------------
(defun TeX-safe-auto-write ()
"Call `TeX-auto-write' safely."
(condition-case _ignored
(and (boundp 'TeX-auto-update)
TeX-auto-update
(TeX-auto-write))
(error nil))
;; Continue with the other write file hooks.
nil)
----------------------------------------------------------------------
---- (2) -------------------------------------------------------------
(defun TeX-update-style (&optional force)
[...]
(unless (or (and (boundp 'TeX-auto-update)
(eq TeX-auto-update 'BibTeX)) ; Not a real TeX buffer
(and (not force)
TeX-style-hook-applied-p))
[... Apply various style hooks]
----------------------------------------------------------------------
About piece (1): The reason why `TeX-safe-auto-write' tests whether
`TeX-auto-update' is bound and non-nil is, I suppose, that this function
formerly had a chance to be stored in `write-file-hooks' as a global
hook; In that case, this function is called when _any_ buffer is going
to be saved in a file, so it is necessary to distinguish that the
current buffer is AUCTeX document or not.
Now that `TeX-safe-auto-write' is stored in `write-contents-functions'
as a local hook, I think that such check is no longer necessary.
About piece (2): Here, `TeX-update-style' tries to skip applying various
style hooks in BibTeX buffer. This check is needed since
`TeX-safe-auto-write' is called via `write-contents-functions' in
bibtex mode buffers, which in turn calls `TeX-auto-write'
calling `TeX-update-style'. I think that it's enough to check that
`major-mode' is `bibtex-mode' or not, instead of looking at
`TeX-auto-update'.
These functions are modified along with the above consideration in the
attached patch.
In bib-cite.el, we see several other usages of `TeX-auto-update'.
In the attached patch, I replaced test for `TeX-auto-update' with a
check for `TeX-mode-p' in `bib-get-bibliography' and a check for
`TeX-mode-p' or `major-mode' being `bibtex-mode' in `bib-apropos'.
I did so because I assumed that `bib-get-bibliography' won't be called
in bibtex mode buffer but I'm not sure this assumption is right or not.
In the patch I omitted let-bound of `TeX-auto-update' in
`bib-create-auto-file' because the changes in `TeX-safe-auto-write' and
`TeX-update-style' would compensate it.
Any comments and advices are much appreciated.
Best regards,
Ikumi Keita
diff --git a/bib-cite.el b/bib-cite.el
index 0799c40c..4e598eba 100644
--- a/bib-cite.el
+++ b/bib-cite.el
@@ -1022,7 +1022,9 @@ cases, *it* is searched. This allows you to trim down a search further
by using bib-apropos sequentially."
;;(interactive "sBibTeX apropos: ")
(interactive)
- (let* ((keylist (and (boundp 'TeX-auto-update) ;Avoid error in FRAMEPOP
+ (let* ((keylist (and (boundp 'TeX-mode-p)
+ (or TeX-mode-p
+ (eq major-mode 'bibtex-mode)) ;Avoid error in FRAMEPOP
(fboundp 'LaTeX-bibitem-list) ;Use this if using auctex
(LaTeX-bibitem-list)))
(keyword (bib-apropos-keyword-at-point))
@@ -2166,7 +2168,7 @@ of each bib file.
Puts the buffer in text-mode such that forward-sexp works with german \"
accents embeded in bibtex entries."
(let ((bib-list (or (and (fboundp 'LaTeX-bibliography-list)
- (boundp 'TeX-auto-update)
+ (boundp 'TeX-mode-p) TeX-mode-p
(LaTeX-bibliography-list))
;; LaTeX-bibliography-list (if bound) returns an unformatted list of
;; bib files used in the document, but only if parsing is turned on
@@ -2250,7 +2252,6 @@ although BiBTeX doesn't allow it!"
(mapcar 'list the-list)))))
(defvar TeX-auto-save)
-(defvar TeX-auto-update)
(defvar TeX-auto-regexp-list)
;; BibTeX-mode key def to create AUCTeX's parsing file.
@@ -2260,7 +2261,6 @@ although BiBTeX doesn't allow it!"
(if (not (require 'latex))
(error "Sorry, This is only useful if you have AUCTeX"))
(let ((TeX-auto-save t)
- (TeX-auto-update t)
(TeX-auto-regexp-list BibTeX-auto-regexp-list))
;; TeX-auto-write
;; -> calls TeX-auto-store
diff --git a/latex.el b/latex.el
index 33851593..d5d56211 100644
--- a/latex.el
+++ b/latex.el
@@ -1990,7 +1990,6 @@ It will setup BibTeX to store keys in an auto file."
;; add it before we enter BibTeX mode the first time.
(add-hook 'write-contents-functions #'TeX-safe-auto-write nil t)
(TeX-bibtex-set-BibTeX-dialect)
- (set (make-local-variable 'TeX-auto-update) 'BibTeX)
(set (make-local-variable 'TeX-auto-untabify) nil)
(set (make-local-variable 'TeX-auto-parse-length) 999999)
(set (make-local-variable 'TeX-auto-regexp-list) BibTeX-auto-regexp-list)
diff --git a/tex-info.el b/tex-info.el
index 2f6a4433..c9810d27 100644
--- a/tex-info.el
+++ b/tex-info.el
@@ -686,7 +686,6 @@ value of `Texinfo-mode-hook'."
(set (make-local-variable 'TeX-esc) "@")
(set (make-local-variable 'TeX-auto-regexp-list) 'TeX-auto-empty-regexp-list)
- (set (make-local-variable 'TeX-auto-update) t)
(setq TeX-command-default "TeX")
(setq TeX-header-end "%*end")
diff --git a/tex.el b/tex.el
index b59aee05..a3642867 100644
--- a/tex.el
+++ b/tex.el
@@ -2989,8 +2989,7 @@ See variable `TeX-style-hook-dialect' for supported dialects."
Only do this if it has not been done before, or if optional argument
FORCE is not nil."
- (unless (or (and (boundp 'TeX-auto-update)
- (eq TeX-auto-update 'BibTeX)) ; Not a real TeX buffer
+ (unless (or (eq major-mode 'bibtex-mode) ; Not a real TeX buffer
(and (not force)
TeX-style-hook-applied-p))
(setq TeX-style-hook-applied-p t)
@@ -3716,7 +3715,6 @@ The algorithm is as follows:
;; We want this to be early in the list, so we do not add it before
;; we enter TeX mode the first time.
(add-hook 'write-contents-functions #'TeX-safe-auto-write nil t)
- (set (make-local-variable 'TeX-auto-update) t)
(define-key TeX-mode-map "\C-xng" 'TeX-narrow-to-group)
@@ -3897,9 +3895,7 @@ Generated by `TeX-auto-add-type'.")
(defun TeX-safe-auto-write ()
"Call `TeX-auto-write' safely."
(condition-case _ignored
- (and (boundp 'TeX-auto-update)
- TeX-auto-update
- (TeX-auto-write))
+ (TeX-auto-write)
(error nil))
;; Continue with the other write file hooks.
nil)