Re: AUCTeX and "builtin latex mode" integration
>>> "SM" == Stefan Monnier writes: > You may have seen an on-going discussion about the annoyance of the > mixups between latex-mode and LaTeX-mode and such. > I do think it would be good to try and "integrate" the two modes, for > some definition of "integrate". The question being indeed what > "integration" is the best way forward. > I'm wondering if it would be possible to turn AUCTeX into a minor mode. > E.g. `LaTeX-mode` would then be redefined as > (define-derived-mode TeX-latex-mode latex-mode ... > (AUCTeX-mode 1)) Two remarks 1. Why can't latex-mode not be removed/substituted by auctex? 2. What's about reftex? Right now, since auctex provides a mayor mode, you can put it in a hook to startup reftex when you open a latex file with auctex installed. Would that be a problem, if auctex is no longer a «real» mayor mode? Uwe Brauer smime.p7s Description: S/MIME cryptographic signature
Re: AUCTeX and "builtin latex mode" integration
Tassilo Horn [2022-09-20 08:38:27] wrote: > Stefan Monnier writes: >> What I'm really asking here is if there's a willingness to introduce >> the inevitable bit of breakage in exchange for a supposed longer term >> benefit, and/or if someone can think of a better way to move towards a >> better long-term arrangement than the status quo. > I wonder why/if it's important that the AUCTeX modes identify as the > builtin modes, i.e., what would be the issue with having (La)TeX-mode > major-modes which have no relationship to (la)tex-mode at all plus a > setup command users would call in their init file in order to modify > `auto-mode-alist' so that the AUCTeX modes are added? It might cause problems for people with `-*- latex -*-` in their files. But other than that, it's also an option, indeed. Personally, I like the idea that `auto-mode-alist` (and mode cookies) should describe the type of a file, rather than the specific mode to use for it, but that's just me (and Emacs doesn't make that convenient since it doesn't offer the needed indirection). Stefan
Re: AUCTeX and "builtin latex mode" integration
>> You may have seen an on-going discussion about the annoyance of the >> mixups between latex-mode and LaTeX-mode and such. > Could you tell us where that discussion takes place? I think it's on gnu.emacs.help, aka help-gnu-emacs. It started with someone complaining that rainbow-delimiters doesn't work with LaTeX's braces, derived into AUCTeX-vs-plain because IIUC the problem was that they enabled the mode via `latex-mode-hook` which their AUCTeX doesn't run even though the mode describes itself as `latex-mode`. >> I do think it would be good to try and "integrate" the two modes, for >> some definition of "integrate". The question being indeed what >> "integration" is the best way forward. > > I also want some improvements with regard to the "integration" because I > recently realized that emacs built-in `tex-mode' (accidentally?) shadows > AUCTeX `TeX-tex-mode' since emacs 28.1, to fail to enter LaTeX mode for > some cases[1][2]. (I'm not sure that the above discussion involves this > issue.) > > [1] thread beginning with > https://lists.gnu.org/r/auctex/2022-08/msg1.html Oh, I wasn't aware of regression. We can workaround the problem using the `depth` property on `advice-add`, to make sure AUCTeX's advice takes precedence over that of `tex-mode.el` even if it's installed before. E.g. if you add the patch below to Emacs, can you confirm that it fixes the problem on your end? diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el index f624b604aac..77c0d234206 100644 --- a/lisp/textmodes/tex-mode.el +++ b/lisp/textmodes/tex-mode.el @@ -1014,7 +1014,10 @@ tex-mode says which mode to use." (tex-common-initialization)) -(advice-add 'tex-mode :around #'tex--redirect-to-submode) +(advice-add 'tex-mode :around #'tex--redirect-to-submode +;; Give it lower precedence than normal advice, so +;; AUCTeX's advice takes precedence over it. +'((depth . 50))) (defvar tex-mode--recursing nil) (defun tex--redirect-to-submode (orig-fun) "Redirect to one of the submodes when called directly." I pushed this to `emacs-28` so it will be fixed in the next Emacs release (but that may be Emacs-29.1). In the mean time, you can use a `((depth . -10))` in AUCTeX to make it work with Emacs-28.1. The dual use of `tex-mode` (as both a major mode and a dispatch function) is very messy :-( >> I'm wondering if it would be possible to turn AUCTeX into a minor mode. >> E.g. `LaTeX-mode` would then be redefined as > >> (define-derived-mode TeX-latex-mode latex-mode ... >> (AUCTeX-mode 1)) > >> and `TeX-modes-set` would add/remove `AUCTeX-mode` from the hooks like >> `latex-mode-hook`. > > It basically looks reasonable. I assume that you are thinking that > `AUCTeX-mode' actually chooses suitable behavior according to the value > of `major-mode' between `latex-mode', `plain-tex-mode', `doctex-mode' > and `texinfo-mode'. That'd be the idea, yes. > 1. There will be some overheads because it first runs initialization > codes of emacs built-in mode and then runs AUCTeX minor mode; I expect > that the associated cost is cheap enough. I'm assuming it would be cheap, yes. > 2. AUCTeX still must retain some major modes, i.e., ConTeXt mode, > AmS-TeX mode, Japanese LaTeX mode and Japanese plain TeX mode because > there are no counterparts in emacs built-in modes. In the short term at least it will also keep `(TeX-)LaTeX-mode` and friends, I think. And maybe even in the long term. > 3. Currently, there is defect in handling doc strings of AUCTeX LaTeX > mode, plain TeX mode and docTeX mode; C-h m and C-h f show doc string > of built-in modes, not AUCTeX modes. Maybe the help facility should be more careful in how it builds the docstring when a function has an `:override` advice, indeed. Could you `M-x report-emacs-bug` for that? Maybe the `latex-mode` docstring would need some tweaking, but `C-h m` would show the docstring of `AUCTeX-mode` as well. > `AUCTeX-mode' should put suitable `function-documentation' property > for the respective major mode symbol. I think that would be exactly the kind of messing around I'd like to move away from. > 4. `TeX-tex-mode' and `tex-mode' would need some special treatment. Special care, that's for sure, yes. >> To be honest, I haven't looked very much at the code to see how >> realistic this is, but I think this could help clarify the situation >> for users. E.g. it would eliminate "lies" such as (setq major-mode >> 'latex-mode) in `latex.el`. > > From the users' point of view, I don't think it matters much. They just > specify > %%% mode: latex > as the file local variable and think that they are using `latex-mode'. > I think that it would be only Elisp programmers that care about the > "lies". There's regularly discussion (among (AUC)TeX Emacs users) about which major mode runs which hook. I think it's an important issue not just for ELisp programmers
Re: AUCTeX and "builtin latex mode" integration
> 1. Why can't latex-mode not be removed/substituted by auctex? For technical/administrative/historical reasons. > 2. What's about reftex? Right now, since auctex provides a mayor >mode, you can put it in a hook to startup reftex when you open a >latex file with auctex installed. Would that be a problem, if >auctex is no longer a «real» mayor mode? The change would/will introduce breakage. The intention is to minimize (and fix) as much of it as possible. I suspect that if you provide a test for AUCTeX's test suite verifying this behavior, then we'll make sure it keeps working :-) Stefan
Re: AUCTeX and "builtin latex mode" integration
>>> "SM" == Stefan Monnier writes: >> 1. Why can't latex-mode not be removed/substituted by auctex? > For technical/administrative/historical reasons. >> 2. What's about reftex? Right now, since auctex provides a mayor >> mode, you can put it in a hook to startup reftex when you open a >> latex file with auctex installed. Would that be a problem, if >> auctex is no longer a «real» mayor mode? > The change would/will introduce breakage. The intention is to minimize > (and fix) as much of it as possible. I suspect that if you provide > a test for AUCTeX's test suite verifying this behavior, then we'll make > sure it keeps working :-) I see, I don't have much of a say here, I don't have write access to the repository, I just test and occasionally send some patches. However I have been using AucTeX at least since 1992 maybe longer, knowing it as a very useful and stable platform and always as a mayor mode. I have seen these discussion (there were another one about cdlatex by the same author) by someone who in my opinion did not really bother much to read the documentation or search the internet (googling)[1] but I feel that the change you propose it is a bit too much! It might causes problems, headaches etc and to shake a program that is so stable [2], just because of this discussion, well... So I would recommend not to try to please that specific complain and to leave things as they are. Regards Uwe Brauer Footnotes: [1] not that I have done sometimes a bit the same...😇 [2] and is so essential for my everyday work smime.p7s Description: S/MIME cryptographic signature
Re: AUCTeX and "builtin latex mode" integration
Stefan Monnier writes: >> I wonder why/if it's important that the AUCTeX modes identify as the >> builtin modes, i.e., what would be the issue with having (La)TeX-mode >> major-modes which have no relationship to (la)tex-mode at all plus a >> setup command users would call in their init file in order to modify >> `auto-mode-alist' so that the AUCTeX modes are added? > > It might cause problems for people with `-*- latex -*-` in their > files. But other than that, it's also an option, indeed. > > Personally, I like the idea that `auto-mode-alist` (and mode cookies) > should describe the type of a file, rather than the specific mode to > use for it, but that's just me Could you elaborate a bit here? I can't quite follow. Anyway: where the actual complaints not more or less like "I want to use the stock tex/latex modes but also with cdlatex which requires the auctex package which then hijacks my editing"? If that was the case, then maybe the only thing to be done was to make the "hijacking" explicit. I think that wouldn't be a bad idea anyway (except for compatibility reasons) because nowadays we all agree that merely installing and loading a package should not have side-effects. Bye, Tassilo
Re: AUCTeX and "builtin latex mode" integration
>>> I wonder why/if it's important that the AUCTeX modes identify as the >>> builtin modes, i.e., what would be the issue with having (La)TeX-mode >>> major-modes which have no relationship to (la)tex-mode at all plus a >>> setup command users would call in their init file in order to modify >>> `auto-mode-alist' so that the AUCTeX modes are added? >> >> It might cause problems for people with `-*- latex -*-` in their >> files. But other than that, it's also an option, indeed. >> >> Personally, I like the idea that `auto-mode-alist` (and mode cookies) >> should describe the type of a file, rather than the specific mode to >> use for it, but that's just me > > Could you elaborate a bit here? I can't quite follow. What I mean is that the entries in mode cookies and auto-mode-alist (and magic-mode-alist, ...) should not say "use this specific mode" but "use the mode which the user chose for files of this specific type". Emacs doesn't have the corresponding concept, so instead we use `latex-mode` resp. `perl-mode` as "the name of the mode to use for LaTeX resp. Perl files" and then we rely on hacks based on `defalias` or `advice-add` to make that symbol point to the user's favorite mode for that file type. > Anyway: where the actual complaints not more or less like "I want to > use the stock tex/latex modes but also with cdlatex which requires the > auctex package which then hijacks my editing"? No (BTW, `cdlatex` doesn't require AUCTeX any more). > I think that wouldn't be a bad idea anyway (except for compatibility > reasons) because nowadays we all agree that merely installing and > loading a package should not have side-effects. Agreed. Maybe `AUCTeX-mode` should be a global minor mode which causes `AUCTeX-minor-mode` to be enabled in the appropriate major modes. Stefan
Re: AUCTeX and "builtin latex mode" integration
Maybe we could start by stating some goals: - AUCTeX should not set the `major-mode` to point to non-AUCTeX functions (even if/when it overrides those functions). - Cleanup the mode function names. Currently, AUCTeX's LaTeX mode is variously called: latex-mode TeX-latex-mode LaTeX-mode AUCTeX should pick one and stick to it as much as possible (e.g. fix all the docs and have the auxiliary user-exposed variables be named accordingly to the base major mode name). WIP patch below. Stefan diff --git a/font-latex.el b/font-latex.el index 4406dea610..577a9834a0 100644 --- a/font-latex.el +++ b/font-latex.el @@ -36,6 +36,7 @@ (require 'font-lock) (require 'tex) +(require 'latex) (eval-when-compile (require 'cl-lib)) @@ -1285,7 +1286,7 @@ triggers Font Lock to recognize the change." (defun font-latex--make-syntax-propertize-function () "Return a `syntax-propertize-function' for (La|Doc)TeX documents." - (let ((kws ;; (if (derived-mode-p 'doctex-mode) + (let ((kws ;; (if (LaTeX--doctex-p) ;; font-latex-doctex-syntactic-keywords font-latex-syntactic-keywords)) ;; ) (syntax-propertize-via-font-lock kws))) @@ -1324,7 +1325,7 @@ triggers Font Lock to recognize the change." syntax-propertize-wholelines font-latex-sp-extend-region-backwards-verb-env ;; Add the mode-dependent stuff to the basic variables defined above. -(if (eq major-mode 'doctex-mode) +(if (LaTeX--doctex-p) (progn (setcar defaults (append (car defaults) '(font-latex-doctex-keywords))) @@ -1429,7 +1430,8 @@ OPENCHAR is the opening character and CLOSECHAR is the closing character. Character pairs are usually { } or [ ]. Comments are ignored during the search." (let ((parse-sexp-ignore-comments - (not (eq major-mode 'doctex-mode))) ; scan-sexps ignores comments + ;; `scan-sexps' ignores comments. + (not (LaTeX--doctex-p))) (init-point (point)) (mycount 1) (esc-char (or (and (boundp 'TeX-esc) TeX-esc) "\\")) @@ -1482,13 +1484,14 @@ ignored during the search." (forward-line 0) (if (and (eq (char-after) ?\%) (not (font-latex-faces-present-p 'font-latex-verbatim-face))) - (not (eq major-mode 'doctex-mode)) + (not (LaTeX--doctex-p)) (catch 'found (while (progn (skip-chars-forward "^%" limit) (< (point) limit)) (when (and (save-excursion (zerop (mod (skip-chars-backward - (regexp-quote esc-char)) 2))) + (regexp-quote esc-char)) + 2))) (not (font-latex-faces-present-p 'font-latex-verbatim-face))) (throw 'found t)) @@ -1510,7 +1513,7 @@ If POS is omitted, the current position of point is used." (defun font-latex-forward-comment () "Like `forward-comment' but with special provisions for docTeX mode. In docTeX mode \"%\" at the start of a line will be treated as whitespace." - (if (eq major-mode 'doctex-mode) + (if (LaTeX--doctex-p) ;; XXX: We should probably cater for ^^A as well. (progn (while (progn (if (bolp) (skip-chars-forward "%")) @@ -1767,7 +1770,7 @@ cases.") (pos (funcall search))) (while (and pos (member (match-string 1) -(if (eq major-mode 'doctex-mode) +(if (LaTeX--doctex-p) (remove "_" font-latex-match-simple-exclude-list) font-latex-match-simple-exclude-list))) (setq pos (funcall search))) diff --git a/latex.el b/latex.el index 59ba9cbfc6..02d23803ca 100644 --- a/latex.el +++ b/latex.el @@ -894,6 +894,11 @@ position just before \\begin and the position just before (defvar LaTeX-syntactic-comments) ;; Defined further below. +(defsubst LaTeX--doctex-p () + ;; FIXME: What's the difference between this test and testing + ;; `LaTeX-syntactic-comments'? + (derived-mode-p 'docTeX-mode)) + (defun LaTeX-current-environment (&optional arg) "Return the name (a string) of the enclosing LaTeX environment. With optional ARG>=1, find that outer level. @@ -925,7 +930,7 @@ work analogously." ;; comment-prefix. Hence, the next check just looks ;; if we're inside such a group and returns t to ;; recognize such a situation. - (and (eq major-mode 'doctex-mode) + (and (LaTeX--doctex-p) (member (match-string-no-properties 2) '("macrocode" "macrocode*" (setq arg (if (string= (match-string 1) "end") (1+ arg) (1- arg) @@ -939,7 +944,8 @@ work analogously." (save-excursio
Re: AUCTeX and "builtin latex mode" integration
Hi Stefan, > Stefan Monnier writes: >>> You may have seen an on-going discussion about the annoyance of the >>> mixups between latex-mode and LaTeX-mode and such. >> Could you tell us where that discussion takes place? > I think it's on gnu.emacs.help, aka help-gnu-emacs. Thank you, I'll take a look. > Oh, I wasn't aware of regression. We can workaround the problem > using the `depth` property on `advice-add`, to make sure AUCTeX's advice > takes precedence over that of `tex-mode.el` even if it's > installed before. > E.g. if you add the patch below to Emacs, can you confirm that it fixes > the problem on your end? Confirmed, it works as expected. > diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el > index f624b604aac..77c0d234206 100644 > --- a/lisp/textmodes/tex-mode.el > +++ b/lisp/textmodes/tex-mode.el > @@ -1014,7 +1014,10 @@ tex-mode > says which mode to use." >(tex-common-initialization)) > -(advice-add 'tex-mode :around #'tex--redirect-to-submode) > +(advice-add 'tex-mode :around #'tex--redirect-to-submode > +;; Give it lower precedence than normal advice, so > +;; AUCTeX's advice takes precedence over it. > +'((depth . 50))) > (defvar tex-mode--recursing nil) > (defun tex--redirect-to-submode (orig-fun) >"Redirect to one of the submodes when called directly." > I pushed this to `emacs-28` so it will be fixed in the next Emacs > release (but that may be Emacs-29.1). In the mean time, you can use > a `((depth . -10))` in AUCTeX to make it work with Emacs-28.1. I'll do. >> 3. Currently, there is defect in handling doc strings of AUCTeX LaTeX >> mode, plain TeX mode and docTeX mode; C-h m and C-h f show doc string >> of built-in modes, not AUCTeX modes. > Maybe the help facility should be more careful in how it builds the > docstring when a function has an `:override` advice, indeed. > Could you `M-x report-emacs-bug` for that? I'll do this, too, probably. >> `AUCTeX-mode' should put suitable `function-documentation' property >> for the respective major mode symbol. > I think that would be exactly the kind of messing around I'd like to > move away from. Hmm. Then C-h m and C-h f will continue to show the doc string of the built-in modes if `AUCTeX-mode' minor mode is implemented in the suggested manner, even if the help facility is modified to take care of :override advice. Is there any good alternative approach to display doc strings of AUCTeX? (But it may be too early to discuss the implementation detail of this level.) >> From the users' point of view, I don't think it matters much. They just >> specify >> %%% mode: latex >> as the file local variable and think that they are using `latex-mode'. >> I think that it would be only Elisp programmers that care about the >> "lies". > There's regularly discussion (among (AUC)TeX Emacs users) about which > major mode runs which hook. I think it's an important issue not just > for ELisp programmers. I see. The hook name inconsistency must be indeed cause of trouble for emacs users new to AUCTeX. Regards, Ikumi Keita #StandWithUkraine #StopWarInUkraine
Re: AUCTeX and "builtin latex mode" integration
> Maybe we could start by stating some goals: > > - AUCTeX should not set the `major-mode` to point to > non-AUCTeX functions (even if/when it overrides those functions). > > - Cleanup the mode function names. Currently, AUCTeX's LaTeX mode is > variously called: > > latex-mode > TeX-latex-mode > LaTeX-mode > > AUCTeX should pick one and stick to it as much as possible (e.g. fix > all the docs and have the auxiliary user-exposed variables be named > accordingly to the base major mode name). Maybe other goals could be to reduce user-confusion by having only "one" mode, tho it's not clear what that would mean. But I think we should come up with a long-term plan (which can include changes in Emacs's built-in `tex-mode.el`: co-evolution is more difficult, but if we can agree on a long term plan, we can then figure out how to get there incrementally). Stefan PS: For the record, I'm one of the those Emacs users who doesn't use AUCTeX: I stopped using AUCTeX many years ago when I decided that since AUCTeX couldn't be part of Emacs, I should "dogfeed". Now that it's in GNU ELPA that reason doesn't really apply any more, but I keep using that mode out of habit. I'd be just as happy with AUCTeX which I was using quite happily before.
Re: AUCTeX and "builtin latex mode" integration
> Sent: Wednesday, September 21, 2022 at 10:10 AM > From: "Stefan Monnier" > To: "Tassilo Horn" > Cc: "David Kastrup" , auctex-devel@gnu.org > Subject: Re: AUCTeX and "builtin latex mode" integration > > > Maybe we could start by stating some goals: > > > > - AUCTeX should not set the `major-mode` to point to > > non-AUCTeX functions (even if/when it overrides those functions). > > > > - Cleanup the mode function names. Currently, AUCTeX's LaTeX mode is > > variously called: > > > > latex-mode > > TeX-latex-mode > > LaTeX-mode > > > > AUCTeX should pick one and stick to it as much as possible (e.g. fix > > all the docs and have the auxiliary user-exposed variables be named > > accordingly to the base major mode name). > > Maybe other goals could be to reduce user-confusion by having only "one" > mode, tho it's not clear what that would mean. But I think we should > come up with a long-term plan (which can include changes in Emacs's > built-in `tex-mode.el`: co-evolution is more difficult, but if we can > agree on a long term plan, we can then figure out how to get there > incrementally). I like the incremental long term plan on a topic that was initially thought too convoluted to change. Have seen that the built-in tex-mode and latex-mode have two powerful features: 1) the prettify-symbols-mode where things such as \alpha are displayed with the corresponding greek glyph symbol; and 2) the ability to reposition the height of superscripts and subscripts. For the two features, I seem to remember than the rendering proves to be superior in Auctex. Could you see whether using the functionality from the Auctex implementation be used. This might then simplify things somehow, in that Auctex could then focus on the other aspects not present in the built-in tex-mode and latex-mode. > PS: For the record, I'm one of the those Emacs users who doesn't use > AUCTeX: I stopped using AUCTeX many years ago when I decided > that since AUCTeX couldn't be part of Emacs, I should "dogfeed". > Now that it's in GNU ELPA that reason doesn't really apply any more, > but I keep using that mode out of habit. I'd be just as happy with AUCTeX > which I was using quite happily before.