auctex-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Uncertain prettification


From: Ikumi Keita
Subject: Uncertain prettification
Date: Sat, 09 Apr 2022 21:36:47 +0900

Hi all,

This is another subtle inconsistency about load dependency of elisp
files. I found there are cases which don't enable prettification.

[How to confirm]
0. Add
(add-hook 'TeX-mode-hook #'turn-on-prettify-symbols-mode)
   in your init file to enable prettification in AUCTeX.
1. Start a new emacs session.
2. Open a texinfo document, say, copying.texi.
3. Open this sample latex document:
----- foo.tex --------------------------------------------------------
\documentclass{article}

\begin{document}
\alpha
\end{document}
----------------------------------------------------------------------
4. Then you'll see that "\alpha" isn't displaed as "α", which means
   that prettification isn't working.

[Reason of fail]
Prettification support codes in tex.el presume that tex-mode.el is
loaded *before* tex.el is loaded. Here is the culprit:
----------------------------------------------------------------------
(when (and (boundp 'tex--prettify-symbols-alist)
           (boundp 'prettify-symbols-compose-predicate))
  (defun TeX--prettify-symbols-compose-p (start end match)
[...]
(defun VirTeX-common-initialization ()
[...]
  ;; Prettify Symbols mode
  (when (fboundp 'TeX--prettify-symbols-compose-p)
    (set (make-local-variable 'prettify-symbols-alist) 
tex--prettify-symbols-alist)
[...]
----------------------------------------------------------------------
(1) If tex-mode.el isn't yet loaded when tex.el is loaded, the first
    `boundp' test fails and thus `TeX--prettify-symbols-compose-p' isn't
    defined.
(2) Hence, when `VirTeX-common-initialization' runs, the `fboundp' test
    fails and prettification isn't activated.
(3) After that, `turn-on-prettify-symbols-mode' in `TeX-mode-hook' is
    called, but that's too late.

[Reason of success]
Most AUCTeX users don't experience this bug, because:
1. They open latex document first in their emacs sessions.
2. That means the autoload stored in the function cell of the symbol
   `latex-mode' triggers loading of tex-mode.el first, followed by
   :override advice of AUCTeX which triggers subsequent loading of
   tex.el.

In other words, the current prettification support codes in AUCTeX rely
on autoloads stored in the symbols `latex-mode', `plain-tex-mode' and
`doctex-mode' for loading tex-mode.el; other AUCTeX major modes, namely
`texinfo-mode', `ams-tex-mode', `context-mode', `japanese-latex-mode'
and `japanese-plain-tex-mode' all fails to load tex-mode.el before
tex.el, if they are the first AUCTeX mode in that emacs session. (Though
`texinfo-mode' does have autoload, it's for texinfo.el, not tex-mode.el)

[How to solve]
The simplest solution is to add "(require 'tex-mode)" in tex.el. See the
patch at the last of this message.

This, however, increases byte compilation time, in particular for "make
dynvars-check"[1]. I think it's acceptable, but what do others think
about this issue?

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine

[1] output of "time make dynvars-check"
----- Current master branch ----------------------------------------------
Executed in   17.17 mins    fish           external
   usr time  874.23 secs    0.00 millis  874.23 secs
   sys time  110.00 secs    7.45 millis  109.99 secs

----- Attached patch applied ---------------------------------------------
Executed in   19.78 mins    fish           external
   usr time   16.65 mins    0.00 millis   16.65 mins
   sys time    2.08 mins    7.32 millis    2.08 mins

>From 7046286254a8cced02a4442bb350bb35a8bd5c58 Mon Sep 17 00:00:00 2001
From: Ikumi Keita <ikumi@ikumi.que.jp>
Date: Tue, 9 Nov 2021 02:53:19 +0900
Subject: [PATCH] Make prettification work reliably

* tex.el (require): Require tex-mode.el to make prettification work
reliably.
Remove now spurious `defvar' and `declare-function'.
* tex-bar.el (TeX-bar-img-filename): Avoid variable name clash with
tex-mode.el.
---
 tex-bar.el | 6 +++---
 tex.el     | 5 ++---
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/tex-bar.el b/tex-bar.el
index a9863f88..01eb61c8 100644
--- a/tex-bar.el
+++ b/tex-bar.el
@@ -367,9 +367,9 @@ format of the argument MEANING-ALIST in the mentioned 
function."
 ;;; Experimental Symbol Toolbar
 
 ;;; symbol toolbar
-(defun TeX-bar-img-filename (tex-command)
-  "Return the filename (no extension) for the image button of TEX-COMMAND."
-  (let ((str-list (append tex-command nil))
+(defun TeX-bar-img-filename (command)
+  "Return the filename (no extension) for the image button of TeX COMMAND."
+  (let ((str-list (append command nil))
         (str-result))
     (dolist (i str-list)
       (cond
diff --git a/tex.el b/tex.el
index ca4b8ad3..a951f979 100644
--- a/tex.el
+++ b/tex.el
@@ -41,6 +41,8 @@
 ;; Require dbus at compile time to get macro definition of
 ;; `dbus-ignore-errors'.
 (eval-when-compile (require 'dbus))
+;; Require tex-mode.el to make prettification work reliably.
+(require 'tex-mode)
 
 ;; Silence the compiler for functions:
 (declare-function dbus-get-unique-name "ext:dbusbind.c"
@@ -61,8 +63,6 @@
                   (buffer name command startfile switches))
 (declare-function comint-mode
                   nil)
-(declare-function tex--prettify-symbols-compose-p "ext:tex-mode"
-                  (start end match))
 (declare-function gnuserv-start "ext:gnuserv"
                   (&optional leave-dead) t)
 
@@ -98,7 +98,6 @@
 ;; tex-ispell.el
 (defvar TeX-ispell-verb-delimiters)
 ;; Others:
-(defvar tex--prettify-symbols-alist)    ; tex-mode.el
 (defvar Info-file-list-for-emacs)       ; info.el
 (defvar ispell-parser)                  ; ispell.el
 (defvar compilation-error-regexp-alist) ; compile.el
-- 
2.34.1


reply via email to

[Prev in Thread] Current Thread [Next in Thread]