GNU bug report logs - #70807
Resetting *-local variables before parsing

Previous Next

Package: auctex;

Reported by: Arash Esbati <arash <at> gnu.org>

Date: Mon, 6 May 2024 19:11:02 UTC

Severity: normal

Tags: fixed

Fixed in version 14.1.0

Done: Arash Esbati <arash <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 70807 in the body.
You can then email your comments to 70807 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-auctex <at> gnu.org:
bug#70807; Package auctex. (Mon, 06 May 2024 19:11:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Arash Esbati <arash <at> gnu.org>:
New bug report received and forwarded. Copy sent to bug-auctex <at> gnu.org. (Mon, 06 May 2024 19:11:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Arash Esbati <arash <at> gnu.org>
To: "auctex-bugs" <bug-auctex <at> gnu.org>
Subject: Resetting *-local variables before parsing
Date: Mon, 06 May 2024 21:10:05 +0200
Hi all,

please save this small file on your HD and call it 'minimal-test.tex'.

--8<---------------cut here---------------start------------->8---
\documentclass{article}

\begin{document}
text body.
\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
--8<---------------cut here---------------end--------------->8---

Now set `TeX-parse-self' to t and open the file, hit 'C-c C-n' and the
parsed file 'minimal-test.el' should look like this:

--8<---------------cut here---------------start------------->8---
;; -*- lexical-binding: t; -*-

(TeX-add-style-hook
 "minimal-test"
 (lambda ()
   (TeX-run-style-hooks
    "latex2e"
    "article"
    "art10"))
 :latex)
--8<---------------cut here---------------end--------------->8---

Now move point into preamble and do

   C-c C-m usepackage RET hyperref RET RET C-c C-n

minimal-test.el should look like this now:

--8<---------------cut here---------------start------------->8---
;; -*- lexical-binding: t; -*-

(TeX-add-style-hook
 "minimal-test"
 (lambda ()
   (add-to-list 'LaTeX-verbatim-macros-with-braces-local "href")
   (add-to-list 'LaTeX-verbatim-macros-with-braces-local "hyperimage")
   (add-to-list 'LaTeX-verbatim-macros-with-braces-local "hyperbaseurl")
   (add-to-list 'LaTeX-verbatim-macros-with-braces-local "nolinkurl")
   (add-to-list 'LaTeX-verbatim-macros-with-braces-local "url")
   (add-to-list 'LaTeX-verbatim-macros-with-braces-local "path")
   (add-to-list 'LaTeX-verbatim-macros-with-delims-local "path")
   (TeX-run-style-hooks
    "latex2e"
    "article"
    "art10"
    "hyperref"))
 :latex)
--8<---------------cut here---------------end--------------->8---

Now comment out the \usepackage{hyperref} and again 'C-c C-n', the
file looks like this:

--8<---------------cut here---------------start------------->8---
;; -*- lexical-binding: t; -*-

(TeX-add-style-hook
 "minimal-test"
 (lambda ()
   (add-to-list 'LaTeX-verbatim-macros-with-braces-local "path")
   (add-to-list 'LaTeX-verbatim-macros-with-braces-local "url")
   (add-to-list 'LaTeX-verbatim-macros-with-braces-local "nolinkurl")
   (add-to-list 'LaTeX-verbatim-macros-with-braces-local "hyperbaseurl")
   (add-to-list 'LaTeX-verbatim-macros-with-braces-local "hyperimage")
   (add-to-list 'LaTeX-verbatim-macros-with-braces-local "href")
   (add-to-list 'LaTeX-verbatim-macros-with-delims-local "path")
   (TeX-run-style-hooks
    "latex2e"
    "article"
    "art10"))
 :latex)
--8<---------------cut here---------------end--------------->8---

Note how the entry for "hyperref" is gone, but not the add-to-list
forms; the value of LaTeX-verbatim-* are not reset.  This probably
applies for `LaTeX-verbatim-environments-local', but I didn't check.

For me, the value of the -local version should be reset somewhere before
parsing and running the style hooks again, but I couldn't find an
appropriate place.  Does this approach make sense?  And if yes, any idea
where to put the reset?  Any comments welcome.

Best, Arash




Information forwarded to bug-auctex <at> gnu.org:
bug#70807; Package auctex. (Sat, 22 Feb 2025 07:10:03 GMT) Full text and rfc822 format available.

Message #8 received at 70807 <at> debbugs.gnu.org (full text, mbox):

From: Ikumi Keita <ikumi <at> ikumi.que.jp>
To: Arash Esbati <arash <at> gnu.org>
Cc: 70807 <at> debbugs.gnu.org
Subject: Re: bug#70807: Resetting *-local variables before parsing
Date: Sat, 22 Feb 2025 16:09:35 +0900
Hi Arash, sorry for late respose.

>>>>> Arash Esbati <arash <at> gnu.org> writes:
> Note how the entry for "hyperref" is gone, but not the add-to-list
> forms; the value of LaTeX-verbatim-* are not reset.  This probably
> applies for `LaTeX-verbatim-environments-local', but I didn't check.

> For me, the value of the -local version should be reset somewhere before
> parsing and running the style hooks again, but I couldn't find an
> appropriate place.  Does this approach make sense?  And if yes, any idea
> where to put the reset?  Any comments welcome.

I agree that -local variables should be cleared at C-c C-n. My
preliminary idea is to record names of such variables in a new internal
variable and kill them in `TeX-normal-mode' like
        (dolist (var TeX-normal-mode-reset-list)
          (set var nil)))
