Hi AUCTeX developers,
I noticed recently that directory local variables are invalid in
`japanese-latex-mode'.
[Short summary of this mail]
Could you review the attached change and apply if it is OK?
[Detail]
First of all, I explain how to confirm that directory local variables
are invalid in `japanese-latex-mode'. You don't need Japanese tex
engines to try.
Put the following two files in an empty directory somewhere.
---- .dir-locals.el ---------------------------------------------
;;; Directory Local Variables
;;; For more information see (info "(emacs) Directory Variables")
((japanese-latex-mode
(TeX-PDF-from-DVI . "Dvipdfmx")))
-----------------------------------------------------------------
---- test.tex ---------------------------------------------------
\documentclass{jarticle}
\begin{document}
DUMMY TEXT
\end{document}
%%% Local Variables:
%%% mode: japanese-latex
%%% TeX-master: t
%%% End:
-----------------------------------------------------------------
Open test.tex with AUCTeX and you fill find that the value of
`TeX-PDF-from-DVI' is not "Dvipdfmx", unless you customized it so before
opening the file. The value of `file-local-variables-alist' is
((mode . japanese-latex)
(TeX-master . t))
, which tells that the entry in .dir-locals.el is skipped over when
parsing .dir-locals.el.
The reason is that `japanese-latex-mode' binds `major-mode' to
`latex-mode', not `japanese-latex-mode' (the reason for this is
explained later). However, editing .dir-locals.el to replace
`japanese-latex-mode' with `latex-mode' and re-opening test.tex ends up
with a strange result. The value of `TeX-PDF-from-DVI' is still not
"Dvipdfmx". The reason for that is a bit complicated.
This time the value of `file-local-variables-alist' is
((TeX-PDF-from-DVI . "Dvipdfmx")
(mode . japanese-latex)
(TeX-master . t))
and the entry in .dir-locals.el is recognized as expected. The point is
that the entry of the directory local variable comes before the
pseudo-variable `mode' entry. These entries are processed in this order
by `hack-local-variables-apply'. The mode specification does not match
the current `major-mode' of `latex-mode', so it is considered that the
major mode is not set correctly and `japanese-latex-mode' is called
again at this point. The function eventually calls
`kill-all-local-variables' in `VirTeX-common-initialization', which
kills the binding of the directory local variable processed before that.
It may seem that simple solution to these problems is to set
`major-mode' to `japanese-latex-mode' in the mode function (or its mode
hook). However, that would bring undesired side effects. The name
`latex-mode' is hard coded in several places of AUCTeX like "(eq
major-mode 'latex-mode)", "(memq major-mode '(doctex-mode latex-mode)"
and so on. By such piece of codes, `japanese-latex-mode' should simply
be regarded as `latex-mode'. So I think that the above solution is not
suitable.
The attached patch is my approach to these problems. The idea is to set
`major-mode' to `japanese-latex-mode' only temporarily, i.e. during the
process of local variables, using `hack-local-variables-hook' to reset
the mode name afterward.
The patch also includes a change so that `latex-mode' is considered as
parent mode of `japanese-latex-mode' in directory local variables. In
this way, we can write .dir-locals.el such as:
---- .dir-locals.el ---------------------------------------------
((latex-mode
(TeX-clean-confirm . nil))
(japanese-latex-mode
(TeX-PDF-from-DVI . "Dvipdfmx")))
-----------------------------------------------------------------
I.e., Japanese TeX specific settings can be separated from general
settings.
Similar changes are added for `japanese-plain-tex-mode', too.
Comments and suggestions are welcome.
Regards,
Ikumi Keita
# HG changeset patch
# User Ikumi Keita <[email protected]>
# Date 1461482468 -32400
# Sun Apr 24 16:21:08 2016 +0900
# Node ID 64dd9f438a7fe920533968919ce3fc88f05c772b
# Parent 58fafa2247b6f7eb7f2767eb4f347dde95456940
Enable directory local variables in japanese-{latex,plain-tex}-mode.
* tex-jp.el (japanese-latex-mode-initialization): Set
major-mode to `japanese-latex-mode' and reset it to
`latex-mode' after `hack-local-variables' is done.
(japanese-plain-tex-mode-initialization): Similar changes
for `japanese-plain-tex-mode'.
(japanese-TeX-reset-mode-name): New function.
(top-level) Make `latex-mode' is regarded as parent of
`japanese-latex-mode' in directory local variables. Similar
addition for `japanese-plain-tex-mode', too.
diff -r 58fafa2247b6 -r 64dd9f438a7f tex-jp.el
--- a/tex-jp.el Sat Apr 23 18:49:19 2016 +0200
+++ b/tex-jp.el Sun Apr 24 16:21:08 2016 +0900
@@ -399,7 +399,13 @@
"Japanese plain-TeX specific initializations."
(when japanese-TeX-mode
; (setq TeX-command-default japanese-TeX-command-default)
- (TeX-engine-set japanese-TeX-engine-default)))
+ (TeX-engine-set japanese-TeX-engine-default)
+
+ ;; For the intent of the following lines, see the comments below
+ ;; in `japanese-latex-mode-initialization'.
+ (setq major-mode 'japanese-plain-tex-mode)
+ (add-hook 'hack-local-variables-hook 'japanese-TeX-reset-mode-name
+ nil t)))
(add-hook 'plain-TeX-mode-hook 'japanese-plain-tex-mode-initialization)
@@ -431,10 +437,41 @@
; (setq TeX-command-BibTeX
; (if (and (eq TeX-engine 'ptex) (executable-find "pbibtex"))
; "pBibTeX" "jBibTeX"))
-))
+
+ ;; The value of `major-mode' should be `latex-mode', not
+ ;; `japanese-latex-mode', because the name `latex-mode' is hard
+ ;; coded in several places of AUCTeX like "(eq major-mode
+ ;; 'latex-mode)", "(memq major-mode '(doctex-mode latex-mode)" and
+ ;; so on. By such piece of codes, `japanese-latex-mode' should
+ ;; simply be regarded as `latex-mode'. So we'd like to leave
+ ;; `major-mode' as `latex-mode' here, but doing so confuses
+ ;; `hack-local-variables' in two ways.
+ ;; (1) It is tricked into considering that the major mode is not
+ ;; yet initialized and calls `japanese-latex-mode' again.
+ ;; (2) It does not read the directory local variables prepared for
+ ;; `japanese-latex-mode'.
+ ;; Thus we temporarily set `major-mode' to `japanese-latex-mode'
+ ;; here and plan to reset it to `latex-mode' after
+ ;; `hack-local-variables' is done.
+ (setq major-mode 'japanese-latex-mode)
+ (add-hook 'hack-local-variables-hook 'japanese-TeX-reset-mode-name
+ nil t)))
(add-hook 'LaTeX-mode-hook 'japanese-latex-mode-initialization)
+;; This function is useful only within `hack-local-variables-hook'.
+(defun japanese-TeX-reset-mode-name ()
+ (cond ((eq major-mode 'japanese-latex-mode)
+ (setq major-mode 'latex-mode))
+ ((eq major-mode 'japanese-plain-tex-mode)
+ (setq major-mode 'plain-tex-mode)))
+ (remove-hook 'hack-local-variables-hook 'japanese-TeX-reset-mode-name t))
+
+;; Make `hack-dir-local-variables' to regard `latex-mode' as parent
+;; of `japanese-latex-mode', and `plain-tex-mode' as parent of
+;; `japanese-plain-tex-mode'.
+(put 'japanese-plain-tex-mode 'derived-mode-parent 'plain-tex-mode)
+(put 'japanese-latex-mode 'derived-mode-parent 'latex-mode)
;;; Support for various self-insert-command
_______________________________________________
auctex-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/auctex-devel