GNU bug report logs -
#76615
14.0.9; error with amsmath style hooks
Previous Next
Reported by: "Paul D. Nelson" <ultrono <at> gmail.com>
Date: Thu, 27 Feb 2025 18:31:02 UTC
Severity: normal
Found in version 14.0.9
Done: Stefan Monnier <monnier <at> iro.umontreal.ca>
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 76615 in the body.
You can then email your comments to 76615 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-auctex <at> gnu.org
:
bug#76615
; Package
auctex
.
(Thu, 27 Feb 2025 18:31:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
"Paul D. Nelson" <ultrono <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-auctex <at> gnu.org
.
(Thu, 27 Feb 2025 18:31:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Hi all,
Evaluating the following after Emacs -Q
(progn
(package-initialize)
(package-activate 'auctex)
(add-hook 'LaTeX-mode-hook #'turn-on-reftex)
(with-temp-buffer
(LaTeX-mode)
(TeX-run-style-hooks "amsmath")))
gives the backtrace:
Debugger entered--Lisp error: (wrong-type-argument stringp nil)
expand-file-name(nil)
reftex-TeX-master-file()
reftex-tie-multifile-symbols()
reftex-add-to-label-alist((AMSTeX))
#f(compiled-function () #<bytecode 0x1528d667892913ee>)()
#<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_105>([TeX-style-hook #f(compiled-function () #<bytecode 0x1528d667892913ee>) 1])
mapcar(#<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_105> ([TeX-style-hook #f(compiled-function () #<bytecode 0x1528d667892913ee>) 1]))
#<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_106>("amsmath")
TeX-run-style-hooks("amsmath")
(progn (LaTeX-mode) (TeX-run-style-hooks "amsmath"))
(unwind-protect (progn (LaTeX-mode) (TeX-run-style-hooks "amsmath")) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))
(save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (LaTeX-mode) (TeX-run-style-hooks "amsmath")) (and (buffer-name temp-buffer) (kill-buffer temp-buffer))))
(let ((temp-buffer (generate-new-buffer " *temp*" t))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (LaTeX-mode) (TeX-run-style-hooks "amsmath")) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))))
(progn (package-initialize) (package-activate 'auctex) (add-hook 'LaTeX-mode-hook #'turn-on-reftex) (let ((temp-buffer (generate-new-buffer " *temp*" t))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (LaTeX-mode) (TeX-run-style-hooks "amsmath")) (and (buffer-name temp-buffer) (kill-buffer temp-buffer))))))
eval((progn (package-initialize) (package-activate 'auctex) (add-hook 'LaTeX-mode-hook #'turn-on-reftex) (let ((temp-buffer (generate-new-buffer " *temp*" t))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (LaTeX-mode) (TeX-run-style-hooks "amsmath")) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))))) nil)
elisp--eval-last-sexp(nil)
#f(compiled-function () #<bytecode 0x1866e7a2d80a>)()
eval-last-sexp(nil)
funcall-interactively(eval-last-sexp nil)
command-execute(eval-last-sexp)
I tried this on both the latest AUCTeX release and some earlier 14.0.4
that was lying around.
The issue arose when using log-edit-generate-changelog-from-diff for a
commit involving tex files. I distilled it down to the above example.
It's clear what's happening -- reftex expects a master file, but it's a
non-file buffer. I don't know enough about style hooks to diagnose why
reftex is being called in this manner in this situation.
Any suggestions would be welcome.
Thanks, best,
Paul
Emacs : GNU Emacs 31.0.50 (build 2, aarch64-apple-darwin24.1.0, NS appkit-2575.20 Version 15.1.1 (Build 24B91))
of 2025-02-27
Package: 14.0.9
current state:
==============
(setq
window-system 'ns
LaTeX-version "2e"
TeX-style-path '("~/.emacs.d/auctex/" "/Users/au710211/.emacs.d/elpa/auctex-14.0.9/style"
"/Users/au710211/.emacs.d/auctex/auto" "/Users/au710211/.emacs.d/auctex/style" "auto" "style")
TeX-auto-save nil
TeX-parse-self nil
TeX-master t
TeX-command-list '(("TeX" "%(PDF)%(tex) %(file-line-error) %`%(extraopts) %S%(PDFout)%(mode)%' %(output-dir) %t"
TeX-run-TeX nil (plain-TeX-mode AmSTeX-mode Texinfo-mode) :help "Run plain TeX")
("LaTeX" "%`%l%(mode)%' %T" TeX-run-TeX nil (LaTeX-mode docTeX-mode) :help "Run LaTeX")
("Makeinfo" "makeinfo %(extraopts) %(o-dir) %t" TeX-run-compile nil (Texinfo-mode) :help
"Run Makeinfo with Info output")
("Makeinfo HTML" "makeinfo %(extraopts) %(o-dir) --html %t" TeX-run-compile nil (Texinfo-mode)
:help "Run Makeinfo with HTML output")
("AmSTeX" "amstex %(PDFout) %`%(extraopts) %S%(mode)%' %(output-dir) %t" TeX-run-TeX nil
(AmSTeX-mode) :help "Run AMSTeX")
("ConTeXt" "%(cntxcom) --once %(extraopts) %(execopts)%t" TeX-run-TeX nil (ConTeXt-mode) :help
"Run ConTeXt once")
("ConTeXt Full" "%(cntxcom) %(extraopts) %(execopts)%t" TeX-run-TeX nil (ConTeXt-mode) :help
"Run ConTeXt until completion")
("BibTeX" "bibtex %(O?aux)" TeX-run-BibTeX nil
(plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode ConTeXt-mode) :help
"Run BibTeX")
("Biber" "biber %(output-dir) %s" TeX-run-Biber nil
(plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode) :help "Run Biber")
("Texindex" "texindex %s.??" TeX-run-command nil (Texinfo-mode) :help "Run Texindex")
("Texi2dvi" "%(PDF)texi2dvi %t" TeX-run-command nil (Texinfo-mode) :help
"Run Texi2dvi or Texi2pdf")
("View" "%V" TeX-run-discard-or-function t t :help "Run Viewer")
("Print" "%p" TeX-run-command t t :help "Print the file")
("Queue" "%q" TeX-run-background nil t :help "View the printer queue" :visible
TeX-queue-command)
("File" "%(o?)dvips %d -o %f " TeX-run-dvips t
(plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode) :help
"Generate PostScript file")
("Dvips" "%(o?)dvips %d -o %f " TeX-run-dvips nil
(plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode) :help
"Convert DVI file to PostScript")
("Dvipdfmx" "dvipdfmx -o %(O?pdf) %d" TeX-run-dvipdfmx nil
(plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode) :help
"Convert DVI file to PDF with dvipdfmx")
("Ps2pdf" "ps2pdf %f %(O?pdf)" TeX-run-ps2pdf nil
(plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode) :help
"Convert PostScript file to PDF")
("LaTeXMk"
"latexmk %(latexmk-out) %(file-line-error) %(output-dir) %`%(extraopts) %S%(mode)%' %t"
TeX-run-TeX nil (LaTeX-mode docTeX-mode) :help "Run LaTeXMk")
("Glossaries" "makeglossaries %(d-dir) %s" TeX-run-command nil
(plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode) :help
"Run makeglossaries to create glossary file")
("Index" "makeindex %(O?idx)" TeX-run-index nil
(plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode) :help
"Run makeindex to create index file")
("upMendex" "upmendex %(O?idx)" TeX-run-index t
(plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode) :help
"Run upmendex to create index file")
("Xindy" "texindy %s" TeX-run-command nil
(plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode) :help
"Run xindy to create index file")
("Check" "lacheck %s" TeX-run-compile nil (LaTeX-mode) :help "Check LaTeX file for correctness")
("ChkTeX" "chktex -v6 %s" TeX-run-compile nil (LaTeX-mode) :help
"Check LaTeX file for common mistakes")
("Spell" "(TeX-ispell-document \"\")" TeX-run-function nil t :help "Spell-check the document")
("Clean" "TeX-clean" TeX-run-function nil t :help "Delete generated intermediate files")
("Clean All" "(TeX-clean t)" TeX-run-function nil t :help
"Delete generated intermediate and output files")
("Other" "" TeX-run-command t t :help "Run an arbitrary command"))
)
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#76615
; Package
auctex
.
(Fri, 28 Feb 2025 07:53:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 76615 <at> debbugs.gnu.org (full text, mbox):
Hi Paul,
"Paul D. Nelson" <ultrono <at> gmail.com> writes:
> Evaluating the following after Emacs -Q
>
> (progn
> (package-initialize)
> (package-activate 'auctex)
> (add-hook 'LaTeX-mode-hook #'turn-on-reftex)
> (with-temp-buffer
> (LaTeX-mode)
> (TeX-run-style-hooks "amsmath")))
>
> gives the backtrace:
>
> Debugger entered--Lisp error: (wrong-type-argument stringp nil)
> expand-file-name(nil)
> reftex-TeX-master-file()
> reftex-tie-multifile-symbols()
> reftex-add-to-label-alist((AMSTeX))
I think this is because of this part of amsmath.el[1]:
;; RefTeX support: Tell RefTeX about amsmath environments.
(when (fboundp 'reftex-add-to-label-alist)
(reftex-add-to-label-alist '(AMSTeX)))
> The issue arose when using log-edit-generate-changelog-from-diff for a
> commit involving tex files. I distilled it down to the above example.
I'd say the form above was in amsmath.el since forever :-)
HTH. Best, Arash
Footnotes:
[1] https://git.savannah.gnu.org/cgit/auctex.git/tree/style/amsmath.el#n165
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#76615
; Package
auctex
.
(Fri, 28 Feb 2025 15:23:04 GMT)
Full text and
rfc822 format available.
Message #11 received at 76615 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Hi Arash,
>
> I think this is because of this part of amsmath.el[1]:
>
> ;; RefTeX support: Tell RefTeX about amsmath environments.
> (when (fboundp 'reftex-add-to-label-alist)
> (reftex-add-to-label-alist '(AMSTeX)))
>
>> The issue arose when using log-edit-generate-changelog-from-diff for a
>> commit involving tex files. I distilled it down to the above example.
>
> I'd say the form above was in amsmath.el since forever :-)
>
Indeed.
The attached patch addresses the issue for me. Thoughts?
Paul
[Message part 2 (text/plain, inline)]
diff --git a/style/amsmath.el b/style/amsmath.el
index 9d6944dc..68cd5983 100644
--- a/style/amsmath.el
+++ b/style/amsmath.el
@@ -163,7 +163,8 @@
(TeX-run-style-hooks "amstext" "amsbsy" "amsopn")
;; RefTeX support: Tell RefTeX about amsmath environments.
- (when (fboundp 'reftex-add-to-label-alist)
+ (when (and (fboundp 'reftex-add-to-label-alist)
+ (buffer-file-name))
(reftex-add-to-label-alist '(AMSTeX)))
;; Add \eqref to `reftex-ref-style-alist' and associate it to `e'
@@ -180,6 +181,7 @@
;; is non-nil
(and LaTeX-reftex-ref-style-auto-activate
(fboundp 'reftex-ref-style-activate)
+ (buffer-file-name)
(reftex-ref-style-activate "AMSmath"))
(when (and (featurep 'font-latex)
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#76615
; Package
auctex
.
(Fri, 28 Feb 2025 15:55:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 76615 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
"Paul D. Nelson" <ultrono <at> gmail.com> writes:
>
> The attached patch addresses the issue for me. Thoughts?
>
Here's a more complete version, addressing related issues. This feels a
bit like plugging a leak with a band-aid, so other suggestions would
also be welcome.
[Message part 2 (text/plain, inline)]
diff --git a/style/amsmath.el b/style/amsmath.el
index 9d6944dc..68cd5983 100644
--- a/style/amsmath.el
+++ b/style/amsmath.el
@@ -163,7 +163,8 @@
(TeX-run-style-hooks "amstext" "amsbsy" "amsopn")
;; RefTeX support: Tell RefTeX about amsmath environments.
- (when (fboundp 'reftex-add-to-label-alist)
+ (when (and (fboundp 'reftex-add-to-label-alist)
+ (buffer-file-name))
(reftex-add-to-label-alist '(AMSTeX)))
;; Add \eqref to `reftex-ref-style-alist' and associate it to `e'
@@ -180,6 +181,7 @@
;; is non-nil
(and LaTeX-reftex-ref-style-auto-activate
(fboundp 'reftex-ref-style-activate)
+ (buffer-file-name)
(reftex-ref-style-activate "AMSmath"))
(when (and (featurep 'font-latex)
diff --git a/style/cleveref.el b/style/cleveref.el
index 129d4ce1..67bece8b 100644
--- a/style/cleveref.el
+++ b/style/cleveref.el
@@ -211,6 +211,7 @@ string."
;; Activate RefTeX reference style.
(and LaTeX-reftex-ref-style-auto-activate
(fboundp 'reftex-ref-style-activate)
+ (buffer-file-name)
(reftex-ref-style-activate "Cleveref")))
TeX-dialect)
diff --git a/style/fancyref.el b/style/fancyref.el
index d2d87bf5..a580fcbf 100644
--- a/style/fancyref.el
+++ b/style/fancyref.el
@@ -103,6 +103,7 @@
;; Activate RefTeX reference style.
(and LaTeX-reftex-ref-style-auto-activate
(fboundp 'reftex-ref-style-activate)
+ (buffer-file-name)
(reftex-ref-style-activate "Fancyref")))
TeX-dialect)
diff --git a/style/hyperref.el b/style/hyperref.el
index 868acd33..e801140b 100644
--- a/style/hyperref.el
+++ b/style/hyperref.el
@@ -343,6 +343,7 @@
;; Activate RefTeX reference style.
(and LaTeX-reftex-ref-style-auto-activate
(fboundp 'reftex-ref-style-activate)
+ (buffer-file-name)
(reftex-ref-style-activate "Hyperref")))
TeX-dialect)
diff --git a/style/refcount.el b/style/refcount.el
index e20ef395..560855c0 100644
--- a/style/refcount.el
+++ b/style/refcount.el
@@ -79,6 +79,7 @@
;; Activate RefTeX reference style
(and LaTeX-reftex-ref-style-auto-activate
(fboundp 'reftex-ref-style-activate)
+ (buffer-file-name)
(reftex-ref-style-activate "Refcount")))
TeX-dialect)
diff --git a/style/varioref.el b/style/varioref.el
index e7f95f7f..b149d4de 100644
--- a/style/varioref.el
+++ b/style/varioref.el
@@ -90,6 +90,7 @@
;; Activate RefTeX reference style.
(and LaTeX-reftex-ref-style-auto-activate
(fboundp 'reftex-ref-style-activate)
+ (buffer-file-name)
(reftex-ref-style-activate "Varioref")))
TeX-dialect)
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#76615
; Package
auctex
.
(Fri, 28 Feb 2025 15:58:02 GMT)
Full text and
rfc822 format available.
Message #17 received at 76615 <at> debbugs.gnu.org (full text, mbox):
Hi Paul and Arash,
>>>>> Arash Esbati <arash <at> gnu.org> writes:
> "Paul D. Nelson" <ultrono <at> gmail.com> writes:
>> Evaluating the following after Emacs -Q
>>
>> (progn
>> (package-initialize)
>> (package-activate 'auctex)
>> (add-hook 'LaTeX-mode-hook #'turn-on-reftex)
>> (with-temp-buffer
>> (LaTeX-mode)
>> (TeX-run-style-hooks "amsmath")))
>>
>> gives the backtrace:
>>
>> Debugger entered--Lisp error: (wrong-type-argument stringp nil)
>> expand-file-name(nil)
>> reftex-TeX-master-file()
>> reftex-tie-multifile-symbols()
>> reftex-add-to-label-alist((AMSTeX))
> I think this is because of this part of amsmath.el[1]:
> ;; RefTeX support: Tell RefTeX about amsmath environments.
> (when (fboundp 'reftex-add-to-label-alist)
> (reftex-add-to-label-alist '(AMSTeX)))
I tried commenting out this part, but it still fails at another part im
amsmath.el:
(and LaTeX-reftex-ref-style-auto-activate
(fboundp 'reftex-ref-style-activate)
(reftex-ref-style-activate "AMSmath"))
>> The issue arose when using log-edit-generate-changelog-from-diff for a
>> commit involving tex files. I distilled it down to the above example.
> I'd say the form above was in amsmath.el since forever :-)
The fundamental origin of the problem is that RefTeX presumes that it
always works in the buffer associated with files. In other words, RefTeX
pays no attention to non-file buffer. (I have such impression, skimming
over the RefTeX code. Please correct me if I'm wrong.)
>>>>> "Paul D. Nelson" <ultrono <at> gmail.com> writes:
> The attached patch addresses the issue for me. Thoughts?
I have basically the same idea, but I think such partial treatment
inctroduces inconsistent internal state of RefTeX and can be potential
problems. Rather I propose to wrap the whole RefTeX management
part in amsmath.el by (when buffer-file-name ... ). In addition, we
should turn off RefTeX mode in `TeX-mode-cleanup' like
(unless buffer-file-truename
(if (bound-and-true-p reftex-mode) <-- addition
(reftex-mode -1)) <-- addition
(TeX-update-style))
to avoid inconsistency.
Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine
#Gaza #StopMassiveKilling #CeasefireNOW
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#76615
; Package
auctex
.
(Fri, 28 Feb 2025 16:08:02 GMT)
Full text and
rfc822 format available.
Message #20 received at 76615 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Hi Ikumi,
>
> The fundamental origin of the problem is that RefTeX presumes that it
> always works in the buffer associated with files. In other words, RefTeX
> pays no attention to non-file buffer. (I have such impression, skimming
> over the RefTeX code. Please correct me if I'm wrong.)
>
This has also been my understanding (although I stopped using RefTeX
years ago, basically for this reason).
>>>>>> "Paul D. Nelson" <ultrono <at> gmail.com> writes:
>> The attached patch addresses the issue for me. Thoughts?
>
> I have basically the same idea, but I think such partial treatment
> inctroduces inconsistent internal state of RefTeX and can be potential
> problems. Rather I propose to wrap the whole RefTeX management
> part in amsmath.el by (when buffer-file-name ... ). In addition, we
> should turn off RefTeX mode in `TeX-mode-cleanup' like
> (unless buffer-file-truename
> (if (bound-and-true-p reftex-mode) <-- addition
> (reftex-mode -1)) <-- addition
> (TeX-update-style))
> to avoid inconsistency.
>
Something like the attached, I guess? There are other uses of "reftex-"
in style/, so I guess something similar should be done for all of them?
Thanks, best,
Paul
[Message part 2 (text/plain, inline)]
diff --git a/style/amsmath.el b/style/amsmath.el
index 9d6944dc..c73f7475 100644
--- a/style/amsmath.el
+++ b/style/amsmath.el
@@ -163,24 +163,25 @@
(TeX-run-style-hooks "amstext" "amsbsy" "amsopn")
;; RefTeX support: Tell RefTeX about amsmath environments.
- (when (fboundp 'reftex-add-to-label-alist)
- (reftex-add-to-label-alist '(AMSTeX)))
-
- ;; Add \eqref to `reftex-ref-style-alist' and associate it to `e'
- (when (and (boundp 'reftex-ref-style-alist)
- ;; check if Emacs is already equipped with this
- (not (assoc "AMSmath" reftex-ref-style-alist)))
- ;; Append it to a local version in order to avoid a clash with
- ;; user settings
- (add-to-list (make-local-variable 'reftex-ref-style-alist)
- '("AMSmath" "amsmath" (("\\eqref" ?e)))
- t))
-
- ;; Activate `AMSmath' when `LaTeX-reftex-ref-style-auto-activate'
- ;; is non-nil
- (and LaTeX-reftex-ref-style-auto-activate
- (fboundp 'reftex-ref-style-activate)
- (reftex-ref-style-activate "AMSmath"))
+ (when buffer-file-truename
+ (when (fboundp 'reftex-add-to-label-alist)
+ (reftex-add-to-label-alist '(AMSTeX)))
+
+ ;; Add \eqref to `reftex-ref-style-alist' and associate it to `e'
+ (when (and (boundp 'reftex-ref-style-alist)
+ ;; check if Emacs is already equipped with this
+ (not (assoc "AMSmath" reftex-ref-style-alist)))
+ ;; Append it to a local version in order to avoid a clash with
+ ;; user settings
+ (add-to-list (make-local-variable 'reftex-ref-style-alist)
+ '("AMSmath" "amsmath" (("\\eqref" ?e)))
+ t))
+
+ ;; Activate `AMSmath' when `LaTeX-reftex-ref-style-auto-activate'
+ ;; is non-nil
+ (and LaTeX-reftex-ref-style-auto-activate
+ (fboundp 'reftex-ref-style-activate)
+ (reftex-ref-style-activate "AMSmath")))
(when (and (featurep 'font-latex)
(eq TeX-install-font-lock 'font-latex-setup))
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#76615
; Package
auctex
.
(Sat, 01 Mar 2025 03:40:01 GMT)
Full text and
rfc822 format available.
Message #23 received at 76615 <at> debbugs.gnu.org (full text, mbox):
Hi Paul,
>>>>> "Paul D. Nelson" <ultrono <at> gmail.com> writes:
> Something like the attached, I guess?
Yes, that's what I thought.
> There are other uses of "reftex-" in style/, so I guess something
> similar should be done for all of them?
Ideally, yes. (But it seems tedious... Does anyone see possibility to
tame RefTeX to live along with non-file buffer?)
Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine
#Gaza #StopMassiveKilling #CeasefireNOW
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#76615
; Package
auctex
.
(Sat, 01 Mar 2025 07:35:02 GMT)
Full text and
rfc822 format available.
Message #26 received at 76615 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
>> There are other uses of "reftex-" in style/, so I guess something
>> similar should be done for all of them?
>
> Ideally, yes. (But it seems tedious... Does anyone see possibility to
> tame RefTeX to live along with non-file buffer?)
>
Making RefTeX work well with non-file buffers always seemed to me like a
major undertaking. The commands
;; reftex-add-index-macros
;; reftex-add-section-levels
;; reftex-add-label-environments
;; reftex-scanning-info-available-p
;; reftex-access-parse-file
;; reftex-access-scan-info
;; reftex-ref-style-list
;; reftex-ref-style-toggle
;; reftex-set-cite-format
each call reftex-tie-multifile-symbols, which in turn calls
reftex-TeX-master-file, which fails (with a hard landing) in a non-file
buffer for which TeX-master has not been set to a tex file.
The attached patch wraps the calls from style files to such functions
with a check for buffer-true-filename (although I would also prefer a
less tedious way to address the underlying issue).
[changes.patch (text/x-patch, attachment)]
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#76615
; Package
auctex
.
(Sat, 01 Mar 2025 18:02:01 GMT)
Full text and
rfc822 format available.
Message #29 received at 76615 <at> debbugs.gnu.org (full text, mbox):
Hi Paul,
>>>>> "Paul D. Nelson" <ultrono <at> gmail.com> writes:
> Making RefTeX work well with non-file buffers always seemed to me like a
> major undertaking. The commands
> ;; reftex-add-index-macros
> ;; reftex-add-section-levels
> ;; reftex-add-label-environments
> ;; reftex-scanning-info-available-p
> ;; reftex-access-parse-file
> ;; reftex-access-scan-info
> ;; reftex-ref-style-list
> ;; reftex-ref-style-toggle
> ;; reftex-set-cite-format
> each call reftex-tie-multifile-symbols, which in turn calls
> reftex-TeX-master-file, which fails (with a hard landing) in a non-file
> buffer for which TeX-master has not been set to a tex file.
Is `reftex-TeX-master-file' the only source of RefTeX non-file buffer
difficulties? If so, I expect there is a possibility that we can amend
it so that RefTeX would not stumble in non-file buffer. For example,
`TeX-master-file' returns "<none>.tex" if it can't find a sensible
master file. What if we implement similar fallback for
`reftex-TeX-master-file'?
Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine
#Gaza #StopMassiveKilling #CeasefireNOW
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#76615
; Package
auctex
.
(Fri, 14 Mar 2025 15:10:02 GMT)
Full text and
rfc822 format available.
Message #32 received at 76615 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Hi Ikumi,
> Is `reftex-TeX-master-file' the only source of RefTeX non-file buffer
> difficulties? If so, I expect there is a possibility that we can amend
> it so that RefTeX would not stumble in non-file buffer. For example,
> `TeX-master-file' returns "<none>.tex" if it can't find a sensible
> master file. What if we implement similar fallback for
> `reftex-TeX-master-file'?
Patching reftex in the suggested way does seem to alleviate the noted
issue with style hooks. I can only imagine it breaks other things, but
given that non-file buffers are already not supported in reftex, maybe
that's OK?
Paul
[Message part 2 (text/x-patch, inline)]
diff --git a/lisp/textmodes/reftex.el b/lisp/textmodes/reftex.el
index 8088ab391f5..2fac7982848 100644
--- a/lisp/textmodes/reftex.el
+++ b/lisp/textmodes/reftex.el
@@ -389,7 +389,9 @@ reftex-TeX-master-file
(t
;; Use buffer file name.
(setq master (buffer-file-name))))
- (expand-file-name master)))
+ (if master
+ (expand-file-name master)
+ "<none>.tex")))
(defun reftex-is-multi ()
;; Tell if this is a multifile document. When not sure, say yes.
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#76615
; Package
auctex
.
(Thu, 20 Mar 2025 12:35:02 GMT)
Full text and
rfc822 format available.
Message #35 received at 76615 <at> debbugs.gnu.org (full text, mbox):
Hi Paul,
>>>>> "Paul D. Nelson" <ultrono <at> gmail.com> writes:
> Patching reftex in the suggested way does seem to alleviate the noted
> issue with style hooks. I can only imagine it breaks other things, but
> given that non-file buffers are already not supported in reftex, maybe
> that's OK?
Thanks for your opinion. Yes, I think that's permissible.
> diff --git a/lisp/textmodes/reftex.el b/lisp/textmodes/reftex.el
I think that we should minimize the change in the RefTeX behavior. How
about the patches below, for both RefTeX and AUCTeX? It introduces a new
flag variable and change the behavior only when the new flag has non-nil
value.
Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine
#Gaza #StopMassiveKilling #CeasefireNOW
diff -r eb0ce6c359be lisp/textmodes/reftex.el
--- a/lisp/textmodes/reftex.el Wed Feb 26 22:15:46 2025 +0900
+++ b/lisp/textmodes/reftex.el Thu Mar 20 21:19:43 2025 +0900
@@ -62,6 +62,12 @@
(setq reftex-tables-dirty t)
(set symbol value)))
+(defvar reftex--suppress-nonfile-error nil
+ "When non-nil, don't signal error in non-file buffer.
+
+Note that this is just a quick and dirty hack and is _not_ reliable at
+all. It only circumvents disastrous error in `reftex-TeX-master-file',
+in case that the user turns on RefTeX in latex mode hook.")
;; Configuration variables
(require 'reftex-vars)
@@ -378,7 +384,8 @@
(buffer-file-name)))))
(cond
((null master)
- (error "Need a filename for this buffer, please save it first"))
+ (or reftex--suppress-nonfile-error
+ (error "Need a filename for this buffer, please save it first")))
((or (file-exists-p (concat master ".tex"))
(find-buffer-visiting (concat master ".tex")))
;; Ahh, an extra .tex was missing...
@@ -390,7 +397,8 @@
(t
;; Use buffer file name.
(setq master (buffer-file-name))))
- (expand-file-name master)))
+ (unless reftex--suppress-nonfile-error
+ (expand-file-name master))))
(defun reftex-is-multi ()
;; Tell if this is a multifile document. When not sure, say yes.
diff --git a/tex.el b/tex.el
index 3d28b2c6..2f650b39 100644
--- a/tex.el
+++ b/tex.el
@@ -102,6 +102,7 @@
(defvar ispell-parser) ; ispell.el
(defvar compilation-error-regexp-alist) ; compile.el
(defvar compilation-in-progress) ; compile.el
+(defvar reftex--suppress-nonfile-error) ; reftex.el
(defconst TeX-mode-comparison-alist
'((plain-tex-mode . plain-TeX-mode)
@@ -3929,7 +3930,12 @@ Run after mode hooks and file local variables application."
;; `find-file-hook'. This is necessary for `xref-find-references',
;; for example. (bug#65912)
(unless buffer-file-truename
- (TeX-update-style))
+ (TeX-update-style)
+
+ ;; Suppress RefTeX error in non-file buffer. (Bug#76615)
+ (when (featurep 'reftex)
+ (setq-local reftex--suppress-nonfile-error t)
+ (reftex-mode -1)))
(TeX-set-mode-name))
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#76615
; Package
auctex
.
(Sun, 23 Mar 2025 00:54:04 GMT)
Full text and
rfc822 format available.
Message #38 received at 76615 <at> debbugs.gnu.org (full text, mbox):
Hi Ikumi,
> I think that we should minimize the change in the RefTeX behavior. How
> about the patches below, for both RefTeX and AUCTeX? It introduces a new
> flag variable and change the behavior only when the new flag has non-nil
> value.
> (...)
> @@ -390,7 +397,8 @@
> (t
> ;; Use buffer file name.
> (setq master (buffer-file-name))))
> - (expand-file-name master)))
> + (unless reftex--suppress-nonfile-error
> + (expand-file-name master))))
>
> (defun reftex-is-multi ()
> ;; Tell if this is a multifile document. When not sure, say yes.
>
The result of reftex-TeX-master-file is passed to file-truename, so it
can be "<none>.tex" but not nil. Modifying your patch as follows seems
to do the trick.
Thanks, best,
Paul
@@ -389,7 +396,9 @@ reftex-TeX-master-file
(t
;; Use buffer file name.
(setq master (buffer-file-name))))
- (expand-file-name master)))
+ (if reftex--suppress-nonfile-error
+ "<none>.tex"
+ (expand-file-name master))))
(defun reftex-is-multi ()
;; Tell if this is a multifile document. When not sure, say yes.
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#76615
; Package
auctex
.
(Mon, 24 Mar 2025 09:11:02 GMT)
Full text and
rfc822 format available.
Message #41 received at 76615 <at> debbugs.gnu.org (full text, mbox):
[ Sorry to have incomplete References: header; I deleted Paul's last post
by mistake. ]
Hi Paul,
>>>>> "Paul D. Nelson" <ultrono <at> gmail.com> writes:
> The result of reftex-TeX-master-file is passed to file-truename, so it
> can be "<none>.tex" but not nil. Modifying your patch as follows seems
> to do the trick.
Thanks. I reconsidered and came to think that we should check whether
`master' is nil. Here is my next proposal:
diff -r 3eca07415d50 lisp/textmodes/reftex.el
--- a/lisp/textmodes/reftex.el Sun Mar 23 02:56:31 2025 +0900
+++ b/lisp/textmodes/reftex.el Mon Mar 24 17:55:36 2025 +0900
@@ -62,6 +62,12 @@
(setq reftex-tables-dirty t)
(set symbol value)))
+(defvar reftex--suppress-nonfile-error nil
+ "When non-nil, don't signal error in non-file buffer.
+
+Note that this is just a quick and dirty hack and is _not_ reliable at
+all. It only circumvents disastrous error in `reftex-TeX-master-file',
+in case that the user turns on RefTeX in latex mode hook.")
;; Configuration variables
(require 'reftex-vars)
@@ -378,7 +384,8 @@
(buffer-file-name)))))
(cond
((null master)
- (error "Need a filename for this buffer, please save it first"))
+ (or reftex--suppress-nonfile-error
+ (error "Need a filename for this buffer, please save it first")))
((or (file-exists-p (concat master ".tex"))
(find-buffer-visiting (concat master ".tex")))
;; Ahh, an extra .tex was missing...
@@ -390,7 +397,10 @@
(t
;; Use buffer file name.
(setq master (buffer-file-name))))
- (expand-file-name master)))
+ (if (and (not master)
+ reftex--suppress-nonfile-error)
+ "<none>.tex"
+ (expand-file-name master))))
(defun reftex-is-multi ()
;; Tell if this is a multifile document. When not sure, say yes.
Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine
#Gaza #StopMassiveKilling #CeasefireNOW
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#76615
; Package
auctex
.
(Tue, 25 Mar 2025 22:49:02 GMT)
Full text and
rfc822 format available.
Message #44 received at 76615 <at> debbugs.gnu.org (full text, mbox):
Hi Ikumi, your last patch looks good and seems to work fine for me.
Thanks, best, Paul
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#76615
; Package
auctex
.
(Wed, 26 Mar 2025 09:16:01 GMT)
Full text and
rfc822 format available.
Message #47 received at 76615 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
>>>>> "Paul D. Nelson" <ultrono <at> gmail.com> writes:
> Hi Ikumi, your last patch looks good and seems to work fine for me.
> Thanks, best, Paul
Thank you, Paul.
Then I'd like someone with write permission of emacs repository to
install the attached patch, please. Then I'll commit the following fix
to the AUCTeX repository.
From b23971c2e37fde9ccfbb8e518c9c0f6f3430a131 Mon Sep 17 00:00:00 2001
From: Ikumi Keita <ikumi <at> ikumi.que.jp>
Date: Wed, 5 Mar 2025 02:37:13 +0900
Subject: [PATCH] Suppress RefTeX error in non-file buffer
* tex.el (TeX-mode-cleanup): In non-file buffer, set up dirty hack for
RefTeX and turn off RefTeX.
---
tex.el | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/tex.el b/tex.el
index 3d28b2c6..2f650b39 100644
--- a/tex.el
+++ b/tex.el
@@ -102,6 +102,7 @@
(defvar ispell-parser) ; ispell.el
(defvar compilation-error-regexp-alist) ; compile.el
(defvar compilation-in-progress) ; compile.el
+(defvar reftex--suppress-nonfile-error) ; reftex.el
(defconst TeX-mode-comparison-alist
'((plain-tex-mode . plain-TeX-mode)
@@ -3929,7 +3930,12 @@ Run after mode hooks and file local variables application."
;; `find-file-hook'. This is necessary for `xref-find-references',
;; for example. (bug#65912)
(unless buffer-file-truename
- (TeX-update-style))
+ (TeX-update-style)
+
+ ;; Suppress RefTeX error in non-file buffer. (Bug#76615)
+ (when (featurep 'reftex)
+ (setq-local reftex--suppress-nonfile-error t)
+ (reftex-mode -1)))
(TeX-set-mode-name))
--
2.48.1
Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine
#Gaza #StopMassiveKilling #CeasefireNOW
[diff (text/x-diff, attachment)]
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#76615
; Package
auctex
.
(Thu, 27 Mar 2025 07:57:04 GMT)
Full text and
rfc822 format available.
Message #50 received at 76615 <at> debbugs.gnu.org (full text, mbox):
Hi Keita,
Ikumi Keita <ikumi <at> ikumi.que.jp> writes:
> Then I'd like someone with write permission of emacs repository to
> install the attached patch, please.
I can do that. Can you please create a patch with git format-patch and
resend it? TIA.
> Then I'll commit the following fix to the AUCTeX repository.
>
> From b23971c2e37fde9ccfbb8e518c9c0f6f3430a131 Mon Sep 17 00:00:00 2001
> From: Ikumi Keita <ikumi <at> ikumi.que.jp>
> Date: Wed, 5 Mar 2025 02:37:13 +0900
> Subject: [PATCH] Suppress RefTeX error in non-file buffer
>
> * tex.el (TeX-mode-cleanup): In non-file buffer, set up dirty hack for
> RefTeX and turn off RefTeX.
> ---
> tex.el | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/tex.el b/tex.el
> index 3d28b2c6..2f650b39 100644
> --- a/tex.el
> +++ b/tex.el
> @@ -102,6 +102,7 @@
> (defvar ispell-parser) ; ispell.el
> (defvar compilation-error-regexp-alist) ; compile.el
> (defvar compilation-in-progress) ; compile.el
> +(defvar reftex--suppress-nonfile-error) ; reftex.el
>
> (defconst TeX-mode-comparison-alist
> '((plain-tex-mode . plain-TeX-mode)
> @@ -3929,7 +3930,12 @@ Run after mode hooks and file local variables application."
> ;; `find-file-hook'. This is necessary for `xref-find-references',
> ;; for example. (bug#65912)
> (unless buffer-file-truename
> - (TeX-update-style))
> + (TeX-update-style)
> +
> + ;; Suppress RefTeX error in non-file buffer. (Bug#76615)
> + (when (featurep 'reftex)
The variable below will be available with Emacs 31. Do you want to add
a check here if `reftex--suppress-nonfile-error' is bound? Or do you
want to set it regardless of being defvar'ed in RefTeX?
> + (setq-local reftex--suppress-nonfile-error t)
> + (reftex-mode -1)))
>
> (TeX-set-mode-name))
Best, Arash
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#76615
; Package
auctex
.
(Fri, 28 Mar 2025 13:29:02 GMT)
Full text and
rfc822 format available.
Message #53 received at 76615 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Hi Arash,
>>>>> Arash Esbati <arash <at> gnu.org> writes:
>> Then I'd like someone with write permission of emacs repository to
>> install the attached patch, please.
> I can do that. Can you please create a patch with git format-patch and
> resend it? TIA.
Sure. I attach the patch.
> The variable below will be available with Emacs 31. Do you want to add
> a check here if `reftex--suppress-nonfile-error' is bound? Or do you
> want to set it regardless of being defvar'ed in RefTeX?
>> + (setq-local reftex--suppress-nonfile-error t)
>> + (reftex-mode -1)))
Thanks for catching this. I'll add `boundp' test instead of `defvar' to
avoid byte compilation warning.
Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine
#Gaza #StopMassiveKilling #CeasefireNOW
[0001-Suppress-error-in-non-file-buffer.patch (text/x-diff, attachment)]
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#76615
; Package
auctex
.
(Tue, 01 Apr 2025 10:31:04 GMT)
Full text and
rfc822 format available.
Message #56 received at 76615 <at> debbugs.gnu.org (full text, mbox):
Hi Keita,
Ikumi Keita <ikumi <at> ikumi.que.jp> writes:
> Sure. I attach the patch.
Thanks, I pushed your change to Emacs master branch (commit 90571269).
Best, Arash
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#76615
; Package
auctex
.
(Wed, 02 Apr 2025 14:38:03 GMT)
Full text and
rfc822 format available.
Message #59 received at 76615 <at> debbugs.gnu.org (full text, mbox):
> The result of reftex-TeX-master-file is passed to file-truename, so it
> can be "<none>.tex" but not nil. Modifying your patch as follows seems
> to do the trick.
>
> Thanks, best,
> Paul
>
>
> @@ -389,7 +396,9 @@ reftex-TeX-master-file
> (t
> ;; Use buffer file name.
> (setq master (buffer-file-name))))
> - (expand-file-name master)))
> + (if reftex--suppress-nonfile-error
> + "<none>.tex"
> + (expand-file-name master))))
I think TRT would be to return the buffer when in a non-file buffer and
then to adjust callers accordingly.
Stefan
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#76615
; Package
auctex
.
(Wed, 02 Apr 2025 20:30:02 GMT)
Full text and
rfc822 format available.
Message #62 received at 76615 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:
>> @@ -389,7 +396,9 @@ reftex-TeX-master-file
>> (t
>> ;; Use buffer file name.
>> (setq master (buffer-file-name))))
>> - (expand-file-name master)))
>> + (if reftex--suppress-nonfile-error
>> + "<none>.tex"
>> + (expand-file-name master))))
>
> I think TRT would be to return the buffer when in a non-file buffer and
> then to adjust callers accordingly.
I agree that the right approach is to make RefTeX work properly in
non-file buffers. To explore this, I implemented the approach you
suggested (see the attached patch). It's a big change that I'm unlikely
to stress-test in my "day job", where for many years I've used a cheap
substitute [1] for RefTeX that I find more efficient for my purposes.
(Any feedback, either on the patch or on how I might better integrate
[1] into the ecosystem, would of course be welcome.)
This bug report arose from a simpler issue: C-x v v C-c C-w in a tex
document (with AUCTeX installed) makes vc activate LaTeX-mode in a
temporary non-file buffer, where AUCTeX style hooks attempt to load
RefTeX (catastrophically). For this narrow issue, the workaround
provided by Ikumi suffices.
[1] https://github.com/ultronozm/czm-tex-ref.el
[0001-Add-RefTeX-support-for-non-file-buffers.patch (text/x-patch, attachment)]
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#76615
; Package
auctex
.
(Wed, 02 Apr 2025 22:14:02 GMT)
Full text and
rfc822 format available.
Message #65 received at 76615 <at> debbugs.gnu.org (full text, mbox):
> I agree that the right approach is to make RefTeX work properly in
> non-file buffers. To explore this, I implemented the approach you
> suggested (see the attached patch).
Looks pretty good. Matches my expectations fairly well.
Should we push it to `master`?
AFAICT it should be safe in the sense that it should not affect behavior
in file buffers. See comments below.
> This bug report arose from a simpler issue: C-x v v C-c C-w in a tex
> document (with AUCTeX installed) makes vc activate LaTeX-mode in a
> temporary non-file buffer, where AUCTeX style hooks attempt to load
> RefTeX (catastrophically). For this narrow issue, the workaround
> provided by Ikumi suffices.
Yes, that was clear, thanks.
Stefan
> @@ -456,7 +458,7 @@ reftex-isearch-isearch-search
> ;; beginning/end of the file list, depending of the search direction.
> (defun reftex-isearch-switch-to-next-file (crt-buf &optional wrapp)
> (reftex-access-scan-info)
> - (let ((cb (buffer-file-name crt-buf))
> + (let ((cb (reftex-get-buffer-identifier crt-buf))
> (flist (reftex-all-document-files)))
> (when flist
> (if wrapp
I think we had better use the buffer object here instead of using
"buffer:<NAME>". More generally, I think we should never convert
"buffer:<NAME>" back to a buffer. I guess that means such a conversion
would only ever be used when displaying info for a human to read, in
which case we could just as well use `prin1`s format `#<buffer ...>`.
> --- a/lisp/textmodes/reftex-ref.el
> +++ b/lisp/textmodes/reftex-ref.el
> @@ -73,8 +73,13 @@ reftex-label-info-update
> (file (nth 3 cell))
> (comment (nth 4 cell))
> (note (nth 5 cell))
> - (buf (reftex-get-file-buffer-force
> - file (not (eq t reftex-keep-temporary-buffers)))))
> + (buf (cond
> + ((and (stringp file)
> + (string-match "\\`buffer:\\(.*\\)" file))
> + (get-buffer (match-string 1 file)))
> + (file (reftex-get-file-buffer-force
> + file (not (eq t reftex-keep-temporary-buffers))))
> + (t nil))))
So here presumably we'd use
(cond
((bufferp file) file)
[...]
and I wouldn't test `file` before calling `reftex-get-file-buffer-force`
since we didn't test it before either.
> +;;; =========================================================================
> +;;;
> +;;; Helper functions for handling both file paths and buffer objects
> +;;;
> +
> +(defun reftex-get-buffer-identifier (&optional buffer)
> + "Return a buffer file name or a buffer identifier.
> +For file buffers, returns `buffer-file-name'.
> +For non-file buffers, returns a string with format
> +\"buffer:BUFFER-NAME\". When BUFFER is nil, use the current buffer."
> + (with-current-buffer (or buffer (current-buffer))
> + (or buffer-file-name (concat "buffer:" (buffer-name)))))
So I think what I said above means this would become:
(or (buffer-file-name buffer) buffer (current-buffer))
> +(defun reftex-get-buffer-for-master (master)
> + "Get the buffer associated with MASTER.
> +MASTER can be a file path or a buffer object."
> + (cond
> + ((bufferp master) master)
> + ((stringp master) (find-file-noselect master))
> + (t nil)))
I wouldn't test `(stringp master)`, so we get a "clean" error if
`master` is neither a buffer nor a string.
> +(defun reftex-get-directory-for-master (master)
> + "Get the directory associated with MASTER.
> +MASTER can be a file path or a buffer object."
> + (cond
> + ((bufferp master) (with-current-buffer master default-directory))
> + ((stringp master) (file-name-directory master))
> + (t default-directory)))
Same here and in most other functions.
> +(defun reftex-file-or-buffer-name (master)
> + "Get a display name for MASTER.
> +Returns the filename for file masters, or the buffer name for buffer
> +masters."
> + (cond
> + ((bufferp master) (buffer-name master))
> + ((stringp master) (file-name-nondirectory master))
> + (t "")))
This doesn't seem to be used.
> +(defun reftex-abbreviate-or-get-name (master)
> + "Get a nice display name for MASTER.
> +For files, returns the abbreviated file name.
> +For buffers, returns the buffer name."
> + (cond
> + ((bufferp master) (buffer-name master))
> + ((stringp master) (abbreviate-file-name master))
> + (t "")))
I think I'd use (prin1-to-string master) in the buffer case, just to
avoid confusing the user in case a buffer name looks like a file name.
And I'd drop the `(stringp master)` test.
> +(defun reftex-get-basename-for-master (master)
> + "Get the base name (without extension) for MASTER.
> +For file masters, returns the file name without directory and extension.
> +For buffer objects, returns a sanitized version of the buffer name
> +suitable for use in LaTeX labels."
> + (cond
> + ((bufferp master)
> + (let ((name (buffer-name master)))
> + ;; Remove extension if present
> + (if (string-match "\\(.*\\)\\.[^.]*\\'" name)
> + (match-string 1 name)
> + name)))
Why not (file-name-base (buffer-name master))?
> ;;; =========================================================================
> ;;;
> ;;; Multibuffer Variables
> @@ -282,8 +354,11 @@ reftex-next-multifile-index
> (defun reftex-tie-multifile-symbols ()
> "Tie the buffer-local symbols to globals connected with the master file.
> If the symbols for the current master file do not exist, they are created."
> - (let* ((master (file-truename (reftex-TeX-master-file)))
> - (index (assoc master reftex-master-index-list))
> + (let* ((master (reftex-TeX-master-file))
> + (master-key (if (bufferp master)
> + master
> + (file-truename master)))
I think you can use `reftex-get-truename-for-master` here, no?
I'd also keep the name of the second var as `master` (which just hides
the previous var of the same name), so we don't need to change the rest
of the code.
> @@ -293,7 +368,7 @@ reftex-tie-multifile-symbols
> ;; Get a new index and add info to the alist.
> (setq index (reftex-next-multifile-index)
> newflag t)
> - (push (cons master index) reftex-master-index-list))
> + (push (cons master-key index) reftex-master-index-list))
BTW, while this works, it's a bit more at risk of creating a memory leak
where `reftex-master-index-list` keeps references to long-dead buffers.
Maybe a `kill-buffer-hook` could be used to remove entries from this list?
> @@ -377,7 +452,7 @@ reftex-TeX-master-file
> (buffer-file-name)))))
> (cond
> ((null master)
> - (error "Need a filename for this buffer, please save it first"))
> + (current-buffer))
> ((or (file-exists-p (concat master ".tex"))
> (find-buffer-visiting (concat master ".tex")))
> ;; Ahh, an extra .tex was missing...
IIRC the `master` of one buffer may end up stored in a `TeX-master`
variable of a related buffer (see `reftex-find-duplicate-labels`), so we
need to adjust the code that consults `TeX-master` to account for the
fact that it can be a buffer. Also, it seems that `tex-main-file`
signals an error if `buffer-file-name` is nil, so we presumably need to
wrap the call to that function in the same kind of `condition-case` as
we do when calling `TeX-master`.
> (cond
> + ;; For non-file buffers, skip file operations but allow initialization
> + ((and is-buffer (memq action '(readable read kill)))
> + ;; Return appropriate values for buffer objects
> + (cond ((eq action 'readable) nil)
> + ((eq action 'read) nil)
> + ((eq action 'kill) t)))
> +
> ((eq action 'readable)
> - (file-readable-p file))
> + (and file (file-readable-p file)))
Here we know `file` is not a buffer, so I'd skip the `file` test.
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#76615
; Package
auctex
.
(Thu, 03 Apr 2025 05:42:02 GMT)
Full text and
rfc822 format available.
Message #68 received at 76615 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Many thanks for your comments. I attach the updated patch, which
contains a few other corrections and hopefully not too many regressions.
> AFAICT it should be safe in the sense that it should not affect behavior
> in file buffers. See comments below.
That's indeed the plan.
> Should we push it to `master`?
I'm curious what Arash/Ikumi think -- if they don't like the idea, then
I'm happy to put this in the wastebin and regard it as an exercise.
Also, if we're going to proceed with this, then I'd like to take the
opportunity to add support for indirect buffers to RefTeX, which
requires modifications to the same parts of the code as this patch.
Thanks, best,
Paul
[0001-Add-RefTeX-support-for-non-file-buffers.patch (text/x-patch, attachment)]
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#76615
; Package
auctex
.
(Thu, 03 Apr 2025 10:44:02 GMT)
Full text and
rfc822 format available.
Message #71 received at 76615 <at> debbugs.gnu.org (full text, mbox):
Hi Paul and Stefan,
>>>>> "Paul D. Nelson" <ultrono <at> gmail.com> writes:
>> Should we push it to `master`?
> I'm curious what Arash/Ikumi think -- if they don't like the idea, then
> I'm happy to put this in the wastebin and regard it as an exercise.
I don't have enough spare time for now to have closer look at Paul's
proposal, so I don't mind.
Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine
#Gaza #StopMassiveKilling #CeasefireNOW
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#76615
; Package
auctex
.
(Thu, 03 Apr 2025 13:51:01 GMT)
Full text and
rfc822 format available.
Message #74 received at 76615 <at> debbugs.gnu.org (full text, mbox):
> Also, if we're going to proceed with this, then I'd like to take the
> opportunity to add support for indirect buffers to RefTeX, which
> requires modifications to the same parts of the code as this patch.
I see you use `buffer-base-buffer` in the new patch. Is that all it
takes or does is there more in the waiting?
The patch looks fine to me. Can you push it or do you need me to do it?
While waiting for Arash's answer, I found a few more nitpicks.
Stefan
> + (let* ((master (reftex-TeX-master-file)))
> + (when (bufferp master)
> + (user-error "RefTeX phrases buffer requires a file buffer. Cannot create phrases for non-file buffers"))
This error message is too long. I'd drop one of the two sentences.
> + (true-master (reftex-get-truename-for-master master))
> + (master-dir (file-name-as-directory (reftex-get-directory-for-master master)))
> + (file (or file (reftex-get-buffer-identifier)))
> + (true-file (if file (file-truename file) (buffer-name)))
This overflows the 80 columns limit, as do many other places in your patch.
> +;;; =========================================================================
> +;;;
> +;;; Helper functions for handling both file paths and buffer objects
> +;;;
In GNU land, we call these file *names* not paths.
[ And please punctuate your comments. ]
Regarding the functions defined in this section, please use a "reftex--"
prefix to mark those functions as internal to RefTeX.
> +(defun reftex-get-buffer-identifier (&optional buffer)
> + "Return the base buffer's file name or buffer identifier.
> +For file buffers, returns the file name of the base buffer.
> +For non-file buffers, return the base buffer object itself.
> +When BUFFER is nil, use the current buffer."
> + (with-current-buffer (or (buffer-base-buffer buffer) buffer (current-buffer))
> + (or (buffer-file-name) (current-buffer))))
`with-current-buffer` is not super-expensive but it's not really cheap
either and it's significantly more expensive than `buffer-local-value`
or `buffer-file-name`, so better use one of those when you can, like here.
> +(defun reftex-abbreviate-or-get-name (master)
> + "Get a nice display name for MASTER.
> +For files, returns the abbreviated file name.
> +For buffers, returns the buffer name."
> + (if (bufferp master)
> + (prin1-to-string master)
> + (abbreviate-file-name master)))
Personally, I'd drop the "or-get" from the name.
> - (push (cons master index) reftex-master-index-list))
> + (push (cons master index) reftex-master-index-list)
> + (when (bufferp master)
> + (add-hook
> + 'kill-buffer-hook
> + (lambda ()
> + (setq reftex-master-index-list
> + (assq-delete-all master reftex-master-index-list))))))
Please avoid adding lambda expressions to hooks, better give a name to
the function and pass the function's name here: comparing function
names is easy, comparing functions is hard.
Also, I think you forgot to pass the `local` arg to `add-hook`.
> - (file (if (string-match "\\.[a-zA-Z]+\\'" master)
> - (concat (substring master 0 (match-beginning 0))
> - reftex-parse-file-extension)
> - (concat master reftex-parse-file-extension))))
> + (is-buffer (bufferp master))
> + (file (if is-buffer
> + nil
> + (if (string-match "\\.[a-zA-Z]+\\'" master)
> + (concat (substring master 0 (match-beginning 0))
> + reftex-parse-file-extension)
> + (concat master reftex-parse-file-extension)))))
Maybe call it `non-file` rather than `is-buffer`, since it seems to
better match the way we think about it (at least, based on the text used
in docstrings and comments 🙂).
> + (cond
> + (is-buffer
> + (error "Cannot restore for non-file buffer"))
Can't this be moved to the first branch of the surrounding `cond`,
along with readable, read, and kill?
> ((eq action 'read)
> (put reftex-docstruct-symbol 'modified nil)
> - (if (file-exists-p file)
[...]
> - nil))
> + (cond
> + (is-buffer nil)
I think we can't reach this branch because we handled that case earlier.
> ((eq action 'kill)
> ;; Remove the file
> - (when (and (file-exists-p file) (file-writable-p file))
> + (when (and file (file-exists-p file) (file-writable-p file))
> (message "Unlinking file %s" file)
> (delete-file file)))
Why?
> - (t
> +
> + (t ; write
> (put docstruct-symbol 'modified nil)
[...]
> + (if is-buffer
> + t
Is the `put` important in this case? If not, then this can also be
moved to the the first branch of the surrounding `cond`, so that this
first branch handles all the `is-buffer` (aka `non-file`) cases, and the
rest doesn't need to be touched at all.
> @@ -1240,10 +1319,13 @@ reftex-check-parse-consistency
> (let* ((real-master (reftex-TeX-master-file))
> (parsed-master
> (nth 1 (assq 'bof (symbol-value reftex-docstruct-symbol)))))
> - (unless (string= (file-truename real-master) (file-truename parsed-master))
> - (message "Master file name in load file is different: %s versus %s"
> - parsed-master real-master)
> - (error "Master file name error")))
> + ;; Skip this check for buffer objects since they don't need saved parse info
> + (when (and (stringp real-master) (stringp parsed-master))
> + (unless (string= (file-truename real-master)
> + (file-truename parsed-master))
> + (message "Master file name in load file is different: %s versus %s"
> + parsed-master real-master)
> + (error "Master file name error"))))
Beside the lack of punctuation in the comment, it leaves me wondering
about why we don't do
(unless (equal (reftex-get-truename-for-file real-master)
(reftex-get-truename-for-file parsed-master))
(message "Master file name in load file is different: %s versus %s"
parsed-master real-master)
(error "Master file name error")))
instead.
> + (cond
> + ((bufferp file) file)
> +
> + ;; Normal file path handling
> + ((stringp file)
> + (let ((buf (find-buffer-visiting file)))
> + (cond (buf
> + ;; We have it already as a buffer - just return it
> + buf)
> +
> + ((file-readable-p file)
> + ;; At least there is such a file and we can read it.
> +
> + (if (or (not mark-to-kill)
> + (eq t reftex-initialize-temporary-buffers))
> +
> + ;; Visit the file with full magic
> + (setq buf (find-file-noselect file))
> +
> + ;; Else: Visit the file just briefly, without or
> + ;; with limited Magic
> +
> + ;; The magic goes away
> + (cl-letf ((format-alist nil)
> + (auto-mode-alist (reftex-auto-mode-alist))
> + ((default-value 'major-mode) 'fundamental-mode)
> + (enable-local-variables nil)
> + (after-insert-file-functions nil))
> + (setq buf (find-file-noselect file)))
> +
> + ;; Is there a hook to run?
> + (when (listp reftex-initialize-temporary-buffers)
> + (with-current-buffer buf
> + (run-hooks 'reftex-initialize-temporary-buffers))))
> +
> + ;; Let's see if we got a license to kill :-|
> + (and mark-to-kill
> + (cl-pushnew buf reftex-buffers-to-kill))
> +
> + ;; Return the new buffer
> + buf)
> +
> + ;; If no such file exists, return nil
> + (t nil))))
> + ;;
> + (t nil)))
Why test (stringp file) here?
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#76615
; Package
auctex
.
(Thu, 03 Apr 2025 13:56:01 GMT)
Full text and
rfc822 format available.
Message #77 received at 76615 <at> debbugs.gnu.org (full text, mbox):
> I see you use `buffer-base-buffer` in the new patch. Is that all it
> takes or does is there more in the waiting?
Thanks very much for your comments, which I'll address a bit later.
This is indeed the thrust of it, but there are a couple minor points
that I'm planning to check on later, and I'd also like to test it out a
bit.
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#76615
; Package
auctex
.
(Thu, 03 Apr 2025 18:28:01 GMT)
Full text and
rfc822 format available.
Message #80 received at 76615 <at> debbugs.gnu.org (full text, mbox):
"Paul D. Nelson" <ultrono <at> gmail.com> writes:
> I'm curious what Arash/Ikumi think --
Usually, I don't think when Stefan talks, I just listen and obey ;-)
> if they don't like the idea, then I'm happy to put this in the
> wastebin and regard it as an exercise.
I like the idea, I just wonder if this is by design, so maybe we can ask
Carsten (in Cc).
@Carsten: Can you remember why RefTeX doesn't work in non-file buffers?
Is this by design?
> Also, if we're going to proceed with this, then I'd like to take the
> opportunity to add support for indirect buffers to RefTeX, which
> requires modifications to the same parts of the code as this patch.
SGTM. If we're changing this, so let's go for indirect buffers as well.
I think AUCTeX supports indirect buffers now[1], so it makes sense to
teach RefTeX this as well. And since Emacs31 is early dev cycle, there
will be enough time to fix things if we break some.
Best, Arash
Footnotes:
[1] https://git.savannah.gnu.org/cgit/auctex.git/commit/?id=0e315c7fbeed081addf369fd42e7206d83580bc5
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#76615
; Package
auctex
.
(Thu, 03 Apr 2025 18:36:03 GMT)
Full text and
rfc822 format available.
Message #83 received at 76615 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Hi Arash,
OK, sounds good. I just finished polishing the patch (also for indirect
buffers) and testing it out a bit, so as far as I'm concerned, it's OK
to push to master, unless Stefan or others have further comments.
Well, I guess this could benefit from a NEWS entry, but I'll leave that
for now.
Thanks, best,
Paul
[0001-Add-RefTeX-support-for-non-file-buffers.patch (text/x-patch, attachment)]
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#76615
; Package
auctex
.
(Thu, 03 Apr 2025 18:38:03 GMT)
Full text and
rfc822 format available.
Message #86 received at 76615 <at> debbugs.gnu.org (full text, mbox):
"Paul D. Nelson" <ultrono <at> gmail.com> writes:
> Thanks very much for your comments, which I'll address a bit later.
> This is indeed the thrust of it, but there are a couple minor points
> that I'm planning to check on later, and I'd also like to test it out a
> bit.
I don't have anything to add to what Stefan said right now, but I think
you can test your patch also by cloning some ERT-tests[1] to run in a
temp-buffer instead of the
(ert-with-temp-directory temp-dir
...
machinery. Have a look at `reftex-all-used-citation-keys' and
`reftex-renumber-simple-labels' tests in that file. Once adjusted, you
run
make reftex-tests
in the test directory.
Thanks for working on this.
Best, Arash
Footnotes:
[1] https://git.savannah.gnu.org/cgit/emacs.git/tree/test/lisp/textmodes/reftex-tests.el
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#76615
; Package
auctex
.
(Thu, 03 Apr 2025 18:48:02 GMT)
Full text and
rfc822 format available.
Message #89 received at 76615 <at> debbugs.gnu.org (full text, mbox):
Hi Paul,
"Paul D. Nelson" <ultrono <at> gmail.com> writes:
> OK, sounds good. I just finished polishing the patch (also for indirect
> buffers) and testing it out a bit, so as far as I'm concerned, it's OK
> to push to master, unless Stefan or others have further comments.
Thanks, I'm currently swamped with real life issues, but I'll try to
have a look at it.
But before we install this, we have to revert 90571269 in Emacs repo,
right?
> Well, I guess this could benefit from a NEWS entry, but I'll leave that
> for now.
That's Ok for now, I guess. I think it would be more important to have
some ERT tests for the new functionality. WDYT?
Best, Arash
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#76615
; Package
auctex
.
(Fri, 04 Apr 2025 15:24:01 GMT)
Full text and
rfc822 format available.
Message #92 received at 76615 <at> debbugs.gnu.org (full text, mbox):
> But before we install this, we have to revert 90571269 in Emacs repo,
> right?
Yes.
> That's Ok for now, I guess. I think it would be more important to have
> some ERT tests for the new functionality. WDYT?
Yes, thanks, I'll see what I can do following your other message.
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#76615
; Package
auctex
.
(Fri, 04 Apr 2025 16:15:01 GMT)
Full text and
rfc822 format available.
Message #95 received at 76615 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Please find attached the updated patch with tests.
[0001-Add-RefTeX-support-for-non-file-buffers.patch (text/x-patch, attachment)]
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#76615
; Package
auctex
.
(Fri, 04 Apr 2025 19:10:01 GMT)
Full text and
rfc822 format available.
Message #98 received at 76615 <at> debbugs.gnu.org (full text, mbox):
> Please find attached the updated patch with tests.
Thanks, pushed to `master`.
Stefan
bug closed, send any further explanations to
76615 <at> debbugs.gnu.org and "Paul D. Nelson" <ultrono <at> gmail.com>
Request was from
Stefan Monnier <monnier <at> iro.umontreal.ca>
to
control <at> debbugs.gnu.org
.
(Fri, 04 Apr 2025 19:10: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
.
(Sat, 03 May 2025 11:24:08 GMT)
Full text and
rfc822 format available.
This bug report was last modified 46 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.