. (Maybe that new variable can be used to simplify `TeX-auto-store'.)

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine
#Gaza #StopMassiveKilling #CeasefireNOW




Information forwarded to bug-auctex <at> gnu.org:
bug#70807; Package auctex. (Sun, 23 Feb 2025 15:55:02 GMT) Full text and rfc822 format available.

Message #11 received at 70807 <at> debbugs.gnu.org (full text, mbox):

From: Arash Esbati <arash <at> gnu.org>
To: Ikumi Keita <ikumi <at> ikumi.que.jp>
Cc: 70807 <at> debbugs.gnu.org
Subject: Re: bug#70807: Resetting *-local variables before parsing
Date: Sun, 23 Feb 2025 16:53:59 +0100
Hi Keiat,

Ikumi Keita <ikumi <at> ikumi.que.jp> writes:

> Hi Arash, sorry for late respose.

No problem!

> I agree that -local variables should be cleared at C-c C-n. My
> preliminary idea is to record names of such variables in a new
> internal variable and kill them in `TeX-normal-mode' like
>         (dolist (var TeX-normal-mode-reset-list)
>           (set var nil)))
> . (Maybe that new variable can be used to simplify `TeX-auto-store'.)

I did some test with resetting the *-local variables in different
places, but none of them was really satisfactory.  Doing the reset in
`TeX-normal-mode' top-level means that the values are never written back
into the parsed-file.el since

  (TeX-update-style t)

comes last in that function.  The best thing I can currently come up
with is to add those variables to `TeX-normal-mode-reset-list' as well.

Any other ideas?

Best, Arash




Information forwarded to bug-auctex <at> gnu.org:
bug#70807; Package auctex. (Mon, 24 Feb 2025 17:48:02 GMT) Full text and rfc822 format available.

Message #14 received at 70807 <at> debbugs.gnu.org (full text, mbox):

From: Ikumi Keita <ikumi <at> ikumi.que.jp>
To: Arash Esbati <arash <at> gnu.org>
Cc: 70807 <at> debbugs.gnu.org
Subject: Re: bug#70807: Resetting *-local variables before parsing
Date: Tue, 25 Feb 2025 02:47:23 +0900
Hi Arash,

>>>>> Arash Esbati <arash <at> gnu.org> writes:
> I did some test with resetting the *-local variables in different
> places, but none of them was really satisfactory.  Doing the reset in
> `TeX-normal-mode' top-level means that the values are never written back
> into the parsed-file.el since

>   (TeX-update-style t)

> comes last in that function.

Thanks, now I realize what is difficult. What we are facing is related
to this comment in `TeX-run-style-hooks':
;; This happens in case some style added a new parser, and
;; now the style isn't used anymore (user deleted
;; \usepackage{style}).  Then we're left over with, e.g.,
;; (LaTeX-add-siunitx-units "\\parsec"), but the function is
;; defined in a style siunitx.el that's not loaded anymore.

The problem is hard to solve because it is almost impossible for AUCTeX
to be aware that the user has deleted or commented out \usepackage :-(


...Hmm, I began to be puzzled. I realize that I'm not sure why we need
the entries for `LaTeX-verbatim-macros-with-delims-local' in
parsed-file.el. `TeX-run-style-hooks' in the parsed-file.el runs hooks
associated with "hyperref", one of which adds various items to -local
variables as expected, even for child files which are \include'd or
\input'ted. What am I missing?

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine
#Gaza #StopMassiveKilling #CeasefireNOW




Information forwarded to bug-auctex <at> gnu.org:
bug#70807; Package auctex. (Mon, 24 Feb 2025 19:41:01 GMT) Full text and rfc822 format available.

Message #17 received at 70807 <at> debbugs.gnu.org (full text, mbox):

From: Arash Esbati <arash <at> gnu.org>
To: Ikumi Keita <ikumi <at> ikumi.que.jp>
Cc: 70807 <at> debbugs.gnu.org
Subject: Re: bug#70807: Resetting *-local variables before parsing
Date: Mon, 24 Feb 2025 20:40:17 +0100
Hi Keita,

Ikumi Keita <ikumi <at> ikumi.que.jp> writes:

> Thanks, now I realize what is difficult. What we are facing is related
> to this comment in `TeX-run-style-hooks':
> ;; This happens in case some style added a new parser, and
> ;; now the style isn't used anymore (user deleted
> ;; \usepackage{style}).  Then we're left over with, e.g.,
> ;; (LaTeX-add-siunitx-units "\\parsec"), but the function is
> ;; defined in a style siunitx.el that's not loaded anymore.
>
> The problem is hard to solve because it is almost impossible for AUCTeX
> to be aware that the user has deleted or commented out \usepackage :-(

Thanks.  Indeed, AUCTeX will know about a removed \usepackage after the
next re-parse, which can be late.

> ...Hmm, I began to be puzzled. I realize that I'm not sure why we need
> the entries for `LaTeX-verbatim-macros-with-delims-local' in
> parsed-file.el. `TeX-run-style-hooks' in the parsed-file.el runs hooks
> associated with "hyperref", one of which adds various items to -local
> variables as expected, even for child files which are \include'd or
> \input'ted. What am I missing?

Probably the same bit I'm missing 🧐  I always wondered why that
information is written to a parsed-file.el because of the reasons you
mentioned above.

Best, Arash




Information forwarded to bug-auctex <at> gnu.org:
bug#70807; Package auctex. (Thu, 27 Feb 2025 14:50:02 GMT) Full text and rfc822 format available.

Message #20 received at 70807 <at> debbugs.gnu.org (full text, mbox):

From: Ikumi Keita <ikumi <at> ikumi.que.jp>
To: Arash Esbati <arash <at> gnu.org>
Cc: 70807 <at> debbugs.gnu.org
Subject: Re: bug#70807: Resetting *-local variables before parsing
Date: Thu, 27 Feb 2025 23:49:35 +0900
Hi Arash,

>>>>> Arash Esbati <arash <at> gnu.org> writes:
> Ikumi Keita <ikumi <at> ikumi.que.jp> writes:
>> ...Hmm, I began to be puzzled. I realize that I'm not sure why we need
>> the entries for `LaTeX-verbatim-macros-with-delims-local' in
>> parsed-file.el. `TeX-run-style-hooks' in the parsed-file.el runs hooks
>> associated with "hyperref", one of which adds various items to -local
>> variables as expected, even for child files which are \include'd or
>> \input'ted. What am I missing?

> Probably the same bit I'm missing 🧐  I always wondered why that
> information is written to a parsed-file.el because of the reasons you
> mentioned above.

OK, I see. This feature was introduced by this commit:
,----
| d3d05d462afbe69687277f7fc0dd09e6ef2ff113
| Author:     Tassilo Horn <tsdh <at> gnu.org>
| AuthorDate: Sat Dec 20 09:10:47 2014 +0100
| Commit:     Tassilo Horn <tsdh <at> gnu.org>
| CommitDate: Sat Dec 20 09:10:47 2014 +0100
| 
| Make some buffer-local vars document-local.
| 
| * tex.el (TeX-auto-store): Write LaTeX-verbatim-*-local variables
| to auto file to make them document-local.
`----
Tassilo explained the detail in [1]:
,----
| But this only
| works in singe-file documents.  As soon as you have
| 
|   preamble.tex % lots of \newminted defs
|   main.tex     % here the generated environments are used
| 
| where main.tex is the `TeX-master' the declaration that elispcode and
| elispcode* are verbatim environments is only available in preamble.tex,
| not in the master (or rather the complete doc).
`----

minted.el adds new elements to LaTeX-verbatim-*-local variables
dynamically based on parsing, in `LaTeX-minted-auto-cleanup' added in
`TeX-auto-cleanup-hook'. Hence, without the entries for
LaTeX-verbatim-*-local variables in the parsed-file.el, the main file
wouldn't know the new verbatim constructs, because in the main.tex
buffer, AUCTeX parses only main.tex, not the child preamble.tex. :-(

I'll ponder to seek some good idea, but probably I'll fail...

[1] https://lists.gnu.org/r/auctex/2014-12/msg00044.html
    https://lists.gnu.org/r/auctex/2014-12/msg00049.html

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine
#Gaza #StopMassiveKilling #CeasefireNOW




Information forwarded to bug-auctex <at> gnu.org:
bug#70807; Package auctex. (Fri, 28 Feb 2025 10:35:02 GMT) Full text and rfc822 format available.

Message #23 received at 70807 <at> debbugs.gnu.org (full text, mbox):

From: Arash Esbati <arash <at> gnu.org>
To: Ikumi Keita <ikumi <at> ikumi.que.jp>
Cc: 70807 <at> debbugs.gnu.org
Subject: Re: bug#70807: Resetting *-local variables before parsing
Date: Fri, 28 Feb 2025 11:33:51 +0100
Hi Keita,

Ikumi Keita <ikumi <at> ikumi.que.jp> writes:

> OK, I see. This feature was introduced by this commit:
> ,----
> | d3d05d462afbe69687277f7fc0dd09e6ef2ff113
> | Author:     Tassilo Horn <tsdh <at> gnu.org>
> | AuthorDate: Sat Dec 20 09:10:47 2014 +0100
> | Commit:     Tassilo Horn <tsdh <at> gnu.org>
> | CommitDate: Sat Dec 20 09:10:47 2014 +0100
> | 
> | Make some buffer-local vars document-local.
> | 
> | * tex.el (TeX-auto-store): Write LaTeX-verbatim-*-local variables
> | to auto file to make them document-local.
> `----

Thanks for digging into this, I see now.

> minted.el adds new elements to LaTeX-verbatim-*-local variables
> dynamically based on parsing, in `LaTeX-minted-auto-cleanup' added in
> `TeX-auto-cleanup-hook'. Hence, without the entries for
> LaTeX-verbatim-*-local variables in the parsed-file.el, the main file
> wouldn't know the new verbatim constructs, because in the main.tex
> buffer, AUCTeX parses only main.tex, not the child preamble.tex. :-(
>
> I'll ponder to seek some good idea, but probably I'll fail...

I'm looking forward to that.  I think my current (final) idea is to add
those variables to `TeX-normal-mode-reset-list', so they can be reset
with 'C-u C-c C-n'.  It seems better that what we have right now which
is deleting the auto-generated .el file and/or even restarting Emacs.

Best, Arash




Information forwarded to bug-auctex <at> gnu.org:
bug#70807; Package auctex. (Wed, 05 Mar 2025 10:38:02 GMT) Full text and rfc822 format available.

Message #26 received at 70807 <at> debbugs.gnu.org (full text, mbox):

From: Ikumi Keita <ikumi <at> ikumi.que.jp>
To: Arash Esbati <arash <at> gnu.org>
Cc: 70807 <at> debbugs.gnu.org
Subject: Re: bug#70807: Resetting *-local variables before parsing
Date: Wed, 05 Mar 2025 19:37:24 +0900
Hi Arash,

>>>>> Arash Esbati <arash <at> gnu.org> writes:
>> I'll ponder to seek some good idea, but probably I'll fail...

> I'm looking forward to that.  I think my current (final) idea is to add
> those variables to `TeX-normal-mode-reset-list', so they can be reset
> with 'C-u C-c C-n'.

I didn't come up with a good idea. I agree that your idea is reasonable
approach.

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine
#Gaza #StopMassiveKilling #CeasefireNOW




Information forwarded to bug-auctex <at> gnu.org:
bug#70807; Package auctex. (Thu, 06 Mar 2025 09:15:01 GMT) Full text and rfc822 format available.

Message #29 received at 70807 <at> debbugs.gnu.org (full text, mbox):

From: Arash Esbati <arash <at> gnu.org>
To: Ikumi Keita <ikumi <at> ikumi.que.jp>
Cc: 70807 <at> debbugs.gnu.org
Subject: Re: bug#70807: Resetting *-local variables before parsing
Date: Thu, 06 Mar 2025 10:14:06 +0100
tags 70807 fixed
close 70807 14.1.0
thanks

Hi Keita,

Ikumi Keita <ikumi <at> ikumi.que.jp> writes:

> I didn't come up with a good idea. I agree that your idea is reasonable
> approach.

Thanks for looking at this issue again.  I installed that change with
commit 0718ac55, therefore closing this report.

Best, Arash




Added tag(s) fixed. Request was from Arash Esbati <arash <at> gnu.org> to control <at> debbugs.gnu.org. (Thu, 06 Mar 2025 09:15:02 GMT) Full text and rfc822 format available.

bug marked as fixed in version 14.1.0, send any further explanations to 70807 <at> debbugs.gnu.org and Arash Esbati <arash <at> gnu.org> Request was from Arash Esbati <arash <at> gnu.org> to control <at> debbugs.gnu.org. (Thu, 06 Mar 2025 09:15:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 03 Apr 2025 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 77 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.