Subject: Re: bug#76615: 14.0.9; error with amsmath style hooks

From: Ikumi Keita <[email-masked]>
Date: Fri, 28 Mar 2025 22:28:17 +0900

Hi Arash,

>>>>> Arash Esbati <[email-masked]> 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

>From 38f3f2d59611e30309046e4c115797ca1110feae Mon Sep 17 00:00:00 2001
From: Ikumi Keita <[email-masked]>
Date: Fri, 28 Mar 2025 22:18:42 +0900
Subject: [PATCH] Suppress error in non-file buffer

* lisp/textmodes/reftex.el (reftex--suppress-nonfile-error): New
variable.
(reftex-TeX-master-file): Don't signal error in non-file buffer.
---
 lisp/textmodes/reftex.el | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/lisp/textmodes/reftex.el b/lisp/textmodes/reftex.el
index fda506a6d87..2dde5232077 100644
--- a/lisp/textmodes/reftex.el
+++ b/lisp/textmodes/reftex.el
@@ -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)
@@ -377,7 +383,8 @@ If the symbols for the current master file do not exist, they are created."
           (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...
@@ -389,7 +396,10 @@ If the symbols for the current master file do not exist, they are created."
      (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.
-- 
2.48.1