GNU bug report logs - #76615
14.0.9; error with amsmath style hooks

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: auctex; Reported by: "Paul D. Nelson" <ultrono@HIDDEN>; Done: Stefan Monnier <monnier@HIDDEN>; Maintainer for auctex is bug-auctex@HIDDEN.
bug closed, send any further explanations to 76615 <at> debbugs.gnu.org and "Paul D. Nelson" <ultrono@HIDDEN> Request was from Stefan Monnier <monnier@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at 76615 <at> debbugs.gnu.org:


Received: (at 76615) by debbugs.gnu.org; 4 Apr 2025 19:09:17 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Apr 04 15:09:17 2025
Received: from localhost ([127.0.0.1]:39930 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1u0mPl-0003iS-Cj
	for submit <at> debbugs.gnu.org; Fri, 04 Apr 2025 15:09:17 -0400
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:28171)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <monnier@HIDDEN>)
 id 1u0mPj-0003iA-1h
 for 76615 <at> debbugs.gnu.org; Fri, 04 Apr 2025 15:09:15 -0400
Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id DE081441DEE;
 Fri,  4 Apr 2025 15:09:08 -0400 (EDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1743793748;
 bh=eCcWVgaLwriLvFE9ToifD8PK4c1V/+1/77IKAX2BVOU=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=EMmYWDYTztvov3VZMftmcBjQ75sw8iu40KaNdxpbnhR+IrNnpxYFbcqyU5caQnLzr
 vjKzMlOFpJ5kMOW/2mntzPHovNL7G4K+D0Yu4r/5RvWg6dFoaGGPhPZjwMnieLgI9o
 TwFUBWfC2/5PU+GPIUiMQZretuUMmOuuARDsjytgnevJemsK2seYxZ/ZfwVe6mWQmB
 MroSIsQAIsO994+f9WtLlRHfZ5esdiqnMmme3WE4HsyKlEM9NaUMpKiPWFLkCoVgf9
 awQi+9GZxEvEK+Xczst0meFUbyNP34Yz7Or8o7aqOjHMe8pg5xQ1BEuhgIWrgAhSqF
 tZAoKBJvBfufA==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 02D60441DA9;
 Fri,  4 Apr 2025 15:09:08 -0400 (EDT)
Received: from alfajor (unknown [23.233.149.155])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id AB6C6120491;
 Fri,  4 Apr 2025 15:09:07 -0400 (EDT)
From: Stefan Monnier <monnier@HIDDEN>
To: "Paul D. Nelson" <ultrono@HIDDEN>
Subject: Re: bug#76615: 14.0.9; error with amsmath style hooks
In-Reply-To: <uxsg7tsemnoqez.fsf@HIDDEN>
Message-ID: <jwvfrinrbg7.fsf-monnier+emacs@HIDDEN>
References: <uxsg7tsemnoqez.fsf@HIDDEN>
Date: Fri, 04 Apr 2025 15:09:06 -0400
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL -0.213 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain
X-SPAM-LEVEL: 
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76615
Cc: ikumi@HIDDEN, arash@HIDDEN, 76615 <at> debbugs.gnu.org,
 carsten.dominik@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> Please find attached the updated patch with tests.

Thanks, pushed to `master`.


        Stefan





Information forwarded to bug-auctex@HIDDEN:
bug#76615; Package auctex. Full text available.

Message received at 76615 <at> debbugs.gnu.org:


Received: (at 76615) by debbugs.gnu.org; 4 Apr 2025 16:14:12 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Apr 04 12:14:12 2025
Received: from localhost ([127.0.0.1]:39677 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1u0jgI-0008ME-42
	for submit <at> debbugs.gnu.org; Fri, 04 Apr 2025 12:14:12 -0400
Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]:58577)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <ultrono@HIDDEN>) id 1u0jgD-0008LR-5x
 for 76615 <at> debbugs.gnu.org; Fri, 04 Apr 2025 12:14:08 -0400
Received: by mail-ej1-x62e.google.com with SMTP id
 a640c23a62f3a-ac2ab99e16eso423205966b.0
 for <76615 <at> debbugs.gnu.org>; Fri, 04 Apr 2025 09:14:05 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1743783239; x=1744388039; darn=debbugs.gnu.org;
 h=mime-version:message-id:date:in-reply-to:subject:cc:to:from:from:to
 :cc:subject:date:message-id:reply-to;
 bh=C5n/IzJW9Vr6BHIghPhesogqR5uVs+RCIIf0K8hIbXw=;
 b=RTMVZ6Q/kMOS24lTIhu3ohhJMp6hl2HWiBayXbk5Kg0FDyciEg3pj23OhifkHv8N2V
 kQ4HT96/JBvKIy1JQ1tA8knRZ2HeBCI7wJuuQ4xSLDEyzJKYsJOFOlJPuuMSipb+FIbl
 wkWUJg9G3Q06YgJjcORVrYTRIQQ1k7jAsjCTe8EfCQaSCcq/o4vXWtVwZ5vqxvc2rcBM
 rHvbepLDFphDAHpqC7MdiBLpg5S3HM35mCUV+OXX5eidmeNle7TFrpzFSDilwsxoclUu
 fSgsHiwKfx8asktjbQc/sjbUNwO0ynRjrR8BaOuGUGv5OWetFIWH4dM1BI6HXOSfh6Rn
 5Y2w==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1743783239; x=1744388039;
 h=mime-version:message-id:date:in-reply-to:subject:cc:to:from
 :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
 bh=C5n/IzJW9Vr6BHIghPhesogqR5uVs+RCIIf0K8hIbXw=;
 b=Q4wU9DfaOy5JUnghB/DaXjX1x4deKP4EH/RW+QLh+eKPPAC1XeuoHYBU0TVK0rZ0ao
 fPVkYwDaW5CoEPs26Gt3sQbXonZTbJeBDxhccpeGKTV0sh63t82xtT5kgwq6rK1TU0u5
 YQfHINgH8qTTLTHfx09QMVfiYXdsqB3KQ87WMrxFL7lqO1sHy1vRTNWB3xjEuiZYmsDf
 XlKGosjEEdaQB7G3CYRD8mEYU5T+WgPHGZZxikx2o3jC2dMb3rWC2n1lhR9I33PZNtrK
 Kbdj2D9xpR9UzX9MdJRcERcFgKKTbLLhw1ctCsPeE3DKYkVOwzwGUiusXgRZirBbJ4pR
 frfQ==
X-Forwarded-Encrypted: i=1;
 AJvYcCVU0fFidfo4YKxqgbaySp42Q8xcIf4BGacFDLH017F6W5JCIWNLh7LrY76i2GpFO2TPm4wRoA==@debbugs.gnu.org
X-Gm-Message-State: AOJu0YxllSCRnaSFFelFfIgFTtuklPlICQHEP991rqeGB4SU7Q0c5CyW
 d4leYS25vvbBrr4kVxoxQQX1yxmlah2Nw9A/M//a5Kstec1Gp8RO
X-Gm-Gg: ASbGncsPNFnCyVppBvTAKbDF9A8Ej1JBROArRwVtkUcT33Xto4KHA/znJC8SsbTqh3T
 PafZCMUdl3+nBR4BSsJhbccjloaoeJuDGMDQx5REHEi3q996Tg+GS/TCvDN9HJBsKD3lohMlhF3
 s3/AS/UUJVu6droOOvctSH6DB1rSAbxhqgwlv5+BxEFFq/jHcGrvpcUGwKijBvplHhDlO/5yaJf
 s+H5GJ0FjDtz1HAPmhYLVQfXPC/rQ+6tTS758gIqJ9kIAyhmBno/seVyI+CLjzfY8Q9FNsXW9fb
 kGEImFPWoFcx+r4jJUMVCpyfvHiwR0qv8vbxTawKB7bdWDRfbxda6IgvdsakrgFR5bVcgqTC15+
 Xr6rBdzcvG93Alh+U5KUA
X-Google-Smtp-Source: AGHT+IGtUPoZwQE0qWVBbPLzVMSsKJdjt45dNUaDjpwZ9KkecZjGkfjzHL4VC+Hb6m8wmLLCSOx2hA==
X-Received: by 2002:a17:907:d25:b0:ac3:b12c:b1f2 with SMTP id
 a640c23a62f3a-ac7d6d81279mr257965966b.35.1743783238458; 
 Fri, 04 Apr 2025 09:13:58 -0700 (PDT)
Received: from localhost (0x573d6713.static.cust.fastspeed.dk. [87.61.103.19])
 by smtp.gmail.com with UTF8SMTPSA id
 a640c23a62f3a-ac7c01857fbsm282459666b.149.2025.04.04.09.13.57
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 04 Apr 2025 09:13:57 -0700 (PDT)
From: "Paul D. Nelson" <ultrono@HIDDEN>
To: "Paul D. Nelson" <ultrono@HIDDEN>
Subject: Re: bug#76615: 14.0.9; error with amsmath style hooks
In-Reply-To: <uxsg7tv7rkne78.fsf@HIDDEN> (ultrono@HIDDEN)
Date: Fri, 04 Apr 2025 18:13:56 +0200
Message-ID: <uxsg7tsemnoqez.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 76615
Cc: ikumi@HIDDEN, arash@HIDDEN, monnier@HIDDEN,
 76615 <at> debbugs.gnu.org, carsten.dominik@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

--=-=-=
Content-Type: text/plain

Please find attached the updated patch with tests.


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=0001-Add-RefTeX-support-for-non-file-buffers.patch

From 9d2f97364bc8eef4924610fbad6981b6baeab32b Mon Sep 17 00:00:00 2001
From: Paul Nelson <ultrono@HIDDEN>
Date: Wed, 2 Apr 2025 21:38:48 +0200
Subject: [PATCH] Add RefTeX support for non-file buffers

* lisp/textmodes/reftex.el (reftex--get-buffer-identifier)
(reftex--get-directory, reftex--abbreviate-name)
(reftex--get-basename, reftex--get-truename): New helper
functions that handle both files and buffer objects.
(reftex--remove-buffer-from-master-index): New helper function.
(reftex-tie-multifile-symbols): Support non-file buffers, using
the above.
(reftex-TeX-master-file): Return current buffer when no file.
(reftex-access-scan-info): Remove check requiring file buffers.
(reftex-access-parse-file, reftex-check-parse-consistency): Skip
for non-file buffers.
(reftex-select-external-document): Use new helper function.
(reftex-locate-file): Return buffer objects directly.
(reftex-get-file-buffer-force): Handle buffer objects and
special 'buffer:' strings.
* lisp/textmodes/reftex-global.el (reftex-create-tags-file): Add
error handling for non-file buffers.  Leave TAGS unsupported in
non-file buffers.
(reftex-find-duplicate-labels)
(reftex-isearch-switch-to-next-file): Use new helper functions
that handle both files and buffer objects.
(reftex-isearch-switch-to-next-file): Use equal rather than
string= to compare strings/buffers.
* lisp/textmodes/reftex-index.el (reftex-display-index)
(reftex-index-change-entry): Use new helper functions.
(reftex-index-visit-phrases-buffer): Add error handling for
non-file buffers.  Leave phrases unsupported in non-file
buffers.
* lisp/textmodes/reftex-parse.el (reftex-do-parse)
(reftex-parse-from-file): Add support for non-file buffers.
(reftex-all-document-files, reftex-where-am-I)
(reftex-notice-new): Use new helper functions.
* lisp/textmodes/reftex-ref.el (reftex-label-info-update):
Support non-file buffers.
(reftex-label-info, reftex-replace-prefix-escapes, reftex-label)
(reftex-replace-prefix-escapes, reftex-offer-label-menu): Use
new helper functions.
* lisp/textmodes/reftex-sel.el (reftex-insert-docstruct): Use
new helper function.
* lisp/textmodes/reftex-toc.el (reftex-toc)
(reftex-recenter-toc-when-idle): Support non-file buffers.
* lisp/textmodes/reftex-cite.el (reftex-bib-or-thebib)
(reftex-get-bibfile-list): Use new helper functions.
* lisp/textmodes/reftex-global.el
(reftex-save-all-document-buffers, reftex-ensure-write-access):
Ignore non-file buffers.
* lisp/textmodes/reftex-parse.el (reftex-all-document-files):
For non-file objects, do not apply relative path transformation.
* test/lisp/textmodes/reftex-tests.el
(reftex-all-used-citation-keys-buffer)
(reftex-renumber-simple-labels-buffer): New tests for operations
on non-file buffers.

RefTeX historically assumed that the buffers it operates on
visit files.  To handle non-file buffers:

Modify reftex-TeX-master-file so that it returns the buffer
object itself (as suggested by Stefan Monnier).  Modify each
caller to handle buffer objects, aided by some helper functions
added to reftex.el.  Replace 'string=' by 'equal' in places.

Use buffer-base-buffer, where appropriate, to handle indirect
buffers (file and non-file).

TAGS files and phrases buffers remain unsupported for non-file
buffers.
---
 lisp/textmodes/reftex-cite.el       |   9 +-
 lisp/textmodes/reftex-global.el     |  70 +++---
 lisp/textmodes/reftex-index.el      |  25 ++-
 lisp/textmodes/reftex-parse.el      |  49 +++--
 lisp/textmodes/reftex-ref.el        |  25 ++-
 lisp/textmodes/reftex-sel.el        |   2 +-
 lisp/textmodes/reftex-toc.el        |  11 +-
 lisp/textmodes/reftex.el            | 237 +++++++++++++-------
 test/lisp/textmodes/reftex-tests.el | 323 ++++++++++++++++++++++++++++
 9 files changed, 586 insertions(+), 165 deletions(-)

diff --git a/lisp/textmodes/reftex-cite.el b/lisp/textmodes/reftex-cite.el
index fe6751a13f6..8830f188c93 100644
--- a/lisp/textmodes/reftex-cite.el
+++ b/lisp/textmodes/reftex-cite.el
@@ -76,7 +76,8 @@ reftex-bib-or-thebib
   "Test if BibTeX or \\begin{thebibliography} should be used for the citation.
 Find the bof of the current file."
   (let* ((docstruct (symbol-value reftex-docstruct-symbol))
-         (rest (or (member (list 'bof (buffer-file-name)) docstruct)
+         (rest (or (member (list 'bof (reftex--get-buffer-identifier))
+                           docstruct)
                    docstruct))
          (bib (assq 'bib rest))
          (thebib (assq 'thebib rest))
@@ -104,11 +105,11 @@ reftex-get-bibfile-list
   (or
    ;; Try inside this file (and its includes)
    (cdr (reftex-last-assoc-before-elt
-         'bib (list 'eof (buffer-file-name))
-         (member (list 'bof (buffer-file-name))
+         'bib (list 'eof (reftex--get-buffer-identifier))
+         (member (list 'bof (reftex--get-buffer-identifier))
                  (symbol-value reftex-docstruct-symbol))))
    ;; Try after the beginning of this file
-   (cdr (assq 'bib (member (list 'bof (buffer-file-name))
+   (cdr (assq 'bib (member (list 'bof (reftex--get-buffer-identifier))
                            (symbol-value reftex-docstruct-symbol))))
    ;; Anywhere in the entire document
    (cdr (assq 'bib (symbol-value reftex-docstruct-symbol)))
diff --git a/lisp/textmodes/reftex-global.el b/lisp/textmodes/reftex-global.el
index 20abd36192d..bd330d3a418 100644
--- a/lisp/textmodes/reftex-global.el
+++ b/lisp/textmodes/reftex-global.el
@@ -37,16 +37,18 @@ reftex-create-tags-file
 The TAGS file is also immediately visited with `visit-tags-table'."
   (interactive)
   (reftex-access-scan-info current-prefix-arg)
-  (let* ((master (reftex-TeX-master-file))
-         (files  (reftex-all-document-files))
-         (cmd    (format "%s %s"
-                         etags-program-name
-                         (mapconcat #'shell-quote-argument
-				    files " "))))
-    (with-current-buffer (reftex-get-file-buffer-force master)
-      (message "Running etags to create TAGS file...")
-      (shell-command cmd)
-      (visit-tags-table "TAGS"))))
+  (let ((master (reftex-TeX-master-file)))
+    (if (bufferp master)
+        (user-error "Cannot create TAGS file for non-file buffers")
+      (let* ((files  (reftex-all-document-files))
+             (cmd (format "%s %s"
+                          etags-program-name
+                          (mapconcat #'shell-quote-argument
+                                     files " "))))
+        (with-current-buffer (reftex-get-file-buffer-force master)
+          (message "Running etags to create TAGS file...")
+          (shell-command cmd)
+          (visit-tags-table "TAGS"))))))
 
 ;; History of grep commands.
 (defvar reftex-grep-history nil)
@@ -144,7 +146,7 @@ reftex-find-duplicate-labels
                 (if (< 1 (length x1))
                     (append (list (car x))
                             (mapcar (lambda(x)
-                                      (abbreviate-file-name (nth 3 x)))
+                                      (reftex--abbreviate-name (nth 3 x)))
                                     x1))
                   (list nil))))))
           (reftex-uniquify-by-car (symbol-value reftex-docstruct-symbol)))))
@@ -369,31 +371,33 @@ reftex-save-all-document-buffers
         file buffer)
     (save-current-buffer
       (while (setq file (pop files))
-        (setq buffer (find-buffer-visiting file))
-        (when buffer
-          (set-buffer buffer)
-          (save-buffer))))))
+        (when (stringp file) ; Ignore non-file buffers.
+          (setq buffer (find-buffer-visiting file))
+          (when buffer
+            (set-buffer buffer)
+            (save-buffer)))))))
 
 (defun reftex-ensure-write-access (files)
   "Make sure we have write access to all files in FILES.
 Also checks if buffers visiting the files are in read-only mode."
   (let (file buf)
-    (while (setq file (pop files))
-      (unless (file-exists-p file)
-        (ding)
-        (or (y-or-n-p (format "No such file %s. Continue?" file))
-            (error "Abort")))
-      (unless (file-writable-p file)
-        (ding)
-        (or (y-or-n-p (format "No write access to %s. Continue?" file))
-            (error "Abort")))
-      (when (and (setq buf (find-buffer-visiting file))
-                 (with-current-buffer buf
-                   buffer-read-only))
-        (ding)
-        (or (y-or-n-p (format "Buffer %s is read-only.  Continue?"
-                              (buffer-name buf)))
-            (error "Abort"))))))
+    (while (setq file (pop files)) ; Ignore non-file buffers.
+      (when (stringp file)
+        (unless (file-exists-p file)
+          (ding)
+          (or (y-or-n-p (format "No such file %s. Continue?" file))
+              (error "Abort")))
+        (unless (file-writable-p file)
+          (ding)
+          (or (y-or-n-p (format "No write access to %s. Continue?" file))
+              (error "Abort")))
+        (when (and (setq buf (find-buffer-visiting file))
+                   (with-current-buffer buf
+                     buffer-read-only))
+          (ding)
+          (or (y-or-n-p (format "Buffer %s is read-only.  Continue?"
+                                (buffer-name buf)))
+              (error "Abort")))))))
 
 ;;; Multi-file RefTeX Isearch
 
@@ -456,7 +460,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
@@ -464,7 +468,7 @@ reftex-isearch-switch-to-next-file
 	    (setq flist (last flist)))
 	(unless isearch-forward
 	  (setq flist (reverse flist)))
-	(while (not (string= (car flist) cb))
+	(while (not (equal (car flist) cb))
 	  (setq flist (cdr flist)))
 	(setq flist (cdr flist)))
       (when flist
diff --git a/lisp/textmodes/reftex-index.el b/lisp/textmodes/reftex-index.el
index db6ebb4caf8..1d18d6047b5 100644
--- a/lisp/textmodes/reftex-index.el
+++ b/lisp/textmodes/reftex-index.el
@@ -475,7 +475,7 @@ reftex-display-index
          (docstruct-symbol reftex-docstruct-symbol)
          (index-tag (or tag (reftex-index-select-tag)))
          (master (reftex-TeX-master-file))
-         (calling-file (buffer-file-name))
+         (calling-file (reftex--get-buffer-identifier))
          (restriction
           (or overriding-restriction
               (and (not redo)
@@ -531,7 +531,7 @@ reftex-display-index
 SPC=view TAB=goto RET=goto+hide [e]dit [q]uit [r]escan [f]ollow [?]Help
 ------------------------------------------------------------------------------
 "
-               index-tag (abbreviate-file-name master)
+               index-tag (reftex--abbreviate-name master)
                (if (eq (car (car reftex-index-restriction-data)) 'toc)
                    (nth 2 (car reftex-index-restriction-data))
                  reftex-index-restriction-indicator)))
@@ -1107,7 +1107,8 @@ reftex-index-change-entry
       (when (and (re-search-forward (reftex-everything-regexp) nil t)
                  (match-end 10)
                  (< (abs (- (match-beginning 10) beg)) (length new))
-                 (setq info (reftex-index-info-safe buffer-file-name)))
+                 (setq info (reftex-index-info-safe
+                             (reftex--get-buffer-identifier))))
         (setcdr data (cdr info))))
     (let ((buffer-read-only nil))
       (save-excursion
@@ -1281,14 +1282,16 @@ reftex-index-visit-phrases-buffer
   (interactive)
   (reftex-access-scan-info)
   (set-marker reftex-index-return-marker (point))
-  (let* ((master (reftex-TeX-master-file))
-         (name (concat (file-name-sans-extension master)
-                       reftex-index-phrase-file-extension)))
-    (find-file name)
-    (unless (eq major-mode 'reftex-index-phrases-mode)
-      (reftex-index-phrases-mode))
-    (if (= (buffer-size) 0)
-        (reftex-index-initialize-phrases-buffer master))))
+  (let ((master (reftex-TeX-master-file)))
+    (when (bufferp master)
+      (user-error "RefTeX phrases buffer requires a file buffer"))
+    (let ((name (concat (file-name-sans-extension master)
+                        reftex-index-phrase-file-extension)))
+      (find-file name)
+      (unless (eq major-mode 'reftex-index-phrases-mode)
+        (reftex-index-phrases-mode))
+      (if (= (buffer-size) 0)
+          (reftex-index-initialize-phrases-buffer master)))))
 
 (defun reftex-index-initialize-phrases-buffer (&optional master)
   "Initialize the phrases buffer by creating the header.
diff --git a/lisp/textmodes/reftex-parse.el b/lisp/textmodes/reftex-parse.el
index 7795c583076..cd8b3378558 100644
--- a/lisp/textmodes/reftex-parse.el
+++ b/lisp/textmodes/reftex-parse.el
@@ -74,10 +74,10 @@ reftex-do-parse
 
   (let* ((old-list (symbol-value reftex-docstruct-symbol))
          (master (reftex-TeX-master-file))
-         (true-master (file-truename master))
-         (master-dir (file-name-as-directory (file-name-directory master)))
-         (file (or file (buffer-file-name)))
-         (true-file (file-truename file))
+         (true-master (reftex--get-truename master))
+         (master-dir (file-name-as-directory (reftex--get-directory master)))
+         (file (or file (reftex--get-buffer-identifier)))
+         (true-file (reftex--get-truename file))
          (bibview-cache (assq 'bibview-cache old-list))
          (reftex--index-tags (cdr (assq 'index-tags old-list)))
          from-file appendix docstruct tmp)
@@ -88,7 +88,7 @@ reftex-do-parse
                          (member (list 'eof file) old-list))))
       ;; Scan whole document because no such file section exists
       (setq rescan 1))
-    (when (string= true-file true-master)
+    (when (equal true-file true-master)
       ;; Scan whole document because this file is the master
       (setq rescan 1))
 
@@ -186,13 +186,14 @@ reftex-all-document-files
 When RELATIVE is non-nil, give file names relative to directory
 of master file."
   (let* ((all (symbol-value reftex-docstruct-symbol))
-         (master-dir (file-name-directory (reftex-TeX-master-file)))
+         (master-dir (reftex--get-directory (reftex-TeX-master-file)))
          (re (concat "\\`" (regexp-quote master-dir)))
         file-list tmp file)
     (while (setq tmp (assoc 'bof all))
       (setq file (nth 1 tmp)
             all (cdr (memq tmp all)))
       (and relative
+           (stringp file) ; Ignore non-file buffers.
            (string-match re file)
            (setq file (substring file (match-end 0))))
       (push file file-list))
@@ -228,7 +229,7 @@ reftex-parse-from-file
                 (not (eq t reftex-keep-temporary-buffers)))))
 
         ;; Begin of file mark
-        (setq file (buffer-file-name))
+        (setq file (reftex--get-buffer-identifier))
         (push (list 'bof file) docstruct)
 
         (reftex-with-special-syntax
@@ -275,7 +276,8 @@ reftex-parse-from-file
                  (when (and toc-entry
                             (eq ;; Either both are t or both are nil.
                              (= (char-after bound) ?%)
-                             (string-suffix-p ".dtx" file)))
+                             (and (stringp file)
+                                  (string-suffix-p ".dtx" file))))
                    ;; It can happen that section info returns nil
                    (setq level (nth 5 toc-entry))
                    (setq highest-level (min highest-level level))
@@ -638,7 +640,8 @@ reftex-where-am-I
                ((not found)
                 ;; no match
                 (or
-                 (car (member (list 'bof (buffer-file-name)) docstruct))
+                 (car (member (list 'bof (reftex--get-buffer-identifier))
+                              docstruct))
                  (not (setq cnt 2))
                  (assq 'bof docstruct)  ;; for safety reasons
                  'corrupted))
@@ -649,15 +652,16 @@ reftex-where-am-I
                ((match-end 3)
                 ;; Section
                 (goto-char (1- (match-beginning 3)))
-                (let* ((list (member (list 'bof (buffer-file-name))
+                (let* ((buffile (reftex--get-buffer-identifier))
+                       (list (member (list 'bof buffile)
                                      docstruct))
-                       (endelt (car (member (list 'eof (buffer-file-name))
+                       (endelt (car (member (list 'eof buffile)
                                             list)))
                        rtn1)
                   (while (and list (not (eq endelt (car list))))
                     (if (and (eq (car (car list)) 'toc)
-                             (string= (buffer-file-name)
-                                      (nth 3 (car list))))
+                             (equal buffile
+                                    (nth 3 (car list))))
                         (cond
                          ((equal (point)
                                  (or (and (markerp (nth 4 (car list)))
@@ -685,10 +689,13 @@ reftex-where-am-I
                 (when reftex-support-index
                   (let* ((index-info (save-excursion
                                        (reftex-index-info-safe nil)))
-                         (list (member (list 'bof (buffer-file-name))
-                                       docstruct))
-                         (endelt (car (member (list 'eof (buffer-file-name))
-                                              list)))
+                         (list (member
+                                (list 'bof (reftex--get-buffer-identifier))
+                                docstruct))
+                         (endelt
+                          (car (member
+                                (list 'eof (reftex--get-buffer-identifier))
+                                list)))
                          dist last-dist last (n 0))
                     ;; Check all index entries with equal text
                     (while (and list (not (eq endelt (car list))))
@@ -758,12 +765,13 @@ reftex-notice-new
          (when (re-search-forward (reftex-everything-regexp) nil t)
            (cond
             ((match-end 1)
-             (push (reftex-label-info (reftex-match-string 1) buffer-file-name)
+             (push (reftex-label-info (reftex-match-string 1)
+                                  (reftex--get-buffer-identifier))
                    (cdr tail)))
 
             ((match-end 3)
              (setq star (= ?* (char-after (match-end 3)))
-                   entry (reftex-section-info (buffer-file-name))
+                   entry (reftex-section-info (reftex--get-buffer-identifier))
                    level (nth 5 entry))
              ;; Insert the section info
              (push entry (cdr tail))
@@ -795,7 +803,8 @@ reftex-notice-new
             ((match-end 10)
              ;; Index entry
              (and reftex-support-index
-                  (setq entry (reftex-index-info-safe buffer-file-name))
+                  (setq entry (reftex-index-info-safe
+                               (reftex--get-buffer-identifier)))
                   ;; FIXME: (add-to-list 'reftex--index-tags (nth 1 index-entry))
                   (push entry (cdr tail))))))))))
 
diff --git a/lisp/textmodes/reftex-ref.el b/lisp/textmodes/reftex-ref.el
index 30e9968a8e5..8aa34ec942a 100644
--- a/lisp/textmodes/reftex-ref.el
+++ b/lisp/textmodes/reftex-ref.el
@@ -73,8 +73,10 @@ 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 (if (bufferp file)
+                  file
+                (reftex-get-file-buffer-force
+                 file (not (eq t reftex-keep-temporary-buffers))))))
     (if (not buf)
         (list label typekey "" file comment "LOST LABEL.  RESCAN TO FIX.")
       (with-current-buffer buf
@@ -102,7 +104,7 @@ reftex-label-info
   (let* ((prefix (if (string-match "^[a-zA-Z0-9]+:" label)
                      (match-string 0 label)))
          (typekey (cdr (assoc prefix reftex-prefix-to-typekey-alist)))
-         (file (or file (buffer-file-name)))
+         (file (or file (reftex--get-buffer-identifier)))
          (trust reftex-trust-label-prefix)
          (in-comment (reftex-in-comment)))
     (if (and typekey
@@ -249,7 +251,7 @@ reftex-label
              (note (if (cdr here-I-am-info)
                        ""
                      "POSITION UNCERTAIN.  RESCAN TO FIX."))
-             (file (buffer-file-name))
+             (file (reftex--get-buffer-identifier))
              ;; (text nil)
              (tail (memq here-I-am (symbol-value reftex-docstruct-symbol))))
 
@@ -314,19 +316,21 @@ reftex-replace-prefix-escapes
               (save-match-data
                 (cond
                  ((equal letter "f")
-                  (file-name-base (buffer-file-name)))
+                  (file-name-base (reftex--get-buffer-identifier)))
                  ((equal letter "F")
-                  (let ((masterdir (file-name-directory (reftex-TeX-master-file)))
-                        (file (file-name-sans-extension (buffer-file-name))))
+                  (let ((masterdir (reftex--get-directory
+                                    (reftex-TeX-master-file)))
+                        (file (file-name-sans-extension
+                               (reftex--get-buffer-identifier))))
                     (if (string-match (concat "\\`" (regexp-quote masterdir))
                                       file)
                         (substring file (length masterdir))
                       file)))
                  ((equal letter "m")
-                  (file-name-base (reftex-TeX-master-file)))
+                  (reftex--get-basename (reftex-TeX-master-file)))
                  ((equal letter "M")
                   (file-name-nondirectory
-                   (substring (file-name-directory (reftex-TeX-master-file))
+                   (substring (reftex--get-directory (reftex-TeX-master-file))
                               0 -1)))
                  ((equal letter "u")
                   (or (user-login-name) ""))
@@ -536,7 +540,8 @@ reftex-offer-label-menu
   ;; Offer a menu with the appropriate labels.
   (let* ((buf (current-buffer))
          (xr-data (assq 'xr (symbol-value reftex-docstruct-symbol)))
-         (xr-alist (cons (cons "" (buffer-file-name)) (nth 1 xr-data)))
+         (xr-alist (cons (cons "" (reftex--get-buffer-identifier))
+                         (nth 1 xr-data)))
          (xr-index 0)
          (here-I-am (car (reftex-where-am-I)))
          (here-I-am1 here-I-am)
diff --git a/lisp/textmodes/reftex-sel.el b/lisp/textmodes/reftex-sel.el
index 1f1c74550a5..6e65ad4786c 100644
--- a/lisp/textmodes/reftex-sel.el
+++ b/lisp/textmodes/reftex-sel.el
@@ -234,7 +234,7 @@ reftex-insert-docstruct
             reftex-active-toc nil
             master-dir-re
             (concat "\\`" (regexp-quote
-                           (file-name-directory (reftex-TeX-master-file))))))
+                           (reftex--get-directory (reftex-TeX-master-file))))))
 
     (setq-local reftex-docstruct-symbol docstruct-symbol)
     (setq-local reftex-prefix
diff --git a/lisp/textmodes/reftex-toc.el b/lisp/textmodes/reftex-toc.el
index d8d09da5ed0..2e3be51c87c 100644
--- a/lisp/textmodes/reftex-toc.el
+++ b/lisp/textmodes/reftex-toc.el
@@ -184,14 +184,14 @@ reftex-toc
 
   (interactive)
 
-  (if (or (not (string= reftex-last-toc-master (reftex-TeX-master-file)))
+  (if (or (not (equal reftex-last-toc-master (reftex-TeX-master-file)))
           ;; FIXME: use (interactive "P") to receive current-prefix-arg as
           ;; an argument instead of using the var here, which forces us to set
           ;; current-prefix-arg in the callers.
           current-prefix-arg)
       (reftex-erase-buffer "*toc*"))
 
-  (setq reftex-last-toc-file   (buffer-file-name))
+  (setq reftex-last-toc-file   (reftex--get-buffer-identifier))
   (setq reftex-last-toc-master (reftex-TeX-master-file))
 
   (set-marker reftex-toc-return-marker (point))
@@ -211,7 +211,8 @@ reftex-toc
   (let* ((this-buf (current-buffer))
          (docstruct-symbol reftex-docstruct-symbol)
          (xr-data (assq 'xr (symbol-value reftex-docstruct-symbol)))
-         (xr-alist (cons (cons "" (buffer-file-name)) (nth 1 xr-data)))
+         (xr-alist (cons (cons "" (reftex--get-buffer-identifier))
+                         (nth 1 xr-data)))
          (here-I-am (if reftex--rebuilding-toc
                         (get 'reftex-toc :reftex-data)
                       (car (reftex-where-am-I))))
@@ -261,7 +262,7 @@ reftex-toc
 "TABLE-OF-CONTENTS on %s
 SPC=view TAB=goto RET=goto+hide [q]uit [r]escan [l]abels [f]ollow [x]r [?]Help
 ------------------------------------------------------------------------------
-" (abbreviate-file-name reftex-last-toc-master)))
+" (reftex--abbreviate-name reftex-last-toc-master)))
 
       (if reftex-use-fonts
           (put-text-property (point-min) (point) 'font-lock-face reftex-toc-header-face))
@@ -997,7 +998,7 @@ reftex-recenter-toc-when-idle
        (not (active-minibuffer-window))
        (fboundp 'reftex-toc-mode)
        (get-buffer-window "*toc*" 'visible)
-       (string= reftex-last-toc-master (reftex-TeX-master-file))
+       (equal reftex-last-toc-master (reftex-TeX-master-file))
        (let (current-prefix-arg)
          (reftex-toc-recenter))))
 
diff --git a/lisp/textmodes/reftex.el b/lisp/textmodes/reftex.el
index fda506a6d87..05e3eb9ac10 100644
--- a/lisp/textmodes/reftex.el
+++ b/lisp/textmodes/reftex.el
@@ -251,6 +251,53 @@ LaTeX-label-function
 (defvar tex-main-file)
 (defvar outline-minor-mode)
 
+;;; =========================================================================
+;;;
+;;; Helper functions for handling both file names and buffer objects.
+;;;
+
+(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."
+  (let* ((buffer (or buffer (current-buffer)))
+         (buffer (or (buffer-base-buffer buffer) buffer)))
+    (or (buffer-local-value 'buffer-file-name buffer)
+        buffer)))
+
+(defun reftex--get-directory (file-or-buffer)
+  "Get the directory associated with FILE-OR-BUFFER.
+FILE-OR-BUFFER can be a file name or a buffer object."
+  (if (bufferp file-or-buffer)
+      (buffer-local-value 'default-directory file-or-buffer)
+    (file-name-directory file-or-buffer)))
+
+(defun reftex--abbreviate-name (file-or-buffer)
+  "Get a nice display name for FILE-OR-BUFFER.
+For files, returns the abbreviated file name.
+For buffers, returns the buffer name."
+  (if (bufferp file-or-buffer)
+      (prin1-to-string file-or-buffer)
+    (abbreviate-file-name file-or-buffer)))
+
+(defun reftex--get-basename (file-or-buffer)
+  "Get the base name (without extension) for FILE-OR-BUFFER.
+For file names, 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."
+  (if (bufferp file-or-buffer)
+      (file-name-base (buffer-name file-or-buffer))
+    (file-name-base file-or-buffer)))
+
+(defun reftex--get-truename (file-or-buffer)
+  "Get the canonical form of FILE-OR-BUFFER's identity.
+For files, returns the result of file-truename.
+For buffer objects, returns the buffer object itself."
+  (if (bufferp file-or-buffer)
+      file-or-buffer
+    (file-truename file-or-buffer)))
+
 ;;; =========================================================================
 ;;;
 ;;; Multibuffer Variables
@@ -279,10 +326,16 @@ reftex-next-multifile-index
   ;; Return the next free index for multifile symbols.
   (incf reftex-multifile-index))
 
+(defun reftex--remove-buffer-from-master-index ()
+  "Remove current buffer from `reftex-master-index-list'."
+  (setq reftex-master-index-list
+        (assq-delete-all (current-buffer) reftex-master-index-list)))
+
 (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)))
+  (let* ((master (reftex-TeX-master-file))
+         (master (reftex--get-truename master))
          (index (assoc master reftex-master-index-list))
          (symlist reftex-multifile-symbols)
          symbol symname newflag)
@@ -293,7 +346,11 @@ 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 index) reftex-master-index-list)
+      (when (bufferp master)
+        (with-current-buffer master
+          (add-hook 'kill-buffer-hook
+                    #'reftex--remove-buffer-from-master-index nil t))))
 
     ;; Get/create symbols and tie them.
     (while symlist
@@ -326,70 +383,76 @@ reftex-TeX-master-file
   ;; When AUCTeX is loaded, we will use it's more sophisticated method.
   ;; We also support the default TeX and LaTeX modes by checking for a
   ;; variable tex-main-file.
-  (let
-      ((master
-        (cond
-	 ;; Test if we're in a subfile using the subfiles document
-	 ;; class, e.g., \documentclass[main.tex]{subfiles}.  It's
-	 ;; argument is the main file, however it's not really the
-	 ;; master file in `TeX-master-file' or `tex-main-file's
-	 ;; sense.  It should be used for references but not for
-	 ;; compilation, thus subfiles use a setting of
-	 ;; `TeX-master'/`tex-main-file' being themselves.
-	 ((save-excursion
-            (goto-char (point-min))
-            (re-search-forward
-             "^[[:space:]]*\\\\documentclass\\[\\([^]]+\\)\\]{subfiles}"
-             nil t))
-          (match-string-no-properties 1))
-         ;; AUCTeX is loaded.  Use its mechanism.
-         ((fboundp 'TeX-master-file)
-          (condition-case nil
-              (TeX-master-file t)
-            (error (buffer-file-name))))
-         ;; Emacs LaTeX mode
-         ((fboundp 'tex-main-file) (tex-main-file))
-         ;; Check the `TeX-master' variable.
-         ((boundp 'TeX-master)
+  (with-current-buffer (or (buffer-base-buffer) (current-buffer))
+    (let
+        ;; Set master to a file name (possibly non-existent), or nil:
+        ((master
           (cond
-           ((eq TeX-master t)
-            (buffer-file-name))
-           ((eq TeX-master 'shared)
-            (setq TeX-master (read-file-name "Master file: "
-                                             nil nil t nil)))
-           (TeX-master)
+	   ;; Test if we're in a subfile using the subfiles document
+	   ;; class, e.g., \documentclass[main.tex]{subfiles}.  It's
+	   ;; argument is the main file, however it's not really the
+	   ;; master file in `TeX-master-file' or `tex-main-file's
+	   ;; sense.  It should be used for references but not for
+	   ;; compilation, thus subfiles use a setting of
+	   ;; `TeX-master'/`tex-main-file' being themselves.
+	   ((save-excursion
+              (goto-char (point-min))
+              (re-search-forward
+               "^[[:space:]]*\\\\documentclass\\[\\([^]]+\\)\\]{subfiles}"
+               nil t))
+            (match-string-no-properties 1))
+           ;; AUCTeX is loaded.  Use its mechanism.
+           ((fboundp 'TeX-master-file)
+            (condition-case nil
+                (TeX-master-file t)
+              (error (buffer-file-name))))
+           ;; Emacs LaTeX mode
+           ((fboundp 'tex-main-file)
+            (condition-case nil
+                (tex-main-file)
+              (error (buffer-file-name))))
+           ;; Check the `TeX-master' variable.
+           ((boundp 'TeX-master)
+            (cond
+             ((eq TeX-master t)
+              (buffer-file-name))
+             ((eq TeX-master 'shared)
+              (setq TeX-master (read-file-name "Master file: "
+                                               nil nil t nil)))
+             (TeX-master)
+             (t
+              (setq TeX-master (read-file-name "Master file: "
+                                               nil nil t nil)))))
+           ;; Check the `tex-main-file' variable.
+           ((boundp 'tex-main-file)
+            ;; This is the variable from the default TeX modes.
+            (cond
+             ((stringp tex-main-file)
+              ;; ok, this must be it
+              tex-main-file)
+             (t
+              ;; In this case, the buffer is its own master.
+              (buffer-file-name))))
+           ;; We know nothing about master file.  Assume this is a
+           ;; master file.
            (t
-            (setq TeX-master (read-file-name "Master file: "
-                                             nil nil t nil)))))
-         ;; Check the `tex-main-file' variable.
-         ((boundp 'tex-main-file)
-          ;; This is the variable from the default TeX modes.
-          (cond
-           ((stringp tex-main-file)
-            ;; ok, this must be it
-            tex-main-file)
-           (t
-            ;; In this case, the buffer is its own master.
-            (buffer-file-name))))
-         ;; We know nothing about master file.  Assume this is a
-         ;; master file.
-         (t
-          (buffer-file-name)))))
-    (cond
-     ((null master)
-      (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...
-      (setq master (concat master ".tex")))
-     ((or (file-exists-p master)
-          (find-buffer-visiting master))
-      ;; We either see the file, or have a buffer on it.  OK.
-      )
-     (t
-      ;; Use buffer file name.
-      (setq master (buffer-file-name))))
-    (expand-file-name master)))
+            (buffer-file-name)))))
+      (cond
+       ((null master))
+       ((or (file-exists-p (concat master ".tex"))
+            (find-buffer-visiting (concat master ".tex")))
+        ;; Ahh, an extra .tex was missing...
+        (setq master (concat master ".tex")))
+       ((or (file-exists-p master)
+            (find-buffer-visiting master))
+        ;; We either see the file, or have a buffer on it.  OK.
+        )
+       (t
+        ;; Use buffer file name.
+        (setq master (buffer-file-name))))
+      (if master
+          (expand-file-name master)
+        (current-buffer)))))
 
 (defun reftex-is-multi ()
   ;; Tell if this is a multifile document.  When not sure, say yes.
@@ -712,7 +775,7 @@ reftex-reset-mode
 (defun reftex-reset-scanning-information ()
   "Reset the symbols containing information from buffer scanning.
 This enforces rescanning the buffer on next use."
-  (if (string= reftex-last-toc-master (reftex-TeX-master-file))
+  (if (equal reftex-last-toc-master (reftex-TeX-master-file))
       (reftex-erase-buffer "*toc*"))
   (let ((symlist reftex-multifile-symbols)
         symbol)
@@ -1105,11 +1168,6 @@ reftex-access-scan-info
   ;; But, when RESCAN is -1, don't rescan even if docstruct is empty.
   ;; When FILE is non-nil, parse only from that file.
 
-  ;; Error out in a buffer without a file.
-  (if (and reftex-mode
-	   (not (buffer-file-name)))
-      (error "RefTeX works only in buffers visiting a file"))
-
   ;; Make sure we have the symbols tied
   (if (eq reftex-docstruct-symbol nil)
       ;; Symbols are not yet tied: Tie them.
@@ -1157,16 +1215,26 @@ reftex-silence-toc-markers
 
 (defun reftex-access-parse-file (action)
   "Perform ACTION on the parse file (the .rel file).
-Valid actions are: readable, restore, read, kill, write."
+Valid actions are: readable, restore, read, kill, write.
+For non-file buffers, persistence operations are skipped."
   (let* ((list (symbol-value reftex-docstruct-symbol))
          (docstruct-symbol reftex-docstruct-symbol)
          (master (reftex-TeX-master-file))
          (enable-local-variables nil)
-         (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))))
+         (non-file (bufferp master))
+         (file (if non-file
+                   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)))))
     (cond
+     ;; For non-file buffers, skip file operations but allow initialization.
+     (non-file (cond ((eq action 'readable) nil)
+                     ((eq action 'read) nil)
+                     ((eq action 'kill) t)
+                     ((eq action 'restore)
+                      (error "Cannot restore for non-file buffer"))))
      ((eq action 'readable)
       (file-readable-p file))
      ((eq action 'restore)
@@ -1240,7 +1308,9 @@ 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))
+    ;; Skip this check for buffer objects.
+    (unless (equal (reftex--get-truename real-master)
+                   (reftex--get-truename parsed-master))
       (message "Master file name in load file is different: %s versus %s"
                parsed-master real-master)
       (error "Master file name error")))
@@ -1281,7 +1351,7 @@ reftex-select-external-document
                   (mapconcat
                    (lambda (x)
                      (format fmt (incf n) (or (car x) "")
-                             (abbreviate-file-name (cdr x))))
+                             (reftex--abbreviate-name (cdr x))))
                    xr-alist ""))
                  nil t))
           (cond
@@ -1299,8 +1369,11 @@ reftex-locate-file
   "Find FILE of type TYPE in MASTER-DIR or on the path associated with TYPE.
 If the file does not have any of the valid extensions for TYPE,
 try first the default extension and only then the naked file name.
-When DIE is non-nil, throw an error if file not found."
-  (let* ((rec-values (if reftex-search-unrecursed-path-first '(nil t) '(t)))
+When DIE is non-nil, throw an error if file not found.
+When FILE is a buffer object, return that buffer."
+  (if (bufferp file)
+      file
+    (let* ((rec-values (if reftex-search-unrecursed-path-first '(nil t) '(t)))
          (extensions (cdr (assoc type reftex-file-extensions)))
          (def-ext (car extensions))
          (ext-re (concat "\\("
@@ -1335,7 +1408,7 @@ reftex-locate-file
 	    (setq file1 (reftex-find-file-on-path f path master-dir)))))))
     (cond (file1 file1)
           (die (error "No such file: %s" file) nil)
-          (t (message "No such file: %s (ignored)" file) nil))))
+          (t (message "No such file: %s (ignored)" file) nil)))))
 
 (defun reftex-find-file-externally (file type &optional master-dir)
   ;; Use external program to find FILE.
@@ -1742,7 +1815,9 @@ reftex-get-file-buffer-force
   ;; initializations according to `reftex-initialize-temporary-buffers',
   ;; and mark the buffer to be killed after use.
 
-  (let ((buf (find-buffer-visiting file)))
+  (let ((buf (if (bufferp file)
+                 file
+               (find-buffer-visiting file))))
 
     (cond (buf
            ;; We have it already as a buffer - just return it
diff --git a/test/lisp/textmodes/reftex-tests.el b/test/lisp/textmodes/reftex-tests.el
index 4e5053065cd..3a4d9b1f2e5 100644
--- a/test/lisp/textmodes/reftex-tests.el
+++ b/test/lisp/textmodes/reftex-tests.el
@@ -548,6 +548,329 @@ reftex-renumber-simple-labels
 \\end{document}"))
       (kill-buffer (file-name-nondirectory tex-file)))))
 
+;;; non-file buffers
+
+(ert-deftest reftex-all-used-citation-keys-buffer ()
+  "Test `reftex-all-used-citation-keys' on a buffer without a file."
+  (with-temp-buffer
+    (insert "\
+\\documentclass{article}
+\\usepackage{biblatex}
+\\begin{document}
+
+Standard commands:
+\\cite[pre][pos]{cite:2022}
+\\Cite[pos]{Cite:2022}
+\\parencite{parencite:2022}
+\\Parencite[pre][]{Parencite:2022}
+\\footcite[][]{footcite:2022}
+\\footcitetext[pre][pos]{footcitetext:2022}
+
+Style specific commands:
+\\textcite{textcite:2022}
+\\Textcite[pos]{Textcite:2022}
+\\smartcite[pre][pos]{smartcite:2022}
+\\Smartcite[pre][]{Smartcite:2022}
+\\cite*[pre][pos]{cite*:2022}
+\\parencite*[][]{parencite*:2022}
+
+Style independent commands:
+\\autocite[pre][pos]{autocite:2022}
+\\autocite*[pos]{autocite*:2022}
+\\Autocite[pre][]{Autocite:2022}
+\\Autocite*{Autocite*:2022}
+
+Text commands:
+\\citeauthor[pre][pos]{citeauthor:2022}
+\\citeauthor*[pre][]{citeauthor*:2022}
+\\Citeauthor[pos]{Citeauthor:2022}
+\\Citeauthor*{Citeauthor*:2022}
+\\citetitle[][]{citetitle:2022}
+\\citetitle*[pre][pos]{citetitle*:2022}
+\\citeyear[pre][pos]{citeyear:2022}
+\\citeyear*[pre][pos]{citeyear*:2022}
+\\citedate[pre][pos]{citedate:2022}
+\\citedate*[pre][pos]{citedate*:2022}
+\\citeurl[pre][pos]{citeurl:2022}
+
+Special commands:
+\\nocite{nocite:2022}
+\\fullcite[pos]{fullcite:2022}
+\\footfullcite[][]{fullfootcite:2022}
+``volcite'' macros have different number of args.
+\\volcite{2}{volcite:2022}
+\\Volcite[pre]{1}{Volcite:2022}
+\\pvolcite{1}[pg]{pvolcite:2022}
+\\Pvolcite[pre]{2}[pg]{Pvolcite:2022}
+\\fvolcite[pre]{3}[pg]{fvolcite:2022}
+\\ftvolcite[pre]{3}[pg]{ftvolcite:2022}
+\\svolcite[pre]{2}[pg]{svolcite:2022}
+\\Svolcite[pre]{4}[pg]{Svolcite:2022}
+\\tvolcite[pre]{5}[pg]{tvolcite:2022}
+\\Tvolcite[pre]{2}[pg]{Tvolcite:2022}
+\\avolcite[pre]{3}[pg]{avolcite:2022}
+\\Avolcite[pre]{1}[pg]{Avolcite:2022}
+\\Notecite[pre]{Notecite:2022}
+\\pnotecite[pre]{pnotecite:2022}
+\\Pnotecite[pre]{Pnotecite:2022}
+\\fnotecite[pre]{fnotecite:2022}
+
+Natbib compatibility commands:
+\\citet{citet:2022}
+\\citet*[pre][pos]{citet*:2022}
+\\citep[pre][pos]{citep:2022}
+\\citep*[pos]{citep*:2022}
+\\citealt[pre][]{citealt:2022}
+\\citealt*[][]{citealt*:2022}
+\\citealp[pre][pos]{citealp:2022}
+\\citealp*{citealp*:2022}
+\\Citet[pre][pos]{Citet:2022}
+\\Citet*[pre][pos]{Citet*:2022}
+\\Citep[pre][pos]{Citep:2022}
+\\Citep*[pre][pos]{Citep*:2022}
+
+Qualified Citation Lists:
+\\cites(Global Prenote)(Global Postnote)[pre][post]{cites:1}[pre][post]{cites:2}
+\\Cites(Global Prenote)(Global Postnote)[pre][post]{Cites:1}[pre][post]{Cites:2}
+\\parencites(Global Prenote)(Global Postnote)[pre][post]{parencites:1}
+  [pre][post]{parencites:2}
+\\Parencites(Global Prenote)(Global Postnote)[pre][post]{Parencites:1}{Parencites:2}
+\\footcites[pre][post]{footcites:1}[pre][post]{footcites:2}
+\\footcitetexts{footcitetexts:1}{footcitetexts:2}
+\\smartcites{smartcites:1}
+% This is comment about \\smartcites{smartcites:2}
+[pre][post]{smartcites:2}
+% And this should be ignored \\smartcites{smartcites:3}{smartcites:4}
+
+
+Test for bug#56655:
+There was a few \\% of increase in budget \\Citep*{bug:56655}.
+
+And this should be % \\cite{ignored}.
+\\end{document}")
+    (tex-mode)
+    (let ((keys (reftex-all-used-citation-keys)))
+      (should (equal (sort keys #'string<)
+                     (sort (list
+                           ;; Standard commands:
+                           "cite:2022"      "Cite:2022"
+                           "parencite:2022" "Parencite:2022"
+                           "footcite:2022"  "footcitetext:2022"
+                           ;; Style specific commands:
+                           "textcite:2022"  "Textcite:2022"
+                           "smartcite:2022" "Smartcite:2022"
+                           "cite*:2022" "parencite*:2022"
+                           ;; Style independent commands:
+                           "autocite:2022"  "autocite*:2022"
+                           "Autocite:2022"  "Autocite*:2022"
+                           ;; Text commands
+                           "citeauthor:2022" "citeauthor*:2022"
+                           "Citeauthor:2022" "Citeauthor*:2022"
+                           "citetitle:2022"  "citetitle*:2022"
+                           "citeyear:2022"   "citeyear*:2022"
+                           "citedate:2022"   "citedate*:2022"
+                           "citeurl:2022"
+                           ;; Special commands:
+                           "nocite:2022"     "fullcite:2022"
+                           "fullfootcite:2022"
+                           "volcite:2022"   "Volcite:2022"
+                           "pvolcite:2022"  "Pvolcite:2022"
+                           "fvolcite:2022"  "ftvolcite:2022"
+                           "svolcite:2022"  "Svolcite:2022"
+                           "tvolcite:2022"  "Tvolcite:2022"
+                           "avolcite:2022"  "Avolcite:2022"
+                           "Notecite:2022"  "pnotecite:2022"
+                           "Pnotecite:2022" "fnotecite:2022"
+                           ;; Natbib compatibility commands:
+                           "citet:2022"   "citet*:2022"
+                           "citep:2022"   "citep*:2022"
+                           "citealt:2022" "citealt*:2022"
+                           "citealp:2022" "citealp*:2022"
+                           "Citet:2022"   "Citet*:2022"
+                           "Citep:2022"   "Citep*:2022"
+                           ;; Qualified Citation Lists
+                           "cites:1"         "cites:2"
+                           "Cites:1"         "Cites:2"
+                           "parencites:1"    "parencites:2"
+                           "Parencites:1"    "Parencites:2"
+                           "footcites:1"     "footcites:2"
+                           "footcitetexts:1" "footcitetexts:2"
+                           "smartcites:1"    "smartcites:2"
+                           "bug:56655")
+                         #'string<))))))
+
+(ert-deftest reftex-renumber-simple-labels-buffer ()
+  "Test `reftex-renumber-simple-labels' on a buffer without a file."
+  (let ((temp-buffer (generate-new-buffer " *temp*")))
+    (unwind-protect
+        (with-current-buffer temp-buffer
+          (insert "\
+\\documentclass{article}
+\\usepackage{tcolorbox}
+\\tcbuselibrary{theorems}
+\\usepackage{fancyvrb}
+\\usepackage{listings}
+
+\\begin{document}
+
+This is with tcolorbox package:
+\\begin{problem}[%
+    colback                = white          ,
+    colframe               = red!50!black   ,
+    fonttitle              = \\bfseries      ,
+    description delimiters = {\\flqq}{\\frqq} ,
+    label                  = {problem:2}]{Prove RH2}{}
+  Problem
+\\end{problem}
+
+This is with vanilla \\LaTeX:
+\\begin{equation}
+  \\label{eq:2}
+  2
+\\end{equation}
+By \\eqref{eq:2} and \\ref{problem:2}
+
+This is with tcolorbox package:
+\\begin{problem}[%
+    colback=white,
+    colframe=red!50!black,
+    fonttitle=\\bfseries,
+    theorem label supplement={hypertarget={XYZ-##1}},
+    theorem full label supplement={code={\\marginnote{##1}}},
+    label={problem:1}]{Prove RH1}{}
+  Problem
+\\end{problem}
+
+This is with vanilla \\LaTeX:
+\\begin{equation}
+  \\label{eq:1}
+  1
+\\end{equation}
+
+\\Cref{problem:1} and \\pageref{eq:1}.
+
+\\begin{problem}[label={problem:6}]{Some Problem}{}
+  Problem
+\\end{problem}
+
+\\Ref{problem:6}.
+
+This is with fancyvrb package:
+\\begin{Verbatim}[reflabel={lst:6}]
+Some Verb Content
+\\end{Verbatim}
+
+\\pageref{lst:6}
+
+This is with listings package:
+\\begin{lstlisting}[language=elisp,caption=Some Caption,label={lst:3}]
+(car (cons 1 '(2)))
+\\end{lstlisting}
+
+\\ref{lst:3}
+
+\\end{document}")
+
+          ;; The label prefix must be known to RefTeX:
+          (add-to-list 'reftex-label-alist
+                       '("problem" ?p "problem:" "~\\ref{%s}"
+                         nil nil nil)
+                       t)
+          (add-to-list 'reftex-label-alist
+                       '("Verbatim" ?l "lst:" "~\\ref{%s}"
+                         nil nil nil)
+                       t)
+          ;; The environments must be known to RefTeX otherwise the labels
+          ;; aren't parsed correctly:
+          (add-to-list 'reftex-label-regexps
+                       (concat "\\\\begin{\\(?:problem\\|Verbatim\\)}"
+                               "\\[[^][]*"
+                               "\\(?:{[^}{]*"
+                               "\\(?:{[^}{]*"
+                               "\\(?:{[^}{]*}[^}{]*\\)*"
+                               "}[^}{]*\\)*"
+                               "}[^][]*\\)*"
+                               "\\<\\(?:ref\\)?label[[:space:]]*=[[:space:]]*"
+                               "{?\\(?1:[^] ,}\r\n\t%]+\\)"
+                               "[^]]*\\]")
+                       t)
+          ;; Always run this after changing `reftex-label-regexps':
+          (reftex-compile-variables)
+
+          ;; Silence the user query:
+          (cl-letf (((symbol-function 'yes-or-no-p) #'always))
+            (reftex-renumber-simple-labels))
+
+          (should (string= (buffer-string)
+                           "\
+\\documentclass{article}
+\\usepackage{tcolorbox}
+\\tcbuselibrary{theorems}
+\\usepackage{fancyvrb}
+\\usepackage{listings}
+
+\\begin{document}
+
+This is with tcolorbox package:
+\\begin{problem}[%
+    colback                = white          ,
+    colframe               = red!50!black   ,
+    fonttitle              = \\bfseries      ,
+    description delimiters = {\\flqq}{\\frqq} ,
+    label                  = {problem:1}]{Prove RH2}{}
+  Problem
+\\end{problem}
+
+This is with vanilla \\LaTeX:
+\\begin{equation}
+  \\label{eq:1}
+  2
+\\end{equation}
+By \\eqref{eq:1} and \\ref{problem:1}
+
+This is with tcolorbox package:
+\\begin{problem}[%
+    colback=white,
+    colframe=red!50!black,
+    fonttitle=\\bfseries,
+    theorem label supplement={hypertarget={XYZ-##1}},
+    theorem full label supplement={code={\\marginnote{##1}}},
+    label={problem:2}]{Prove RH1}{}
+  Problem
+\\end{problem}
+
+This is with vanilla \\LaTeX:
+\\begin{equation}
+  \\label{eq:2}
+  1
+\\end{equation}
+
+\\Cref{problem:2} and \\pageref{eq:2}.
+
+\\begin{problem}[label={problem:3}]{Some Problem}{}
+  Problem
+\\end{problem}
+
+\\Ref{problem:3}.
+
+This is with fancyvrb package:
+\\begin{Verbatim}[reflabel={lst:1}]
+Some Verb Content
+\\end{Verbatim}
+
+\\pageref{lst:1}
+
+This is with listings package:
+\\begin{lstlisting}[language=elisp,caption=Some Caption,label={lst:2}]
+(car (cons 1 '(2)))
+\\end{lstlisting}
+
+\\ref{lst:2}
+
+\\end{document}")))
+      (kill-buffer temp-buffer))))
+
+
 ;;; Autoload tests
 
 ;; Test to check whether reftex autoloading mechanisms are working
-- 
2.39.3 (Apple Git-145)


--=-=-=--




Information forwarded to bug-auctex@HIDDEN:
bug#76615; Package auctex. Full text available.

Message received at 76615 <at> debbugs.gnu.org:


Received: (at 76615) by debbugs.gnu.org; 4 Apr 2025 15:23:20 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Apr 04 11:23:20 2025
Received: from localhost ([127.0.0.1]:39600 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1u0it6-0005vh-33
	for submit <at> debbugs.gnu.org; Fri, 04 Apr 2025 11:23:20 -0400
Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]:54600)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <ultrono@HIDDEN>) id 1u0it2-0005vA-Uu
 for 76615 <at> debbugs.gnu.org; Fri, 04 Apr 2025 11:23:17 -0400
Received: by mail-ed1-x534.google.com with SMTP id
 4fb4d7f45d1cf-5efe8d9eb12so3228224a12.1
 for <76615 <at> debbugs.gnu.org>; Fri, 04 Apr 2025 08:23:16 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1743780190; x=1744384990; darn=debbugs.gnu.org;
 h=mime-version:message-id:date:in-reply-to:subject:cc:to:from:from:to
 :cc:subject:date:message-id:reply-to;
 bh=qH8C3OZUy+wBv7QIoSbDO4Lx2F/Jk00ly7mZJ1UiqC0=;
 b=KMzaZ3oIpBQmtT7tt1JH98yLf33fG/kp4azs7NvIOah/DAIgZ0YDXLqj6WKAEfH3cZ
 j9129mPGsxxzWgag0IXMg8kCvROxtqXhP9u/3HD5UFvZHqC+k8kTrzX4IEB4OdQjOQ3d
 QxERRnFnX+ndBZB3sjlig9ZLbmTMW1M0lfjQzpJ2TIHQchIDDBI4L6Cd9iKwklBt8Mw8
 iZItueEuOUgAsaW4xh5VEm5WPionsCYxD2sAi3z2pdRKuqEoKRYK16mqYjVWf2jjGaPr
 AwxBmvB4PH92VywT8KBYjSkSL6GA0/VmQ6p1Eu86nUJjK3pK3zvW61SeXAraONSb7hMb
 +A/A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1743780190; x=1744384990;
 h=mime-version:message-id:date:in-reply-to:subject:cc:to:from
 :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
 bh=qH8C3OZUy+wBv7QIoSbDO4Lx2F/Jk00ly7mZJ1UiqC0=;
 b=WBay3ZsgwwGy294MFu7V0MXVADFjhh3z88RJiuBCmNgdGSV5QL7EoJebuObxLhkSXx
 UKaSL4cUJJIHSn3CrdVFlOYAbfkZcETATehXDipISDuKiKDtvmykn4ptLlW3RenWrXnH
 4xasVFB4vhsEAXUJFwCye/V2NrfePTiT6naRuuIGsfPvfVTYCljEnn4LbAHB4CDSiLRq
 2bmRVOmPhVJxlEh0y8lXrbrX4w+O7lcPU8qJWuHwqA3AF0j9WcTVlC76SZbAQz2EjfK1
 DRyHqIjUkQo+7COma7ho4y2cJy63v/5OzMhJo6tJL+Br/FRWFffHoHb4xKNsnvhNU5/Y
 igig==
X-Forwarded-Encrypted: i=1;
 AJvYcCWd8JKT2pccSFYQ/CrvsF5dkoLd3AAIewhoUvDRBz1buj7dx06w86WOorzFAO9+2sgCpTCkuQ==@debbugs.gnu.org
X-Gm-Message-State: AOJu0YwstCJXUt0yo1NIe+GIAYxdTNxa+19ykfIfmdo2x550b4v80TJ5
 hcy97SPnQ9BVhGKgJD7b2wyheqVrcyJ3eMRpg+7rQSUw/3+sA2Xh
X-Gm-Gg: ASbGncs3dKxmDGFD2qcuzJq81jnTRaL0x2FZqrITdu3x+p5eGD7X5WYpIxmpT4yP9ZY
 xH17a53YNSQa44BvNXDlyR6V3MmDDEHM0C5zobixa+Rd+r+fsxl54NzJk/Qc/muF1f418Ksy3kc
 ZAP8l0IMEp3C34vEucraACo344cZt9cYEtBJuGB61ezp7J6LrHar/bSOOWEvZOa9IzaDaRQjcwr
 nJpgiMYnv3WI+7y/xc4j04vsEVM+6PqiVWpSYfphuOrpDBWp4QVjaQIOlk3f52PHuP4/tnTrL0i
 wdBMoXJckc4Kyuo947bBHbsLUvB3ni3MZPb7p0sNYTTgSbeXD4xuI8btULMPFAwXjtD5wCOyxV5
 /FEIjlwHh1w==
X-Google-Smtp-Source: AGHT+IGbxp1whc1y7QjdJ8ABQQWHfGyiEf2vLpkEYqyqgddhq6EmrxRB9q3nzy48P1wcs5AQxygPtg==
X-Received: by 2002:a05:6402:34c6:b0:5e4:d402:5c20 with SMTP id
 4fb4d7f45d1cf-5f0b309b9bcmr3003364a12.0.1743780189818; 
 Fri, 04 Apr 2025 08:23:09 -0700 (PDT)
Received: from localhost (0x573d6713.static.cust.fastspeed.dk. [87.61.103.19])
 by smtp.gmail.com with UTF8SMTPSA id
 4fb4d7f45d1cf-5f087ed1c1csm2485322a12.22.2025.04.04.08.23.08
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 04 Apr 2025 08:23:09 -0700 (PDT)
From: "Paul D. Nelson" <ultrono@HIDDEN>
To: Arash Esbati <arash@HIDDEN>
Subject: Re: bug#76615: 14.0.9; error with amsmath style hooks
In-Reply-To: <m2v7rlrskl.fsf@HIDDEN> (message from Arash Esbati
 on Thu, 03 Apr 2025 20:46:50 +0200)
Date: Fri, 04 Apr 2025 17:23:07 +0200
Message-ID: <uxsg7tv7rkne78.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 76615
Cc: ikumi@HIDDEN, monnier@HIDDEN, 76615 <at> debbugs.gnu.org,
 carsten.dominik@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

> 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@HIDDEN:
bug#76615; Package auctex. Full text available.

Message received at 76615 <at> debbugs.gnu.org:


Received: (at 76615) by debbugs.gnu.org; 3 Apr 2025 18:47:04 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Apr 03 14:47:04 2025
Received: from localhost ([127.0.0.1]:35704 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1u0Pah-0003iY-RK
	for submit <at> debbugs.gnu.org; Thu, 03 Apr 2025 14:47:04 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:42530)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <arash@HIDDEN>) id 1u0Paf-0003hx-3A
 for 76615 <at> debbugs.gnu.org; Thu, 03 Apr 2025 14:47:01 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <arash@HIDDEN>)
 id 1u0PaY-0006v6-1x; Thu, 03 Apr 2025 14:46:54 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To:
 From; bh=HJsF/WHq5HAliQA3tmER1ViYvwzguRTU6bMrCq0V13w=; b=POcQ4PHc2dEuCNusZPTa
 PpsMO/ufmwBhCCvyyzljjw4O81VzbzXXAL05pAge5KaBdT7VwN6t661UMSnDdhE5w0Z2BQ4c5UsgU
 AlH9kxWsLMJl7HXZj4gd7gwCVyugAVsIPSZ/xPCJnDYYDLrdyEcs9+gmkjZUHjCPzl3pnr9hxuNyT
 NVRsfDpXVhYqEXnJGQXSvPgAyk9f2HAL/3JJuWZvX1/2jYWQEyWV1vnLWCfKmsPN3N7GaHta6vPRZ
 0+yeSJ8a1Sj6VQEylkFybr+n5bkSazjWfeQgg7TrYEnlpjqe9te2E/Ozegm3jrjY/iSO7Su0Lfenq
 zoFw7ApCjdqK4A==;
From: Arash Esbati <arash@HIDDEN>
To: "Paul D. Nelson" <ultrono@HIDDEN>
Subject: Re: bug#76615: 14.0.9; error with amsmath style hooks
In-Reply-To: <uxsg7ty0whnle6.fsf@HIDDEN>
References: <uxsg7ty0whnle6.fsf@HIDDEN>
Date: Thu, 03 Apr 2025 20:46:50 +0200
Message-ID: <m2v7rlrskl.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76615
Cc: ikumi@HIDDEN, monnier@HIDDEN, 76615 <at> debbugs.gnu.org,
 carsten.dominik@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

Hi Paul,

"Paul D. Nelson" <ultrono@HIDDEN> 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@HIDDEN:
bug#76615; Package auctex. Full text available.

Message received at 76615 <at> debbugs.gnu.org:


Received: (at 76615) by debbugs.gnu.org; 3 Apr 2025 18:37:21 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Apr 03 14:37:21 2025
Received: from localhost ([127.0.0.1]:35662 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1u0PRI-0003DQ-Or
	for submit <at> debbugs.gnu.org; Thu, 03 Apr 2025 14:37:21 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:35786)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <arash@HIDDEN>) id 1u0PRG-0003D9-Rj
 for 76615 <at> debbugs.gnu.org; Thu, 03 Apr 2025 14:37:19 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <arash@HIDDEN>)
 id 1u0PR8-0005Gh-KA; Thu, 03 Apr 2025 14:37:10 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To:
 From; bh=zl4wWRoeDBySDSShlYuxYxdEv6HardX4cFI7DTtuxb4=; b=UCUC8J29ssCmXNJ2PBQz
 2pg27+eA1hYNWnuMZtZ8gDqAxYYqHlutajYshOr4b9LPtLLMf4cjRq2W+lHvtCdNcf0t0iM+DNDTQ
 eCUVFfySRVQpHm4FGqVDH2zmN8lUxvi6j1J4l6+bA45B04ULQaN8lIL7g9pEIxruyzEF9gWYUCr7B
 09ItRGsVss+cqnOn86pj8o1oasEPNUuFXbV+RLZODNLJ+BrBsai2p7wRMrtfM8GEtTRHmbb6bVIgH
 HWd32iAIKh7ksBhS73qtmKlVSgpM5y7gTSzTgCTpCG7P9dl3C7ig/y1SwVzgKCPTTJ/HXhwMxDrP5
 JH3e1x5CyUagNA==;
From: Arash Esbati <arash@HIDDEN>
To: "Paul D. Nelson" <ultrono@HIDDEN>
Subject: Re: bug#76615: 14.0.9; error with amsmath style hooks
In-Reply-To: <uxsg7t1pu9pcwu.fsf@HIDDEN>
References: <uxsg7t1pu9pcwu.fsf@HIDDEN>
Date: Thu, 03 Apr 2025 20:37:07 +0200
Message-ID: <m2zfgxrt0s.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76615
Cc: ikumi@HIDDEN, Stefan Monnier <monnier@HIDDEN>,
 76615 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

"Paul D. Nelson" <ultrono@HIDDEN> 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@HIDDEN:
bug#76615; Package auctex. Full text available.

Message received at 76615 <at> debbugs.gnu.org:


Received: (at 76615) by debbugs.gnu.org; 3 Apr 2025 18:35:43 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Apr 03 14:35:43 2025
Received: from localhost ([127.0.0.1]:35652 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1u0PPi-00039T-0F
	for submit <at> debbugs.gnu.org; Thu, 03 Apr 2025 14:35:43 -0400
Received: from mail-ej1-x635.google.com ([2a00:1450:4864:20::635]:42493)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <ultrono@HIDDEN>) id 1u0PPd-00039C-SV
 for 76615 <at> debbugs.gnu.org; Thu, 03 Apr 2025 14:35:39 -0400
Received: by mail-ej1-x635.google.com with SMTP id
 a640c23a62f3a-ac2a089fbbdso218818766b.1
 for <76615 <at> debbugs.gnu.org>; Thu, 03 Apr 2025 11:35:37 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1743705332; x=1744310132; darn=debbugs.gnu.org;
 h=mime-version:message-id:date:in-reply-to:subject:cc:to:from:from:to
 :cc:subject:date:message-id:reply-to;
 bh=jprbNNto8kJ01s1hMpExo9zHu6Ga8Cx2jQaG49QGeE0=;
 b=cw6mxMDLaBXERsY6VgsN5L7jUi57bfmzM86jdnMdH6lIFJR/JCEmkEXyiZfmAtKSiM
 s3WzZnBLKvlMqiOgOatrZ07+RRH/2rZ83y7s0SP0qSXA5PljwiSf70C2kBLA/yX+SBFp
 FRS9WvyYkJ3eALu67okT/8AM1gHkZOAq0JBE1xnHIqZCJ1NlvCJ4wtTsVXYKBseMAi5m
 QtvOoelHnIbb3zWzQdaV84TUocbvDMXIVk6wtcubyqPcVQ4hTiv3ypc31zlYThQ6kxBe
 96tlsl119INzva0RNt1jnQ14oJtIsFaN076na/fay9UMtUwQjRRnXkyxfJY6Yc1LhTVa
 587Q==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1743705332; x=1744310132;
 h=mime-version:message-id:date:in-reply-to:subject:cc:to:from
 :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
 bh=jprbNNto8kJ01s1hMpExo9zHu6Ga8Cx2jQaG49QGeE0=;
 b=s+LPzPcGIxhXk8m2WgVEI3P6SN9e+zN6Yxp334W7gHm0QRuQc+w1k0VRH7V3sd8PhG
 xUWHKT+kuBsO9IE6fk9Y3OAPcjnurWP6pLDlTHbsDAg/kV2cfsMJ1KOIfg+9gbNxCJuT
 JHsorSce/yRYlZnXCpUqAQCjuho5HcnH5N4b7ZyFAf6Mm7S6lZ35OTQn9fVmdkP4PUvG
 9dkqOTDtIGcbCrzrlzlfXzXxEX/xS5odN3z7tJ3nfK1VHS3sw28EEgKZdvOA3OiZrN6b
 /9IUJEqszjwa0EdVflaNePV0Z/wi534Sp4Rmld1T6kOTYw0ldgLXMYsxkED2WTKHjfgd
 ne5A==
X-Forwarded-Encrypted: i=1;
 AJvYcCXQJzkrHsqX/TxSVVewWFjFKZXK+C/qOV7yTDq183HbQ7cyQDMA2w/SLc96j3uy/BjwlNGhlg==@debbugs.gnu.org
X-Gm-Message-State: AOJu0Yxx7kXLTSclrR7Jl4gep49+SM1tIe2A336NI/H8iAOXYefnMdoQ
 OtcuNTmtO37DRfOjLPVSEfVIxO/yb1nGQnNoOYjV/lX5w2STls4RMwD1a26L
X-Gm-Gg: ASbGncuJuILczY2dOBcHsbHrQmmdg45mN0rGlJSTpm3Wf/CxFRooIT5AVe54qITWlsf
 jCTCjSDQWULj8q+wD1CIPR0oVxyoXjwNBjP80vg7e9WuzCctpyAgRbn1LDHzEJ7HwtFPry0n4/I
 hPrltKpeMHJNB1NLLLQ3lc8oHk8FySMi8vXW0H0Hx6rcQC9+fwLKLnigz0FdGE0OHAhATWbi7so
 iFMrnAtj5gnVxKmg7Z1O/e84b9v+bC+NQLypPhvlu/1WHDfGlmYml0nbCuC4fSn0XSsp9hzDWiG
 yPzxIGTLur2MrLDYdcjjEDST5m6ewHpDFmIjAQz1kIwQOOcBptry5q3ch+VZa9k4h8/TfV+R7NF
 mD4+knVTQ5A==
X-Google-Smtp-Source: AGHT+IELa9xkjFbA/X/hW7nUTTSn8V1PTMAQyS3eatGLFu79pCCxW42LpE/OwYfmAR6HQiFt1WDdvw==
X-Received: by 2002:a17:907:6e9e:b0:ac7:3dd2:db90 with SMTP id
 a640c23a62f3a-ac7b671e786mr405205066b.0.1743705331287; 
 Thu, 03 Apr 2025 11:35:31 -0700 (PDT)
Received: from localhost (0x573d6713.static.cust.fastspeed.dk. [87.61.103.19])
 by smtp.gmail.com with UTF8SMTPSA id
 a640c23a62f3a-ac7bfe5d794sm133926866b.11.2025.04.03.11.35.30
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Thu, 03 Apr 2025 11:35:30 -0700 (PDT)
From: "Paul D. Nelson" <ultrono@HIDDEN>
To: Arash Esbati <arash@HIDDEN>
Subject: Re: bug#76615: 14.0.9; error with amsmath style hooks
In-Reply-To: <m24iz5t80x.fsf@HIDDEN> (message from Arash Esbati
 on Thu, 03 Apr 2025 20:27:42 +0200)
Date: Thu, 03 Apr 2025 20:35:29 +0200
Message-ID: <uxsg7ty0whnle6.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 76615
Cc: ikumi@HIDDEN, monnier@HIDDEN, 76615 <at> debbugs.gnu.org,
 carsten.dominik@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

--=-=-=
Content-Type: text/plain

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


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=0001-Add-RefTeX-support-for-non-file-buffers.patch

From ecdb46947b6668566da9a730415038e74e925943 Mon Sep 17 00:00:00 2001
From: Paul Nelson <ultrono@HIDDEN>
Date: Wed, 2 Apr 2025 21:38:48 +0200
Subject: [PATCH] Add RefTeX support for non-file buffers

* lisp/textmodes/reftex.el (reftex--get-buffer-identifier)
(reftex--get-directory, reftex--abbreviate-name)
(reftex--get-basename, reftex--get-truename): New helper
functions that handle both files and buffer objects.
(reftex--remove-buffer-from-master-index): New helper function.
(reftex-tie-multifile-symbols): Support non-file buffers, using
the above.
(reftex-TeX-master-file): Return current buffer when no file.
(reftex-access-scan-info): Remove check requiring file buffers.
(reftex-access-parse-file, reftex-check-parse-consistency): Skip
for non-file buffers.
(reftex-select-external-document): Use new helper function.
(reftex-locate-file): Return buffer objects directly.
(reftex-get-file-buffer-force): Handle buffer objects and
special 'buffer:' strings.
* lisp/textmodes/reftex-global.el (reftex-create-tags-file): Add
error handling for non-file buffers.  Leave TAGS unsupported in
non-file buffers.
(reftex-find-duplicate-labels)
(reftex-isearch-switch-to-next-file): Use new helper functions
that handle both files and buffer objects.
(reftex-isearch-switch-to-next-file): Use equal rather than
string= to compare strings/buffers.
* lisp/textmodes/reftex-index.el (reftex-display-index)
(reftex-index-change-entry): Use new helper functions.
(reftex-index-visit-phrases-buffer): Add error handling for
non-file buffers.  Leave phrases unsupported in non-file
buffers.
* lisp/textmodes/reftex-parse.el (reftex-do-parse)
(reftex-parse-from-file): Add support for non-file buffers.
(reftex-all-document-files, reftex-where-am-I)
(reftex-notice-new): Use new helper functions.
* lisp/textmodes/reftex-ref.el (reftex-label-info-update):
Support non-file buffers.
(reftex-label-info, reftex-replace-prefix-escapes, reftex-label)
(reftex-replace-prefix-escapes, reftex-offer-label-menu): Use
new helper functions.
* lisp/textmodes/reftex-sel.el (reftex-insert-docstruct): Use
new helper function.
* lisp/textmodes/reftex-toc.el (reftex-toc)
(reftex-recenter-toc-when-idle): Support non-file buffers.
* lisp/textmodes/reftex-cite.el (reftex-bib-or-thebib)
(reftex-get-bibfile-list): Use new helper functions.

RefTeX historically assumed that the buffers it operates on
visit files.  To handle non-file buffers:

Modify reftex-TeX-master-file so that it returns the buffer
object itself (as suggested by Stefan Monnier).  Modify each
caller to handle buffer objects, aided by some helper functions
added to reftex.el.  Replace 'string=' by 'equal' in places.

Use buffer-base-buffer, where appropriate, to handle indirect
buffers (file and non-file).

TAGS files and phrases buffers remain unsupported for non-file
buffers.
---
 lisp/textmodes/reftex-cite.el   |   9 +-
 lisp/textmodes/reftex-global.el |  28 ++--
 lisp/textmodes/reftex-index.el  |  25 ++--
 lisp/textmodes/reftex-parse.el  |  48 ++++---
 lisp/textmodes/reftex-ref.el    |  25 ++--
 lisp/textmodes/reftex-sel.el    |   2 +-
 lisp/textmodes/reftex-toc.el    |  11 +-
 lisp/textmodes/reftex.el        | 234 +++++++++++++++++++++-----------
 8 files changed, 237 insertions(+), 145 deletions(-)

diff --git a/lisp/textmodes/reftex-cite.el b/lisp/textmodes/reftex-cite.el
index fe6751a13f6..8830f188c93 100644
--- a/lisp/textmodes/reftex-cite.el
+++ b/lisp/textmodes/reftex-cite.el
@@ -76,7 +76,8 @@ reftex-bib-or-thebib
   "Test if BibTeX or \\begin{thebibliography} should be used for the citation.
 Find the bof of the current file."
   (let* ((docstruct (symbol-value reftex-docstruct-symbol))
-         (rest (or (member (list 'bof (buffer-file-name)) docstruct)
+         (rest (or (member (list 'bof (reftex--get-buffer-identifier))
+                           docstruct)
                    docstruct))
          (bib (assq 'bib rest))
          (thebib (assq 'thebib rest))
@@ -104,11 +105,11 @@ reftex-get-bibfile-list
   (or
    ;; Try inside this file (and its includes)
    (cdr (reftex-last-assoc-before-elt
-         'bib (list 'eof (buffer-file-name))
-         (member (list 'bof (buffer-file-name))
+         'bib (list 'eof (reftex--get-buffer-identifier))
+         (member (list 'bof (reftex--get-buffer-identifier))
                  (symbol-value reftex-docstruct-symbol))))
    ;; Try after the beginning of this file
-   (cdr (assq 'bib (member (list 'bof (buffer-file-name))
+   (cdr (assq 'bib (member (list 'bof (reftex--get-buffer-identifier))
                            (symbol-value reftex-docstruct-symbol))))
    ;; Anywhere in the entire document
    (cdr (assq 'bib (symbol-value reftex-docstruct-symbol)))
diff --git a/lisp/textmodes/reftex-global.el b/lisp/textmodes/reftex-global.el
index 20abd36192d..e211b10451a 100644
--- a/lisp/textmodes/reftex-global.el
+++ b/lisp/textmodes/reftex-global.el
@@ -37,16 +37,18 @@ reftex-create-tags-file
 The TAGS file is also immediately visited with `visit-tags-table'."
   (interactive)
   (reftex-access-scan-info current-prefix-arg)
-  (let* ((master (reftex-TeX-master-file))
-         (files  (reftex-all-document-files))
-         (cmd    (format "%s %s"
-                         etags-program-name
-                         (mapconcat #'shell-quote-argument
-				    files " "))))
-    (with-current-buffer (reftex-get-file-buffer-force master)
-      (message "Running etags to create TAGS file...")
-      (shell-command cmd)
-      (visit-tags-table "TAGS"))))
+  (let ((master (reftex-TeX-master-file)))
+    (if (bufferp master)
+        (user-error "Cannot create TAGS file for non-file buffers")
+      (let* ((files  (reftex-all-document-files))
+             (cmd (format "%s %s"
+                          etags-program-name
+                          (mapconcat #'shell-quote-argument
+                                     files " "))))
+        (with-current-buffer (reftex-get-file-buffer-force master)
+          (message "Running etags to create TAGS file...")
+          (shell-command cmd)
+          (visit-tags-table "TAGS"))))))
 
 ;; History of grep commands.
 (defvar reftex-grep-history nil)
@@ -144,7 +146,7 @@ reftex-find-duplicate-labels
                 (if (< 1 (length x1))
                     (append (list (car x))
                             (mapcar (lambda(x)
-                                      (abbreviate-file-name (nth 3 x)))
+                                      (reftex--abbreviate-name (nth 3 x)))
                                     x1))
                   (list nil))))))
           (reftex-uniquify-by-car (symbol-value reftex-docstruct-symbol)))))
@@ -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
@@ -464,7 +466,7 @@ reftex-isearch-switch-to-next-file
 	    (setq flist (last flist)))
 	(unless isearch-forward
 	  (setq flist (reverse flist)))
-	(while (not (string= (car flist) cb))
+	(while (not (equal (car flist) cb))
 	  (setq flist (cdr flist)))
 	(setq flist (cdr flist)))
       (when flist
diff --git a/lisp/textmodes/reftex-index.el b/lisp/textmodes/reftex-index.el
index db6ebb4caf8..1d18d6047b5 100644
--- a/lisp/textmodes/reftex-index.el
+++ b/lisp/textmodes/reftex-index.el
@@ -475,7 +475,7 @@ reftex-display-index
          (docstruct-symbol reftex-docstruct-symbol)
          (index-tag (or tag (reftex-index-select-tag)))
          (master (reftex-TeX-master-file))
-         (calling-file (buffer-file-name))
+         (calling-file (reftex--get-buffer-identifier))
          (restriction
           (or overriding-restriction
               (and (not redo)
@@ -531,7 +531,7 @@ reftex-display-index
 SPC=view TAB=goto RET=goto+hide [e]dit [q]uit [r]escan [f]ollow [?]Help
 ------------------------------------------------------------------------------
 "
-               index-tag (abbreviate-file-name master)
+               index-tag (reftex--abbreviate-name master)
                (if (eq (car (car reftex-index-restriction-data)) 'toc)
                    (nth 2 (car reftex-index-restriction-data))
                  reftex-index-restriction-indicator)))
@@ -1107,7 +1107,8 @@ reftex-index-change-entry
       (when (and (re-search-forward (reftex-everything-regexp) nil t)
                  (match-end 10)
                  (< (abs (- (match-beginning 10) beg)) (length new))
-                 (setq info (reftex-index-info-safe buffer-file-name)))
+                 (setq info (reftex-index-info-safe
+                             (reftex--get-buffer-identifier))))
         (setcdr data (cdr info))))
     (let ((buffer-read-only nil))
       (save-excursion
@@ -1281,14 +1282,16 @@ reftex-index-visit-phrases-buffer
   (interactive)
   (reftex-access-scan-info)
   (set-marker reftex-index-return-marker (point))
-  (let* ((master (reftex-TeX-master-file))
-         (name (concat (file-name-sans-extension master)
-                       reftex-index-phrase-file-extension)))
-    (find-file name)
-    (unless (eq major-mode 'reftex-index-phrases-mode)
-      (reftex-index-phrases-mode))
-    (if (= (buffer-size) 0)
-        (reftex-index-initialize-phrases-buffer master))))
+  (let ((master (reftex-TeX-master-file)))
+    (when (bufferp master)
+      (user-error "RefTeX phrases buffer requires a file buffer"))
+    (let ((name (concat (file-name-sans-extension master)
+                        reftex-index-phrase-file-extension)))
+      (find-file name)
+      (unless (eq major-mode 'reftex-index-phrases-mode)
+        (reftex-index-phrases-mode))
+      (if (= (buffer-size) 0)
+          (reftex-index-initialize-phrases-buffer master)))))
 
 (defun reftex-index-initialize-phrases-buffer (&optional master)
   "Initialize the phrases buffer by creating the header.
diff --git a/lisp/textmodes/reftex-parse.el b/lisp/textmodes/reftex-parse.el
index 7795c583076..3d1849f618d 100644
--- a/lisp/textmodes/reftex-parse.el
+++ b/lisp/textmodes/reftex-parse.el
@@ -74,10 +74,10 @@ reftex-do-parse
 
   (let* ((old-list (symbol-value reftex-docstruct-symbol))
          (master (reftex-TeX-master-file))
-         (true-master (file-truename master))
-         (master-dir (file-name-as-directory (file-name-directory master)))
-         (file (or file (buffer-file-name)))
-         (true-file (file-truename file))
+         (true-master (reftex--get-truename master))
+         (master-dir (file-name-as-directory (reftex--get-directory master)))
+         (file (or file (reftex--get-buffer-identifier)))
+         (true-file (reftex--get-truename file))
          (bibview-cache (assq 'bibview-cache old-list))
          (reftex--index-tags (cdr (assq 'index-tags old-list)))
          from-file appendix docstruct tmp)
@@ -88,7 +88,7 @@ reftex-do-parse
                          (member (list 'eof file) old-list))))
       ;; Scan whole document because no such file section exists
       (setq rescan 1))
-    (when (string= true-file true-master)
+    (when (equal true-file true-master)
       ;; Scan whole document because this file is the master
       (setq rescan 1))
 
@@ -186,7 +186,7 @@ reftex-all-document-files
 When RELATIVE is non-nil, give file names relative to directory
 of master file."
   (let* ((all (symbol-value reftex-docstruct-symbol))
-         (master-dir (file-name-directory (reftex-TeX-master-file)))
+         (master-dir (reftex--get-directory (reftex-TeX-master-file)))
          (re (concat "\\`" (regexp-quote master-dir)))
         file-list tmp file)
     (while (setq tmp (assoc 'bof all))
@@ -228,7 +228,7 @@ reftex-parse-from-file
                 (not (eq t reftex-keep-temporary-buffers)))))
 
         ;; Begin of file mark
-        (setq file (buffer-file-name))
+        (setq file (reftex--get-buffer-identifier))
         (push (list 'bof file) docstruct)
 
         (reftex-with-special-syntax
@@ -275,7 +275,8 @@ reftex-parse-from-file
                  (when (and toc-entry
                             (eq ;; Either both are t or both are nil.
                              (= (char-after bound) ?%)
-                             (string-suffix-p ".dtx" file)))
+                             (and (stringp file)
+                                  (string-suffix-p ".dtx" file))))
                    ;; It can happen that section info returns nil
                    (setq level (nth 5 toc-entry))
                    (setq highest-level (min highest-level level))
@@ -638,7 +639,8 @@ reftex-where-am-I
                ((not found)
                 ;; no match
                 (or
-                 (car (member (list 'bof (buffer-file-name)) docstruct))
+                 (car (member (list 'bof (reftex--get-buffer-identifier))
+                              docstruct))
                  (not (setq cnt 2))
                  (assq 'bof docstruct)  ;; for safety reasons
                  'corrupted))
@@ -649,15 +651,16 @@ reftex-where-am-I
                ((match-end 3)
                 ;; Section
                 (goto-char (1- (match-beginning 3)))
-                (let* ((list (member (list 'bof (buffer-file-name))
+                (let* ((buffile (reftex--get-buffer-identifier))
+                       (list (member (list 'bof buffile)
                                      docstruct))
-                       (endelt (car (member (list 'eof (buffer-file-name))
+                       (endelt (car (member (list 'eof buffile)
                                             list)))
                        rtn1)
                   (while (and list (not (eq endelt (car list))))
                     (if (and (eq (car (car list)) 'toc)
-                             (string= (buffer-file-name)
-                                      (nth 3 (car list))))
+                             (equal buffile
+                                    (nth 3 (car list))))
                         (cond
                          ((equal (point)
                                  (or (and (markerp (nth 4 (car list)))
@@ -685,10 +688,13 @@ reftex-where-am-I
                 (when reftex-support-index
                   (let* ((index-info (save-excursion
                                        (reftex-index-info-safe nil)))
-                         (list (member (list 'bof (buffer-file-name))
-                                       docstruct))
-                         (endelt (car (member (list 'eof (buffer-file-name))
-                                              list)))
+                         (list (member
+                                (list 'bof (reftex--get-buffer-identifier))
+                                docstruct))
+                         (endelt
+                          (car (member
+                                (list 'eof (reftex--get-buffer-identifier))
+                                list)))
                          dist last-dist last (n 0))
                     ;; Check all index entries with equal text
                     (while (and list (not (eq endelt (car list))))
@@ -758,12 +764,13 @@ reftex-notice-new
          (when (re-search-forward (reftex-everything-regexp) nil t)
            (cond
             ((match-end 1)
-             (push (reftex-label-info (reftex-match-string 1) buffer-file-name)
+             (push (reftex-label-info (reftex-match-string 1)
+                                  (reftex--get-buffer-identifier))
                    (cdr tail)))
 
             ((match-end 3)
              (setq star (= ?* (char-after (match-end 3)))
-                   entry (reftex-section-info (buffer-file-name))
+                   entry (reftex-section-info (reftex--get-buffer-identifier))
                    level (nth 5 entry))
              ;; Insert the section info
              (push entry (cdr tail))
@@ -795,7 +802,8 @@ reftex-notice-new
             ((match-end 10)
              ;; Index entry
              (and reftex-support-index
-                  (setq entry (reftex-index-info-safe buffer-file-name))
+                  (setq entry (reftex-index-info-safe
+                               (reftex--get-buffer-identifier)))
                   ;; FIXME: (add-to-list 'reftex--index-tags (nth 1 index-entry))
                   (push entry (cdr tail))))))))))
 
diff --git a/lisp/textmodes/reftex-ref.el b/lisp/textmodes/reftex-ref.el
index 30e9968a8e5..8aa34ec942a 100644
--- a/lisp/textmodes/reftex-ref.el
+++ b/lisp/textmodes/reftex-ref.el
@@ -73,8 +73,10 @@ 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 (if (bufferp file)
+                  file
+                (reftex-get-file-buffer-force
+                 file (not (eq t reftex-keep-temporary-buffers))))))
     (if (not buf)
         (list label typekey "" file comment "LOST LABEL.  RESCAN TO FIX.")
       (with-current-buffer buf
@@ -102,7 +104,7 @@ reftex-label-info
   (let* ((prefix (if (string-match "^[a-zA-Z0-9]+:" label)
                      (match-string 0 label)))
          (typekey (cdr (assoc prefix reftex-prefix-to-typekey-alist)))
-         (file (or file (buffer-file-name)))
+         (file (or file (reftex--get-buffer-identifier)))
          (trust reftex-trust-label-prefix)
          (in-comment (reftex-in-comment)))
     (if (and typekey
@@ -249,7 +251,7 @@ reftex-label
              (note (if (cdr here-I-am-info)
                        ""
                      "POSITION UNCERTAIN.  RESCAN TO FIX."))
-             (file (buffer-file-name))
+             (file (reftex--get-buffer-identifier))
              ;; (text nil)
              (tail (memq here-I-am (symbol-value reftex-docstruct-symbol))))
 
@@ -314,19 +316,21 @@ reftex-replace-prefix-escapes
               (save-match-data
                 (cond
                  ((equal letter "f")
-                  (file-name-base (buffer-file-name)))
+                  (file-name-base (reftex--get-buffer-identifier)))
                  ((equal letter "F")
-                  (let ((masterdir (file-name-directory (reftex-TeX-master-file)))
-                        (file (file-name-sans-extension (buffer-file-name))))
+                  (let ((masterdir (reftex--get-directory
+                                    (reftex-TeX-master-file)))
+                        (file (file-name-sans-extension
+                               (reftex--get-buffer-identifier))))
                     (if (string-match (concat "\\`" (regexp-quote masterdir))
                                       file)
                         (substring file (length masterdir))
                       file)))
                  ((equal letter "m")
-                  (file-name-base (reftex-TeX-master-file)))
+                  (reftex--get-basename (reftex-TeX-master-file)))
                  ((equal letter "M")
                   (file-name-nondirectory
-                   (substring (file-name-directory (reftex-TeX-master-file))
+                   (substring (reftex--get-directory (reftex-TeX-master-file))
                               0 -1)))
                  ((equal letter "u")
                   (or (user-login-name) ""))
@@ -536,7 +540,8 @@ reftex-offer-label-menu
   ;; Offer a menu with the appropriate labels.
   (let* ((buf (current-buffer))
          (xr-data (assq 'xr (symbol-value reftex-docstruct-symbol)))
-         (xr-alist (cons (cons "" (buffer-file-name)) (nth 1 xr-data)))
+         (xr-alist (cons (cons "" (reftex--get-buffer-identifier))
+                         (nth 1 xr-data)))
          (xr-index 0)
          (here-I-am (car (reftex-where-am-I)))
          (here-I-am1 here-I-am)
diff --git a/lisp/textmodes/reftex-sel.el b/lisp/textmodes/reftex-sel.el
index 1f1c74550a5..6e65ad4786c 100644
--- a/lisp/textmodes/reftex-sel.el
+++ b/lisp/textmodes/reftex-sel.el
@@ -234,7 +234,7 @@ reftex-insert-docstruct
             reftex-active-toc nil
             master-dir-re
             (concat "\\`" (regexp-quote
-                           (file-name-directory (reftex-TeX-master-file))))))
+                           (reftex--get-directory (reftex-TeX-master-file))))))
 
     (setq-local reftex-docstruct-symbol docstruct-symbol)
     (setq-local reftex-prefix
diff --git a/lisp/textmodes/reftex-toc.el b/lisp/textmodes/reftex-toc.el
index d8d09da5ed0..2e3be51c87c 100644
--- a/lisp/textmodes/reftex-toc.el
+++ b/lisp/textmodes/reftex-toc.el
@@ -184,14 +184,14 @@ reftex-toc
 
   (interactive)
 
-  (if (or (not (string= reftex-last-toc-master (reftex-TeX-master-file)))
+  (if (or (not (equal reftex-last-toc-master (reftex-TeX-master-file)))
           ;; FIXME: use (interactive "P") to receive current-prefix-arg as
           ;; an argument instead of using the var here, which forces us to set
           ;; current-prefix-arg in the callers.
           current-prefix-arg)
       (reftex-erase-buffer "*toc*"))
 
-  (setq reftex-last-toc-file   (buffer-file-name))
+  (setq reftex-last-toc-file   (reftex--get-buffer-identifier))
   (setq reftex-last-toc-master (reftex-TeX-master-file))
 
   (set-marker reftex-toc-return-marker (point))
@@ -211,7 +211,8 @@ reftex-toc
   (let* ((this-buf (current-buffer))
          (docstruct-symbol reftex-docstruct-symbol)
          (xr-data (assq 'xr (symbol-value reftex-docstruct-symbol)))
-         (xr-alist (cons (cons "" (buffer-file-name)) (nth 1 xr-data)))
+         (xr-alist (cons (cons "" (reftex--get-buffer-identifier))
+                         (nth 1 xr-data)))
          (here-I-am (if reftex--rebuilding-toc
                         (get 'reftex-toc :reftex-data)
                       (car (reftex-where-am-I))))
@@ -261,7 +262,7 @@ reftex-toc
 "TABLE-OF-CONTENTS on %s
 SPC=view TAB=goto RET=goto+hide [q]uit [r]escan [l]abels [f]ollow [x]r [?]Help
 ------------------------------------------------------------------------------
-" (abbreviate-file-name reftex-last-toc-master)))
+" (reftex--abbreviate-name reftex-last-toc-master)))
 
       (if reftex-use-fonts
           (put-text-property (point-min) (point) 'font-lock-face reftex-toc-header-face))
@@ -997,7 +998,7 @@ reftex-recenter-toc-when-idle
        (not (active-minibuffer-window))
        (fboundp 'reftex-toc-mode)
        (get-buffer-window "*toc*" 'visible)
-       (string= reftex-last-toc-master (reftex-TeX-master-file))
+       (equal reftex-last-toc-master (reftex-TeX-master-file))
        (let (current-prefix-arg)
          (reftex-toc-recenter))))
 
diff --git a/lisp/textmodes/reftex.el b/lisp/textmodes/reftex.el
index fda506a6d87..d72b1ba7315 100644
--- a/lisp/textmodes/reftex.el
+++ b/lisp/textmodes/reftex.el
@@ -251,6 +251,53 @@ LaTeX-label-function
 (defvar tex-main-file)
 (defvar outline-minor-mode)
 
+;;; =========================================================================
+;;;
+;;; Helper functions for handling both file names and buffer objects.
+;;;
+
+(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."
+  (let* ((buffer (or buffer (current-buffer)))
+         (buffer (or (buffer-base-buffer buffer) buffer)))
+    (or (buffer-local-value 'buffer-file-name buffer)
+        buffer)))
+
+(defun reftex--get-directory (file-or-buffer)
+  "Get the directory associated with FILE-OR-BUFFER.
+FILE-OR-BUFFER can be a file name or a buffer object."
+  (if (bufferp file-or-buffer)
+      (buffer-local-value 'default-directory file-or-buffer)
+    (file-name-directory file-or-buffer)))
+
+(defun reftex--abbreviate-name (file-or-buffer)
+  "Get a nice display name for FILE-OR-BUFFER.
+For files, returns the abbreviated file name.
+For buffers, returns the buffer name."
+  (if (bufferp file-or-buffer)
+      (prin1-to-string file-or-buffer)
+    (abbreviate-file-name file-or-buffer)))
+
+(defun reftex--get-basename (file-or-buffer)
+  "Get the base name (without extension) for FILE-OR-BUFFER.
+For file names, 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."
+  (if (bufferp file-or-buffer)
+      (file-name-base (buffer-name file-or-buffer))
+    (file-name-base file-or-buffer)))
+
+(defun reftex--get-truename (file-or-buffer)
+  "Get the canonical form of FILE-OR-BUFFER's identity.
+For files, returns the result of file-truename.
+For buffer objects, returns the buffer object itself."
+  (if (bufferp file-or-buffer)
+      file-or-buffer
+    (file-truename file-or-buffer)))
+
 ;;; =========================================================================
 ;;;
 ;;; Multibuffer Variables
@@ -279,10 +326,16 @@ reftex-next-multifile-index
   ;; Return the next free index for multifile symbols.
   (incf reftex-multifile-index))
 
+(defun reftex--remove-buffer-from-master-index ()
+  "Remove current buffer from `reftex-master-index-list'."
+  (setq reftex-master-index-list
+        (assq-delete-all (current-buffer) reftex-master-index-list)))
+
 (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)))
+  (let* ((master (reftex-TeX-master-file))
+         (master (reftex--get-truename master))
          (index (assoc master reftex-master-index-list))
          (symlist reftex-multifile-symbols)
          symbol symname newflag)
@@ -293,7 +346,11 @@ 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 index) reftex-master-index-list)
+      (when (bufferp master)
+        (with-current-buffer master
+          (add-hook 'kill-buffer-hook
+                    #'reftex--remove-buffer-from-master-index nil t))))
 
     ;; Get/create symbols and tie them.
     (while symlist
@@ -326,70 +383,73 @@ reftex-TeX-master-file
   ;; When AUCTeX is loaded, we will use it's more sophisticated method.
   ;; We also support the default TeX and LaTeX modes by checking for a
   ;; variable tex-main-file.
-  (let
-      ((master
-        (cond
-	 ;; Test if we're in a subfile using the subfiles document
-	 ;; class, e.g., \documentclass[main.tex]{subfiles}.  It's
-	 ;; argument is the main file, however it's not really the
-	 ;; master file in `TeX-master-file' or `tex-main-file's
-	 ;; sense.  It should be used for references but not for
-	 ;; compilation, thus subfiles use a setting of
-	 ;; `TeX-master'/`tex-main-file' being themselves.
-	 ((save-excursion
-            (goto-char (point-min))
-            (re-search-forward
-             "^[[:space:]]*\\\\documentclass\\[\\([^]]+\\)\\]{subfiles}"
-             nil t))
-          (match-string-no-properties 1))
-         ;; AUCTeX is loaded.  Use its mechanism.
-         ((fboundp 'TeX-master-file)
-          (condition-case nil
-              (TeX-master-file t)
-            (error (buffer-file-name))))
-         ;; Emacs LaTeX mode
-         ((fboundp 'tex-main-file) (tex-main-file))
-         ;; Check the `TeX-master' variable.
-         ((boundp 'TeX-master)
+  (with-current-buffer (or (buffer-base-buffer) (current-buffer))
+    (let
+        ;; Set master to a file name (possibly non-existent), or nil:
+        ((master
           (cond
-           ((eq TeX-master t)
-            (buffer-file-name))
-           ((eq TeX-master 'shared)
-            (setq TeX-master (read-file-name "Master file: "
-                                             nil nil t nil)))
-           (TeX-master)
+	   ;; Test if we're in a subfile using the subfiles document
+	   ;; class, e.g., \documentclass[main.tex]{subfiles}.  It's
+	   ;; argument is the main file, however it's not really the
+	   ;; master file in `TeX-master-file' or `tex-main-file's
+	   ;; sense.  It should be used for references but not for
+	   ;; compilation, thus subfiles use a setting of
+	   ;; `TeX-master'/`tex-main-file' being themselves.
+	   ((save-excursion
+              (goto-char (point-min))
+              (re-search-forward
+               "^[[:space:]]*\\\\documentclass\\[\\([^]]+\\)\\]{subfiles}"
+               nil t))
+            (match-string-no-properties 1))
+           ;; AUCTeX is loaded.  Use its mechanism.
+           ((fboundp 'TeX-master-file)
+            (condition-case nil
+                (TeX-master-file t)
+              (error (buffer-file-name))))
+           ;; Emacs LaTeX mode
+           ((fboundp 'tex-main-file) (tex-main-file))
+           ;; Check the `TeX-master' variable.
+           ((boundp 'TeX-master)
+            (cond
+             ((eq TeX-master t)
+              (buffer-file-name))
+             ((eq TeX-master 'shared)
+              (setq TeX-master (read-file-name "Master file: "
+                                               nil nil t nil)))
+             (TeX-master)
+             (t
+              (setq TeX-master (read-file-name "Master file: "
+                                               nil nil t nil)))))
+           ;; Check the `tex-main-file' variable.
+           ((boundp 'tex-main-file)
+            ;; This is the variable from the default TeX modes.
+            (cond
+             ((stringp tex-main-file)
+              ;; ok, this must be it
+              tex-main-file)
+             (t
+              ;; In this case, the buffer is its own master.
+              (buffer-file-name))))
+           ;; We know nothing about master file.  Assume this is a
+           ;; master file.
            (t
-            (setq TeX-master (read-file-name "Master file: "
-                                             nil nil t nil)))))
-         ;; Check the `tex-main-file' variable.
-         ((boundp 'tex-main-file)
-          ;; This is the variable from the default TeX modes.
-          (cond
-           ((stringp tex-main-file)
-            ;; ok, this must be it
-            tex-main-file)
-           (t
-            ;; In this case, the buffer is its own master.
-            (buffer-file-name))))
-         ;; We know nothing about master file.  Assume this is a
-         ;; master file.
-         (t
-          (buffer-file-name)))))
-    (cond
-     ((null master)
-      (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...
-      (setq master (concat master ".tex")))
-     ((or (file-exists-p master)
-          (find-buffer-visiting master))
-      ;; We either see the file, or have a buffer on it.  OK.
-      )
-     (t
-      ;; Use buffer file name.
-      (setq master (buffer-file-name))))
-    (expand-file-name master)))
+            (buffer-file-name)))))
+      (cond
+       ((null master))
+       ((or (file-exists-p (concat master ".tex"))
+            (find-buffer-visiting (concat master ".tex")))
+        ;; Ahh, an extra .tex was missing...
+        (setq master (concat master ".tex")))
+       ((or (file-exists-p master)
+            (find-buffer-visiting master))
+        ;; We either see the file, or have a buffer on it.  OK.
+        )
+       (t
+        ;; Use buffer file name.
+        (setq master (buffer-file-name))))
+      (if master
+          (expand-file-name master)
+        (current-buffer)))))
 
 (defun reftex-is-multi ()
   ;; Tell if this is a multifile document.  When not sure, say yes.
@@ -712,7 +772,7 @@ reftex-reset-mode
 (defun reftex-reset-scanning-information ()
   "Reset the symbols containing information from buffer scanning.
 This enforces rescanning the buffer on next use."
-  (if (string= reftex-last-toc-master (reftex-TeX-master-file))
+  (if (equal reftex-last-toc-master (reftex-TeX-master-file))
       (reftex-erase-buffer "*toc*"))
   (let ((symlist reftex-multifile-symbols)
         symbol)
@@ -1105,11 +1165,6 @@ reftex-access-scan-info
   ;; But, when RESCAN is -1, don't rescan even if docstruct is empty.
   ;; When FILE is non-nil, parse only from that file.
 
-  ;; Error out in a buffer without a file.
-  (if (and reftex-mode
-	   (not (buffer-file-name)))
-      (error "RefTeX works only in buffers visiting a file"))
-
   ;; Make sure we have the symbols tied
   (if (eq reftex-docstruct-symbol nil)
       ;; Symbols are not yet tied: Tie them.
@@ -1157,16 +1212,26 @@ reftex-silence-toc-markers
 
 (defun reftex-access-parse-file (action)
   "Perform ACTION on the parse file (the .rel file).
-Valid actions are: readable, restore, read, kill, write."
+Valid actions are: readable, restore, read, kill, write.
+For non-file buffers, persistence operations are skipped."
   (let* ((list (symbol-value reftex-docstruct-symbol))
          (docstruct-symbol reftex-docstruct-symbol)
          (master (reftex-TeX-master-file))
          (enable-local-variables nil)
-         (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))))
+         (non-file (bufferp master))
+         (file (if non-file
+                   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)))))
     (cond
+     ;; For non-file buffers, skip file operations but allow initialization.
+     (non-file (cond ((eq action 'readable) nil)
+                     ((eq action 'read) nil)
+                     ((eq action 'kill) t)
+                     ((eq action 'restore)
+                      (error "Cannot restore for non-file buffer"))))
      ((eq action 'readable)
       (file-readable-p file))
      ((eq action 'restore)
@@ -1240,7 +1305,9 @@ 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))
+    ;; Skip this check for buffer objects.
+    (unless (equal (reftex--get-truename real-master)
+                   (reftex--get-truename parsed-master))
       (message "Master file name in load file is different: %s versus %s"
                parsed-master real-master)
       (error "Master file name error")))
@@ -1281,7 +1348,7 @@ reftex-select-external-document
                   (mapconcat
                    (lambda (x)
                      (format fmt (incf n) (or (car x) "")
-                             (abbreviate-file-name (cdr x))))
+                             (reftex--abbreviate-name (cdr x))))
                    xr-alist ""))
                  nil t))
           (cond
@@ -1299,8 +1366,11 @@ reftex-locate-file
   "Find FILE of type TYPE in MASTER-DIR or on the path associated with TYPE.
 If the file does not have any of the valid extensions for TYPE,
 try first the default extension and only then the naked file name.
-When DIE is non-nil, throw an error if file not found."
-  (let* ((rec-values (if reftex-search-unrecursed-path-first '(nil t) '(t)))
+When DIE is non-nil, throw an error if file not found.
+When FILE is a buffer object, return that buffer."
+  (if (bufferp file)
+      file
+    (let* ((rec-values (if reftex-search-unrecursed-path-first '(nil t) '(t)))
          (extensions (cdr (assoc type reftex-file-extensions)))
          (def-ext (car extensions))
          (ext-re (concat "\\("
@@ -1335,7 +1405,7 @@ reftex-locate-file
 	    (setq file1 (reftex-find-file-on-path f path master-dir)))))))
     (cond (file1 file1)
           (die (error "No such file: %s" file) nil)
-          (t (message "No such file: %s (ignored)" file) nil))))
+          (t (message "No such file: %s (ignored)" file) nil)))))
 
 (defun reftex-find-file-externally (file type &optional master-dir)
   ;; Use external program to find FILE.
@@ -1742,7 +1812,9 @@ reftex-get-file-buffer-force
   ;; initializations according to `reftex-initialize-temporary-buffers',
   ;; and mark the buffer to be killed after use.
 
-  (let ((buf (find-buffer-visiting file)))
+  (let ((buf (if (bufferp file)
+                 file
+               (find-buffer-visiting file))))
 
     (cond (buf
            ;; We have it already as a buffer - just return it
-- 
2.39.3 (Apple Git-145)


--=-=-=--




Information forwarded to bug-auctex@HIDDEN:
bug#76615; Package auctex. Full text available.

Message received at 76615 <at> debbugs.gnu.org:


Received: (at 76615) by debbugs.gnu.org; 3 Apr 2025 18:27:58 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Apr 03 14:27:58 2025
Received: from localhost ([127.0.0.1]:35638 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1u0PID-0002j9-MF
	for submit <at> debbugs.gnu.org; Thu, 03 Apr 2025 14:27:58 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:60732)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <arash@HIDDEN>) id 1u0PIA-0002is-Do
 for 76615 <at> debbugs.gnu.org; Thu, 03 Apr 2025 14:27:55 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <arash@HIDDEN>)
 id 1u0PI2-0003St-Eo; Thu, 03 Apr 2025 14:27:46 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To:
 From; bh=UqFz+dBsaJQl5ugOtNRQ5tgh4QsvFmIJoIJZlsrAB7I=; b=HGURhIZjZRG6s266POu3
 aGIexFjRPfWPQEy5LGkCWKfVWUxjp5kXQ9ORTSRfPg1YgJQVyebeUdvI50kSIdwes/T/lseMoZrTA
 jSC8L0POf+uJif3cK9V0Yo2qaeYTGaBnfKN5rGMVAOY4qBvfSEpLLPyTEKMpE/+bTkuWX610PmDb/
 GJSTh/dpmM6Zo7xZm3uRwgUz9Uuup3Ad2Vp0yu7YagsDj5U2tqwS71Dw71PWSyAyOB64bjobzS3w4
 aIXmPl+voiGFNhq0R/7+zucRczzKN8LAR9sNVZQqZPgB0t+OEdVJPcHc+ABrevLZc3TA+yeYoVf51
 9CEWbhaBQOUl0w==;
From: Arash Esbati <arash@HIDDEN>
To: "Paul D. Nelson" <ultrono@HIDDEN>, carsten.dominik@HIDDEN
Subject: Re: bug#76615: 14.0.9; error with amsmath style hooks
In-Reply-To: <uxsg7t4iz5pzt7.fsf@HIDDEN>
References: <uxsg7t4iz5pzt7.fsf@HIDDEN>
Date: Thu, 03 Apr 2025 20:27:42 +0200
Message-ID: <m24iz5t80x.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76615
Cc: ikumi@HIDDEN, Stefan Monnier <monnier@HIDDEN>,
 76615 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

"Paul D. Nelson" <ultrono@HIDDEN> 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@HIDDEN:
bug#76615; Package auctex. Full text available.

Message received at 76615 <at> debbugs.gnu.org:


Received: (at 76615) by debbugs.gnu.org; 3 Apr 2025 13:55:57 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Apr 03 09:55:57 2025
Received: from localhost ([127.0.0.1]:34323 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1u0L2y-0006Ff-Vp
	for submit <at> debbugs.gnu.org; Thu, 03 Apr 2025 09:55:57 -0400
Received: from mail-ej1-x632.google.com ([2a00:1450:4864:20::632]:43296)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <ultrono@HIDDEN>) id 1u0L2w-0006Cj-0k
 for 76615 <at> debbugs.gnu.org; Thu, 03 Apr 2025 09:55:54 -0400
Received: by mail-ej1-x632.google.com with SMTP id
 a640c23a62f3a-ac7bd86f637so124277566b.1
 for <76615 <at> debbugs.gnu.org>; Thu, 03 Apr 2025 06:55:53 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1743688548; x=1744293348; darn=debbugs.gnu.org;
 h=mime-version:message-id:date:in-reply-to:subject:cc:to:from:from:to
 :cc:subject:date:message-id:reply-to;
 bh=OemTdsjYhpxB0O0hCjz6HIFIH3GYM7Vwzxd9VqP5eHY=;
 b=W31lPlq+TYKuy61zo0om1GGU7hIMDC0yl9DmXgPc+fzMJPBzsAxDpa48EUrhJ+szDe
 xIye1h7ZxiXdUuDW74uzwn0hcqWOoF+KppdHh2J7HTsVHip+RAlKsK9OzQUgsp+DW3E1
 bHw6r+WqBQ2s1T5vL3/SozyrkFhMTcbVZZv/a+Y8CIqIFskZxvhD5uaXU/Wb8YnE3FL9
 082f9hQE5VZRPbUsgJvu2ldJt/Vde/liquy1/sfBDUZ10x0X5oGR/geAMQ+xfzkb4Ws7
 cMoJFe1E2n6OJIl5YHWxKy+CjwKr8rWYq4u2b7eCNwfHyC7EdhrIlNAxGMF8KW8Zv771
 Duxw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1743688548; x=1744293348;
 h=mime-version:message-id:date:in-reply-to:subject:cc:to:from
 :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
 bh=OemTdsjYhpxB0O0hCjz6HIFIH3GYM7Vwzxd9VqP5eHY=;
 b=AgGHFCq0eUyLw9PCbli7nSnVkRskzCMvXxS/4SBF0YR2EMjZMTdkEqbH82k3IWLTMa
 cDB4OtE/6xPRwLHQ1VCBh+ZsHPhf9NU5BiPJJkMHyl0BUtVq/aUwwOJ+Ps6l4cpw2sqY
 ZyH6uKm/mhDivsxCvUpsMJPeMxnsuSU8VJBcWHOsWhyhxjnPbjGYDNloyU0Imv5Qx3p4
 ywzAe2fG9Zu5a9pkZ7rkningatoZ/PuAT+155MGmLspjuy3ADxGsvplHKG9raGQf6pYH
 uk8tkWlmZnywn65RdLXVno9PvoB14gryukUhmNxLymIbdmX34CTnaCsUQ7KaTj5WonOm
 UNag==
X-Forwarded-Encrypted: i=1;
 AJvYcCXlaeYQCesGEC621DPvC/KeivMqHOsJP69iwsaNKJ+2fxPYdG/WT7PJpeiHhRkMZFhbf+BeAg==@debbugs.gnu.org
X-Gm-Message-State: AOJu0Yxrtmq7EIhiyZA5spIjN7T4eR/OfZeL5pud4zPTmUeTXoTeErVC
 BouXOa0uDieHNGf3aQ/7iVLL5ktqCOMmbGottGo5OzWjZLWkBrAm
X-Gm-Gg: ASbGncuSm+swgFG8jdUA17+rBmVWzmHPBC/o9NQSyrA1OZFKOPJr3cyrud0fxgodl88
 qr4qigBI3ldwVWC6sU/EhD7LVVOJ9XIgbOCHTbQ8hkXg/EnnLHxga8ZU3RqktYtPgmdwX0RM2nS
 ulU7rUGjDqcHxM4YYbEKCd0MUSzgQb+ufiVGuEC1rqccPqd3Fm56+vc5/O5GDBTf6Xeg90MoVh1
 qNrZ5HOd9AM3MBqjcaOanhIsnZQ2lpXkqlS97DOMfWD1bQOUTyUMtK/FnDSIbBhtC5svhDDoDXl
 76xmZemrzY3VmriUGy3BYJPaGGVMK+mKmjfHPwHE0nsLRrd0k1e+c1AANxxvXaFI1Cs7xLkbm0y
 hdQBNM+dqOQ==
X-Google-Smtp-Source: AGHT+IH9mcA5aI3WNS1QCr18PFp//zqk8fZoP1KBhLEvSkvC5bo4QOhepnz43gjJe1FyjJrnQ+iRbA==
X-Received: by 2002:a17:906:f583:b0:ac7:7f1d:f268 with SMTP id
 a640c23a62f3a-ac7b6fa2f0fmr334482266b.28.1743688547157; 
 Thu, 03 Apr 2025 06:55:47 -0700 (PDT)
Received: from localhost (0x573d6713.static.cust.fastspeed.dk. [87.61.103.19])
 by smtp.gmail.com with UTF8SMTPSA id
 a640c23a62f3a-ac7c01c10dcsm96788566b.180.2025.04.03.06.55.46
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Thu, 03 Apr 2025 06:55:46 -0700 (PDT)
From: "Paul D. Nelson" <ultrono@HIDDEN>
To: Stefan Monnier <monnier@HIDDEN>
Subject: Re: bug#76615: 14.0.9; error with amsmath style hooks
In-Reply-To: <jwv5xjl4cas.fsf-monnier+emacs@HIDDEN> (message from Stefan
 Monnier on Thu, 03 Apr 2025 09:50:04 -0400)
Date: Thu, 03 Apr 2025 15:55:45 +0200
Message-ID: <uxsg7t1pu9pcwu.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 76615
Cc: ikumi@HIDDEN, arash@HIDDEN, 76615 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

> 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@HIDDEN:
bug#76615; Package auctex. Full text available.

Message received at 76615 <at> debbugs.gnu.org:


Received: (at 76615) by debbugs.gnu.org; 3 Apr 2025 13:50:18 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Apr 03 09:50:18 2025
Received: from localhost ([127.0.0.1]:33392 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1u0KxV-0005ly-N2
	for submit <at> debbugs.gnu.org; Thu, 03 Apr 2025 09:50:18 -0400
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:49179)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <monnier@HIDDEN>)
 id 1u0KxR-0005gO-Sa
 for 76615 <at> debbugs.gnu.org; Thu, 03 Apr 2025 09:50:14 -0400
Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 7B58B10006B;
 Thu,  3 Apr 2025 09:50:07 -0400 (EDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1743688206;
 bh=VcGNjaO7W/pXTg9L1bHalvWRcFDnDlxajDKgCw6rXq4=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=oDM0fwJ023goEGEnThznC8otVZmj6J2uMVVA0Wu/2NQSWQCAuOObGwU3An1lfF/MG
 +9q7AfOUCiX7SRD+p+OxfJvkMq6q/omjrnzZnsgX4k2DmJzE49Pi5tKSFIYZLxgWLt
 apI1jGaQkuxiKHLgZqeRJm24hEd3B0d+qwS3yrym/I1ed6iXerxuJdbkAJ1VIKwYM1
 mC3bNGYXeM/qIUXqidcAx+tGy+70BEd6BnJ0tiYevlame6G7vj1fL0owgXJDc0LXkY
 W0TJngMMN80jmMmfNPdPGSZJx4Bj2etR+weOv5Mrr2y6AjyMdh6EzHNzMHlqCjeWrT
 fN+ppGwEVeCqQ==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 66583100027;
 Thu,  3 Apr 2025 09:50:06 -0400 (EDT)
Received: from pastel (unknown [104.247.242.5])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 19EE1120205;
 Thu,  3 Apr 2025 09:50:06 -0400 (EDT)
From: Stefan Monnier <monnier@HIDDEN>
To: "Paul D. Nelson" <ultrono@HIDDEN>
Subject: Re: bug#76615: 14.0.9; error with amsmath style hooks
In-Reply-To: <uxsg7t4iz5pzt7.fsf@HIDDEN>
Message-ID: <jwv5xjl4cas.fsf-monnier+emacs@HIDDEN>
References: <uxsg7t4iz5pzt7.fsf@HIDDEN>
Date: Thu, 03 Apr 2025 09:50:04 -0400
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL -0.361 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain
X-SPAM-LEVEL: 
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76615
Cc: ikumi@HIDDEN, arash@HIDDEN, 76615 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> 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-m=
aster 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.

> +;;; =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D
> +;;;
> +;;; 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-b=
uffer))
> +    (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 =F0=9F=99=82).

> +      (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=3D (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 pa=
rse info
> +    (when (and (stringp real-master) (stringp parsed-master))
> +      (unless (string=3D (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@HIDDEN:
bug#76615; Package auctex. Full text available.

Message received at 76615 <at> debbugs.gnu.org:


Received: (at 76615) by debbugs.gnu.org; 3 Apr 2025 10:43:16 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Apr 03 06:43:16 2025
Received: from localhost ([127.0.0.1]:32956 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1u0I2W-0004y9-9v
	for submit <at> debbugs.gnu.org; Thu, 03 Apr 2025 06:43:16 -0400
Received: from smtp1a.inetd.co.jp ([210.129.88.11]:42432)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <ikumi@HIDDEN>)
 id 1u0I2T-0004xu-HZ
 for 76615 <at> debbugs.gnu.org; Thu, 03 Apr 2025 06:43:14 -0400
Received: from localhost (42-144-34-247.rev.home.ne.jp [42.144.34.247])
 by smtp1a.inetd.co.jp (Postfix) with ESMTPSA id 5E2745F;
 Thu,  3 Apr 2025 19:43:10 +0900 (JST)
From: Ikumi Keita <ikumi@HIDDEN>
To: Stefan Monnier <monnier@HIDDEN>,
 "Paul D. Nelson" <ultrono@HIDDEN>
Subject: Re: bug#76615: 14.0.9; error with amsmath style hooks
In-reply-to: <uxsg7t4iz5pzt7.fsf@HIDDEN>
References: <uxsg7t4iz5pzt7.fsf@HIDDEN>
Comments: In-reply-to "Paul D. Nelson" <ultrono@HIDDEN>
 message dated "Thu, 03 Apr 2025 07:41:08 +0200."
X-Mailer: MH-E 8.6+git; nmh 1.8; Emacs 30.1
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-ID: <4398.1743676990.1@localhost>
Date: Thu, 03 Apr 2025 19:43:10 +0900
Message-ID: <4401.1743676990@localhost>
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 76615
Cc: arash@HIDDEN, 76615 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Hi Paul and Stefan,

>>>>> "Paul D. Nelson" <ultrono@HIDDEN> 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@HIDDEN:
bug#76615; Package auctex. Full text available.

Message received at 76615 <at> debbugs.gnu.org:


Received: (at 76615) by debbugs.gnu.org; 3 Apr 2025 05:41:24 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Apr 03 01:41:24 2025
Received: from localhost ([127.0.0.1]:60476 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1u0DKM-0001rg-3P
	for submit <at> debbugs.gnu.org; Thu, 03 Apr 2025 01:41:24 -0400
Received: from mail-ed1-x52b.google.com ([2a00:1450:4864:20::52b]:53744)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <ultrono@HIDDEN>) id 1u0DKH-0001rQ-Ry
 for 76615 <at> debbugs.gnu.org; Thu, 03 Apr 2025 01:41:20 -0400
Received: by mail-ed1-x52b.google.com with SMTP id
 4fb4d7f45d1cf-5ed1ac116e3so906011a12.3
 for <76615 <at> debbugs.gnu.org>; Wed, 02 Apr 2025 22:41:17 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1743658872; x=1744263672; darn=debbugs.gnu.org;
 h=mime-version:message-id:date:in-reply-to:subject:cc:to:from:from:to
 :cc:subject:date:message-id:reply-to;
 bh=veVGwtAphZwMd1Ykg6+e9zxmSrcx6SVFGom0pJFL3kQ=;
 b=QFdknbQGogbfbJXOjMP21c9xEVUUFhiQq6KrQMgdM0dt0S4/8qv8W/9pfIySJ+Ak4b
 qJsBOiCpoaWDDE1dCBCe32mdTNCKBLnJ9bXcA3sGCf9HSUrqnEJ51LyrC91hkJeoJUTS
 F9YASMksUHeGD/9j3wITMC3a9rWo3EbbuDj37EFsg4otf7D2FPjYuflGOpI5XgNhCVdY
 jPJ9plut/wPuD8OSzsmar30RH2BhHwJqgNr4QVDrcjBP4F+mzmHX4A4uGsPOvVCsqTKS
 uqANKRzwJ/JclFwKB3CI5PLdSPl07TDwNNz4oXGpyn2m/8wj6+U2uG3TDvXBwyi4RHf0
 RASg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1743658872; x=1744263672;
 h=mime-version:message-id:date:in-reply-to:subject:cc:to:from
 :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
 bh=veVGwtAphZwMd1Ykg6+e9zxmSrcx6SVFGom0pJFL3kQ=;
 b=m6kFOXhh5I28mtpUGp16VNhv5OzYnBH4z25VSND4JtlttzCcyyt1md5zCXzzq9EaUx
 SPr6/jdZkSaNmJn8Unm+a4hxr6VY1nwM9bQOBhXnRv4U0N43XByZXXtjKOc2L5YQfsKs
 ojwruKhMgkj5b0XRahd3fz/4UjDM4Bt/2DTp5ho60Oxu/FkRNrW0xOOEQZZ9lCV/A8kK
 1+sk0qtr1fQGJ461JJy3BTDwMN+xVrrL5OjMDkG1Vc3OQYV5HSAwIGTKKE8GY/eYtOav
 CKSBtjF6Zb9dFf9zMpdvnnzslL2QmnjTfheB5P3lqZFRjDewDtpqwqmtaGcMmwf0Asi2
 paAA==
X-Forwarded-Encrypted: i=1;
 AJvYcCWpRCh1Y6oEjQQNBSCBuONyV5wpiERjEQo6ZC2tzDlAPA3uztBPXniq0ei61dgD5eCMlatLyw==@debbugs.gnu.org
X-Gm-Message-State: AOJu0YwH71QB4LNQkEHyV+JJ8JPOHnNHjMTHtIqASk7TfJaBlGisjeUH
 VjX6DA7rmBQrIyXJP1NEc78hXr8h2ccwXFgovuUCrmrQoA1y4HLM
X-Gm-Gg: ASbGncuC6ILjHh1Ooviwqpks+1QKXaYPc78BnxRqynP5TfhhjVnPl123gwJshXdhXW6
 RhYVCTgiRY4oz6jgJB+1RUPGguRHOqicP5lg3aaJlEYXlYJ1yBsPmJ5GBvjmwZfhMSM5k0uHmZ3
 r9QJaubQXUjSVUbnRwl+i5V3tOIvDH2Zle4AU0NYV7FGyxLLGjq3JTtyvp8oCf5yjm0449UO3rs
 6v2KJT18CrQZD6CRWBl01ia1sItOabsrzc0p/i2w1bDTBISdMO6VcQeDoK5tK27N1+5n/AuYZGm
 GQpx+5Z/dmCAZBJGBIjOj4qGkl2Lzk8XAR3ZdQRipk0XPvTQeRbEekFf3Zx9xf0LvW1wBEd3iZ2
 eCInFbvZTBA==
X-Google-Smtp-Source: AGHT+IEXnJxxWVlIRKf9Cf62KEVjivdGRQb77KYxsSmLWlFthGIsgrqj6V9NKBlbUdtCMvp00clPDA==
X-Received: by 2002:a05:6402:4404:b0:5df:6a:54ea with SMTP id
 4fb4d7f45d1cf-5f08716b758mr975196a12.11.1743658871213; 
 Wed, 02 Apr 2025 22:41:11 -0700 (PDT)
Received: from localhost (0x573d6713.static.cust.fastspeed.dk. [87.61.103.19])
 by smtp.gmail.com with UTF8SMTPSA id
 4fb4d7f45d1cf-5f0880a4054sm418631a12.67.2025.04.02.22.41.09
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Wed, 02 Apr 2025 22:41:09 -0700 (PDT)
From: "Paul D. Nelson" <ultrono@HIDDEN>
To: Stefan Monnier <monnier@HIDDEN>
Subject: Re: bug#76615: 14.0.9; error with amsmath style hooks
In-Reply-To: <jwvy0wixn84.fsf-monnier+emacs@HIDDEN> (message from Stefan
 Monnier on Wed, 02 Apr 2025 18:13:33 -0400)
Date: Thu, 03 Apr 2025 07:41:08 +0200
Message-ID: <uxsg7t4iz5pzt7.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 76615
Cc: ikumi@HIDDEN, arash@HIDDEN, 76615 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

--=-=-=
Content-Type: text/plain

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


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=0001-Add-RefTeX-support-for-non-file-buffers.patch

From d921b6fd64bb93387c42ff133a0f185624a096e1 Mon Sep 17 00:00:00 2001
From: Paul Nelson <ultrono@HIDDEN>
Date: Wed, 2 Apr 2025 21:38:48 +0200
Subject: [PATCH] Add RefTeX support for non-file buffers

* lisp/textmodes/reftex.el (reftex-get-buffer-identifier)
(reftex-get-buffer-for-master, reftex-get-directory-for-master)
(reftex-file-or-buffer-name, reftex-abbreviate-or-get-name)
(reftex-get-basename-for-master, reftex-get-truename-for-master):
New helper functions that handle both files and buffer objects.
(reftex-tie-multifile-symbols): Support non-file buffers.
(reftex-TeX-master-file): Return current buffer when no file.
(reftex-access-scan-info): Remove check requiring file buffers.
(reftex-access-parse-file, reftex-check-parse-consistency): Skip
for non-file buffers.
(reftex-select-external-document): Use new helper function.
(reftex-locate-file): Return buffer objects directly.
(reftex-get-file-buffer-force): Handle buffer objects and
special 'buffer:' strings.
* lisp/textmodes/reftex-global.el (reftex-create-tags-file): Add
error handling for non-file buffers.  We leave TAGS unsupported
in non-file buffers.
(reftex-find-duplicate-labels)
(reftex-isearch-switch-to-next-file): Use new helper functions
that handle both files and buffer objects.
* lisp/textmodes/reftex-index.el (reftex-display-index): Use new
helper functions.
(reftex-index-visit-phrases-buffer): Add error handling for
non-file buffers.  We leave phrases unsupported in non-file
buffers.
* lisp/textmodes/reftex-parse.el (reftex-do-parse): Add support
for non-file buffers.
(reftex-all-document-files, reftex-where-am-I)
(reftex-notice-new): Use new helper functions.
* lisp/textmodes/reftex-ref.el (reftex-label-info-update):
Support non-file buffers.
(reftex-label-info, reftex-replace-prefix-escapes, reftex-label)
(reftex-replace-prefix-escapes, reftex-offer-label-menu): Use new
helper functions.
* lisp/textmodes/reftex-sel.el (reftex-insert-docstruct): Use
new helper function.
* lisp/textmodes/reftex-toc.el (reftex-toc)
(reftex-recenter-toc-when-idle): Support non-file buffers.

RefTeX historically assumed that the buffers it operates on
visit files.  For non-file buffers, we follow Stefan Monnier's
suggestion of modifying reftex-TeX-master-file so that it
returns the buffer object itself.  We then modify each caller to
handle buffer objects, aided by some helper functions added to
reftex.el.
---
 lisp/textmodes/reftex-global.el |  20 +-
 lisp/textmodes/reftex-index.el  |  20 +-
 lisp/textmodes/reftex-parse.el  |  26 +-
 lisp/textmodes/reftex-ref.el    |  22 +-
 lisp/textmodes/reftex-sel.el    |   2 +-
 lisp/textmodes/reftex-toc.el    |  10 +-
 lisp/textmodes/reftex.el        | 464 +++++++++++++++++++-------------
 7 files changed, 332 insertions(+), 232 deletions(-)

diff --git a/lisp/textmodes/reftex-global.el b/lisp/textmodes/reftex-global.el
index 20abd36192d..d706d3e9fd2 100644
--- a/lisp/textmodes/reftex-global.el
+++ b/lisp/textmodes/reftex-global.el
@@ -38,15 +38,17 @@ reftex-create-tags-file
   (interactive)
   (reftex-access-scan-info current-prefix-arg)
   (let* ((master (reftex-TeX-master-file))
-         (files  (reftex-all-document-files))
-         (cmd    (format "%s %s"
+         (files  (reftex-all-document-files)))
+    (if (bufferp master)
+        (user-error "Cannot create TAGS file for non-file buffers")
+      (let ((cmd (format "%s %s"
                          etags-program-name
                          (mapconcat #'shell-quote-argument
-				    files " "))))
-    (with-current-buffer (reftex-get-file-buffer-force master)
-      (message "Running etags to create TAGS file...")
-      (shell-command cmd)
-      (visit-tags-table "TAGS"))))
+                                    files " "))))
+        (with-current-buffer (reftex-get-file-buffer-force master)
+          (message "Running etags to create TAGS file...")
+          (shell-command cmd)
+          (visit-tags-table "TAGS"))))))
 
 ;; History of grep commands.
 (defvar reftex-grep-history nil)
@@ -144,7 +146,7 @@ reftex-find-duplicate-labels
                 (if (< 1 (length x1))
                     (append (list (car x))
                             (mapcar (lambda(x)
-                                      (abbreviate-file-name (nth 3 x)))
+                                      (reftex-abbreviate-or-get-name (nth 3 x)))
                                     x1))
                   (list nil))))))
           (reftex-uniquify-by-car (symbol-value reftex-docstruct-symbol)))))
@@ -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
diff --git a/lisp/textmodes/reftex-index.el b/lisp/textmodes/reftex-index.el
index db6ebb4caf8..47a389500f1 100644
--- a/lisp/textmodes/reftex-index.el
+++ b/lisp/textmodes/reftex-index.el
@@ -531,7 +531,7 @@ reftex-display-index
 SPC=view TAB=goto RET=goto+hide [e]dit [q]uit [r]escan [f]ollow [?]Help
 ------------------------------------------------------------------------------
 "
-               index-tag (abbreviate-file-name master)
+               index-tag (reftex-abbreviate-or-get-name master)
                (if (eq (car (car reftex-index-restriction-data)) 'toc)
                    (nth 2 (car reftex-index-restriction-data))
                  reftex-index-restriction-indicator)))
@@ -1281,14 +1281,16 @@ reftex-index-visit-phrases-buffer
   (interactive)
   (reftex-access-scan-info)
   (set-marker reftex-index-return-marker (point))
-  (let* ((master (reftex-TeX-master-file))
-         (name (concat (file-name-sans-extension master)
-                       reftex-index-phrase-file-extension)))
-    (find-file name)
-    (unless (eq major-mode 'reftex-index-phrases-mode)
-      (reftex-index-phrases-mode))
-    (if (= (buffer-size) 0)
-        (reftex-index-initialize-phrases-buffer master))))
+  (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"))
+    (let ((name (concat (file-name-sans-extension master)
+                        reftex-index-phrase-file-extension)))
+      (find-file name)
+      (unless (eq major-mode 'reftex-index-phrases-mode)
+        (reftex-index-phrases-mode))
+      (if (= (buffer-size) 0)
+          (reftex-index-initialize-phrases-buffer master)))))
 
 (defun reftex-index-initialize-phrases-buffer (&optional master)
   "Initialize the phrases buffer by creating the header.
diff --git a/lisp/textmodes/reftex-parse.el b/lisp/textmodes/reftex-parse.el
index 7795c583076..f089536c40a 100644
--- a/lisp/textmodes/reftex-parse.el
+++ b/lisp/textmodes/reftex-parse.el
@@ -74,10 +74,10 @@ reftex-do-parse
 
   (let* ((old-list (symbol-value reftex-docstruct-symbol))
          (master (reftex-TeX-master-file))
-         (true-master (file-truename master))
-         (master-dir (file-name-as-directory (file-name-directory master)))
-         (file (or file (buffer-file-name)))
-         (true-file (file-truename file))
+         (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)))
          (bibview-cache (assq 'bibview-cache old-list))
          (reftex--index-tags (cdr (assq 'index-tags old-list)))
          from-file appendix docstruct tmp)
@@ -88,7 +88,7 @@ reftex-do-parse
                          (member (list 'eof file) old-list))))
       ;; Scan whole document because no such file section exists
       (setq rescan 1))
-    (when (string= true-file true-master)
+    (when (equal true-file true-master)
       ;; Scan whole document because this file is the master
       (setq rescan 1))
 
@@ -186,7 +186,7 @@ reftex-all-document-files
 When RELATIVE is non-nil, give file names relative to directory
 of master file."
   (let* ((all (symbol-value reftex-docstruct-symbol))
-         (master-dir (file-name-directory (reftex-TeX-master-file)))
+         (master-dir (reftex-get-directory-for-master (reftex-TeX-master-file)))
          (re (concat "\\`" (regexp-quote master-dir)))
         file-list tmp file)
     (while (setq tmp (assoc 'bof all))
@@ -638,7 +638,7 @@ reftex-where-am-I
                ((not found)
                 ;; no match
                 (or
-                 (car (member (list 'bof (buffer-file-name)) docstruct))
+                 (car (member (list 'bof (reftex-get-buffer-identifier)) docstruct))
                  (not (setq cnt 2))
                  (assq 'bof docstruct)  ;; for safety reasons
                  'corrupted))
@@ -649,14 +649,15 @@ reftex-where-am-I
                ((match-end 3)
                 ;; Section
                 (goto-char (1- (match-beginning 3)))
-                (let* ((list (member (list 'bof (buffer-file-name))
+                (let* ((buffile (reftex-get-buffer-identifier))
+                       (list (member (list 'bof buffile)
                                      docstruct))
-                       (endelt (car (member (list 'eof (buffer-file-name))
+                       (endelt (car (member (list 'eof buffile)
                                             list)))
                        rtn1)
                   (while (and list (not (eq endelt (car list))))
                     (if (and (eq (car (car list)) 'toc)
-                             (string= (buffer-file-name)
+                             (string= buffile
                                       (nth 3 (car list))))
                         (cond
                          ((equal (point)
@@ -758,12 +759,13 @@ reftex-notice-new
          (when (re-search-forward (reftex-everything-regexp) nil t)
            (cond
             ((match-end 1)
-             (push (reftex-label-info (reftex-match-string 1) buffer-file-name)
+             (push (reftex-label-info (reftex-match-string 1)
+                                  (reftex-get-buffer-identifier))
                    (cdr tail)))
 
             ((match-end 3)
              (setq star (= ?* (char-after (match-end 3)))
-                   entry (reftex-section-info (buffer-file-name))
+                   entry (reftex-section-info (reftex-get-buffer-identifier))
                    level (nth 5 entry))
              ;; Insert the section info
              (push entry (cdr tail))
diff --git a/lisp/textmodes/reftex-ref.el b/lisp/textmodes/reftex-ref.el
index 30e9968a8e5..a495a06ce37 100644
--- a/lisp/textmodes/reftex-ref.el
+++ b/lisp/textmodes/reftex-ref.el
@@ -73,8 +73,10 @@ 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 (if (bufferp file)
+                  file
+                (reftex-get-file-buffer-force
+                 file (not (eq t reftex-keep-temporary-buffers))))))
     (if (not buf)
         (list label typekey "" file comment "LOST LABEL.  RESCAN TO FIX.")
       (with-current-buffer buf
@@ -102,7 +104,7 @@ reftex-label-info
   (let* ((prefix (if (string-match "^[a-zA-Z0-9]+:" label)
                      (match-string 0 label)))
          (typekey (cdr (assoc prefix reftex-prefix-to-typekey-alist)))
-         (file (or file (buffer-file-name)))
+         (file (or file (reftex-get-buffer-identifier)))
          (trust reftex-trust-label-prefix)
          (in-comment (reftex-in-comment)))
     (if (and typekey
@@ -249,7 +251,7 @@ reftex-label
              (note (if (cdr here-I-am-info)
                        ""
                      "POSITION UNCERTAIN.  RESCAN TO FIX."))
-             (file (buffer-file-name))
+             (file (reftex-get-buffer-identifier))
              ;; (text nil)
              (tail (memq here-I-am (symbol-value reftex-docstruct-symbol))))
 
@@ -314,19 +316,19 @@ reftex-replace-prefix-escapes
               (save-match-data
                 (cond
                  ((equal letter "f")
-                  (file-name-base (buffer-file-name)))
+                  (file-name-base (reftex-get-buffer-identifier)))
                  ((equal letter "F")
-                  (let ((masterdir (file-name-directory (reftex-TeX-master-file)))
-                        (file (file-name-sans-extension (buffer-file-name))))
+                  (let ((masterdir (reftex-get-directory-for-master (reftex-TeX-master-file)))
+                        (file (file-name-sans-extension (reftex-get-buffer-identifier))))
                     (if (string-match (concat "\\`" (regexp-quote masterdir))
                                       file)
                         (substring file (length masterdir))
                       file)))
                  ((equal letter "m")
-                  (file-name-base (reftex-TeX-master-file)))
+                  (reftex-get-basename-for-master (reftex-TeX-master-file)))
                  ((equal letter "M")
                   (file-name-nondirectory
-                   (substring (file-name-directory (reftex-TeX-master-file))
+                   (substring (reftex-get-directory-for-master (reftex-TeX-master-file))
                               0 -1)))
                  ((equal letter "u")
                   (or (user-login-name) ""))
@@ -536,7 +538,7 @@ reftex-offer-label-menu
   ;; Offer a menu with the appropriate labels.
   (let* ((buf (current-buffer))
          (xr-data (assq 'xr (symbol-value reftex-docstruct-symbol)))
-         (xr-alist (cons (cons "" (buffer-file-name)) (nth 1 xr-data)))
+         (xr-alist (cons (cons "" (reftex-get-buffer-identifier)) (nth 1 xr-data)))
          (xr-index 0)
          (here-I-am (car (reftex-where-am-I)))
          (here-I-am1 here-I-am)
diff --git a/lisp/textmodes/reftex-sel.el b/lisp/textmodes/reftex-sel.el
index 1f1c74550a5..813a9b17532 100644
--- a/lisp/textmodes/reftex-sel.el
+++ b/lisp/textmodes/reftex-sel.el
@@ -234,7 +234,7 @@ reftex-insert-docstruct
             reftex-active-toc nil
             master-dir-re
             (concat "\\`" (regexp-quote
-                           (file-name-directory (reftex-TeX-master-file))))))
+                           (reftex-get-directory-for-master (reftex-TeX-master-file))))))
 
     (setq-local reftex-docstruct-symbol docstruct-symbol)
     (setq-local reftex-prefix
diff --git a/lisp/textmodes/reftex-toc.el b/lisp/textmodes/reftex-toc.el
index d8d09da5ed0..3a1bc2d3d10 100644
--- a/lisp/textmodes/reftex-toc.el
+++ b/lisp/textmodes/reftex-toc.el
@@ -184,14 +184,14 @@ reftex-toc
 
   (interactive)
 
-  (if (or (not (string= reftex-last-toc-master (reftex-TeX-master-file)))
+  (if (or (not (equal reftex-last-toc-master (reftex-TeX-master-file)))
           ;; FIXME: use (interactive "P") to receive current-prefix-arg as
           ;; an argument instead of using the var here, which forces us to set
           ;; current-prefix-arg in the callers.
           current-prefix-arg)
       (reftex-erase-buffer "*toc*"))
 
-  (setq reftex-last-toc-file   (buffer-file-name))
+  (setq reftex-last-toc-file   (reftex-get-buffer-identifier))
   (setq reftex-last-toc-master (reftex-TeX-master-file))
 
   (set-marker reftex-toc-return-marker (point))
@@ -211,7 +211,7 @@ reftex-toc
   (let* ((this-buf (current-buffer))
          (docstruct-symbol reftex-docstruct-symbol)
          (xr-data (assq 'xr (symbol-value reftex-docstruct-symbol)))
-         (xr-alist (cons (cons "" (buffer-file-name)) (nth 1 xr-data)))
+         (xr-alist (cons (cons "" (reftex-get-buffer-identifier)) (nth 1 xr-data)))
          (here-I-am (if reftex--rebuilding-toc
                         (get 'reftex-toc :reftex-data)
                       (car (reftex-where-am-I))))
@@ -261,7 +261,7 @@ reftex-toc
 "TABLE-OF-CONTENTS on %s
 SPC=view TAB=goto RET=goto+hide [q]uit [r]escan [l]abels [f]ollow [x]r [?]Help
 ------------------------------------------------------------------------------
-" (abbreviate-file-name reftex-last-toc-master)))
+" (reftex-abbreviate-or-get-name reftex-last-toc-master)))
 
       (if reftex-use-fonts
           (put-text-property (point-min) (point) 'font-lock-face reftex-toc-header-face))
@@ -997,7 +997,7 @@ reftex-recenter-toc-when-idle
        (not (active-minibuffer-window))
        (fboundp 'reftex-toc-mode)
        (get-buffer-window "*toc*" 'visible)
-       (string= reftex-last-toc-master (reftex-TeX-master-file))
+       (equal reftex-last-toc-master (reftex-TeX-master-file))
        (let (current-prefix-arg)
          (reftex-toc-recenter))))
 
diff --git a/lisp/textmodes/reftex.el b/lisp/textmodes/reftex.el
index fda506a6d87..67a7b120200 100644
--- a/lisp/textmodes/reftex.el
+++ b/lisp/textmodes/reftex.el
@@ -251,6 +251,58 @@ LaTeX-label-function
 (defvar tex-main-file)
 (defvar outline-minor-mode)
 
+;;; =========================================================================
+;;;
+;;; Helper functions for handling both file paths and buffer objects
+;;;
+
+(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))))
+
+(defun reftex-get-buffer-for-master (master)
+  "Get the buffer associated with MASTER.
+MASTER can be a file path or a buffer object."
+  (if (bufferp master)
+      master
+    (find-file-noselect master)))
+
+(defun reftex-get-directory-for-master (master)
+  "Get the directory associated with MASTER.
+MASTER can be a file path or a buffer object."
+  (if (bufferp master)
+      (with-current-buffer master default-directory)
+    (file-name-directory master)))
+
+(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)))
+
+(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."
+  (if (bufferp master)
+      (file-name-base (buffer-name master))
+    (file-name-base master)))
+
+(defun reftex-get-truename-for-file (file)
+  "Get the canonical form of FILE's identity.
+For files, returns the result of file-truename.
+For buffer objects, returns the buffer object itself."
+  (if (bufferp file)
+      file
+    (file-truename file)))
+
 ;;; =========================================================================
 ;;;
 ;;; Multibuffer Variables
@@ -282,7 +334,8 @@ 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)))
+  (let* ((master (reftex-TeX-master-file))
+         (master (reftex-get-truename-for-file master))
          (index (assoc master reftex-master-index-list))
          (symlist reftex-multifile-symbols)
          symbol symname newflag)
@@ -293,7 +346,13 @@ 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 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))))))
 
     ;; Get/create symbols and tie them.
     (while symlist
@@ -326,70 +385,73 @@ reftex-TeX-master-file
   ;; When AUCTeX is loaded, we will use it's more sophisticated method.
   ;; We also support the default TeX and LaTeX modes by checking for a
   ;; variable tex-main-file.
-  (let
-      ((master
-        (cond
-	 ;; Test if we're in a subfile using the subfiles document
-	 ;; class, e.g., \documentclass[main.tex]{subfiles}.  It's
-	 ;; argument is the main file, however it's not really the
-	 ;; master file in `TeX-master-file' or `tex-main-file's
-	 ;; sense.  It should be used for references but not for
-	 ;; compilation, thus subfiles use a setting of
-	 ;; `TeX-master'/`tex-main-file' being themselves.
-	 ((save-excursion
-            (goto-char (point-min))
-            (re-search-forward
-             "^[[:space:]]*\\\\documentclass\\[\\([^]]+\\)\\]{subfiles}"
-             nil t))
-          (match-string-no-properties 1))
-         ;; AUCTeX is loaded.  Use its mechanism.
-         ((fboundp 'TeX-master-file)
-          (condition-case nil
-              (TeX-master-file t)
-            (error (buffer-file-name))))
-         ;; Emacs LaTeX mode
-         ((fboundp 'tex-main-file) (tex-main-file))
-         ;; Check the `TeX-master' variable.
-         ((boundp 'TeX-master)
-          (cond
-           ((eq TeX-master t)
-            (buffer-file-name))
-           ((eq TeX-master 'shared)
-            (setq TeX-master (read-file-name "Master file: "
-                                             nil nil t nil)))
-           (TeX-master)
-           (t
-            (setq TeX-master (read-file-name "Master file: "
-                                             nil nil t nil)))))
-         ;; Check the `tex-main-file' variable.
-         ((boundp 'tex-main-file)
-          ;; This is the variable from the default TeX modes.
+  (with-current-buffer (or (buffer-base-buffer) (current-buffer))
+    (let
+        ;; Set master to a file name (possibly non-existent), or nil:
+        ((master
           (cond
-           ((stringp tex-main-file)
-            ;; ok, this must be it
-            tex-main-file)
+	   ;; Test if we're in a subfile using the subfiles document
+	   ;; class, e.g., \documentclass[main.tex]{subfiles}.  It's
+	   ;; argument is the main file, however it's not really the
+	   ;; master file in `TeX-master-file' or `tex-main-file's
+	   ;; sense.  It should be used for references but not for
+	   ;; compilation, thus subfiles use a setting of
+	   ;; `TeX-master'/`tex-main-file' being themselves.
+	   ((save-excursion
+              (goto-char (point-min))
+              (re-search-forward
+               "^[[:space:]]*\\\\documentclass\\[\\([^]]+\\)\\]{subfiles}"
+               nil t))
+            (match-string-no-properties 1))
+           ;; AUCTeX is loaded.  Use its mechanism.
+           ((fboundp 'TeX-master-file)
+            (condition-case nil
+                (TeX-master-file t)
+              (error (buffer-file-name))))
+           ;; Emacs LaTeX mode
+           ((fboundp 'tex-main-file) (tex-main-file))
+           ;; Check the `TeX-master' variable.
+           ((boundp 'TeX-master)
+            (cond
+             ((eq TeX-master t)
+              (buffer-file-name))
+             ((eq TeX-master 'shared)
+              (setq TeX-master (read-file-name "Master file: "
+                                               nil nil t nil)))
+             (TeX-master)
+             (t
+              (setq TeX-master (read-file-name "Master file: "
+                                               nil nil t nil)))))
+           ;; Check the `tex-main-file' variable.
+           ((boundp 'tex-main-file)
+            ;; This is the variable from the default TeX modes.
+            (cond
+             ((stringp tex-main-file)
+              ;; ok, this must be it
+              tex-main-file)
+             (t
+              ;; In this case, the buffer is its own master.
+              (buffer-file-name))))
+           ;; We know nothing about master file.  Assume this is a
+           ;; master file.
            (t
-            ;; In this case, the buffer is its own master.
-            (buffer-file-name))))
-         ;; We know nothing about master file.  Assume this is a
-         ;; master file.
-         (t
-          (buffer-file-name)))))
-    (cond
-     ((null master)
-      (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...
-      (setq master (concat master ".tex")))
-     ((or (file-exists-p master)
-          (find-buffer-visiting master))
-      ;; We either see the file, or have a buffer on it.  OK.
-      )
-     (t
-      ;; Use buffer file name.
-      (setq master (buffer-file-name))))
-    (expand-file-name master)))
+            (buffer-file-name)))))
+      (cond
+       ((null master))
+       ((or (file-exists-p (concat master ".tex"))
+            (find-buffer-visiting (concat master ".tex")))
+        ;; Ahh, an extra .tex was missing...
+        (setq master (concat master ".tex")))
+       ((or (file-exists-p master)
+            (find-buffer-visiting master))
+        ;; We either see the file, or have a buffer on it.  OK.
+        )
+       (t
+        ;; Use buffer file name.
+        (setq master (buffer-file-name))))
+      (if master
+          (expand-file-name master)
+        (current-buffer)))))
 
 (defun reftex-is-multi ()
   ;; Tell if this is a multifile document.  When not sure, say yes.
@@ -1105,11 +1167,6 @@ reftex-access-scan-info
   ;; But, when RESCAN is -1, don't rescan even if docstruct is empty.
   ;; When FILE is non-nil, parse only from that file.
 
-  ;; Error out in a buffer without a file.
-  (if (and reftex-mode
-	   (not (buffer-file-name)))
-      (error "RefTeX works only in buffers visiting a file"))
-
   ;; Make sure we have the symbols tied
   (if (eq reftex-docstruct-symbol nil)
       ;; Symbols are not yet tied: Tie them.
@@ -1157,81 +1214,103 @@ reftex-silence-toc-markers
 
 (defun reftex-access-parse-file (action)
   "Perform ACTION on the parse file (the .rel file).
-Valid actions are: readable, restore, read, kill, write."
+Valid actions are: readable, restore, read, kill, write.
+For non-file buffers, persistence operations are skipped."
   (let* ((list (symbol-value reftex-docstruct-symbol))
          (docstruct-symbol reftex-docstruct-symbol)
          (master (reftex-TeX-master-file))
          (enable-local-variables nil)
-         (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)))))
     (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)))
+
      ((eq action 'restore)
       (put reftex-docstruct-symbol 'modified nil)
       (if (eq reftex-docstruct-symbol nil)
           ;; Symbols are not yet tied: Tie them.
           (reftex-tie-multifile-symbols))
-      (if (file-exists-p file)
-          ;; load the file and return t for success
-          (condition-case nil
-              (progn (load-file file) t)
-            (error (set reftex-docstruct-symbol nil)
-                   (error "Error while loading file %s" file)))
+      (cond
+       (is-buffer
+        (error "Cannot restore for non-file buffer"))
+       ((file-exists-p file)
+        ;; load the file and return t for success
+        (condition-case nil
+            (progn (load-file file) t)
+          (error (set reftex-docstruct-symbol nil)
+                 (error "Error while loading file %s" file))))
+       (t
         ;; Throw an exception if the file does not exist
-        (error "No restore file %s" file)))
+        (error "No restore file %s" file))))
+
      ((eq action 'read)
       (put reftex-docstruct-symbol 'modified nil)
-      (if (file-exists-p file)
-          ;; load the file and return t for success
-          (condition-case nil
-              (progn
-                (load-file file)
-                (reftex-check-parse-consistency)
-                t)
-            (error (message "Error while restoring file %s" file)
-                   (set reftex-docstruct-symbol nil)
-                   nil))
-        ;; return nil for failure, but no exception
-        nil))
+      (cond
+       (is-buffer nil)
+       ((file-exists-p file)
+        ;; load the file and return t for success
+        (condition-case nil
+            (progn
+              (load-file file)
+              (reftex-check-parse-consistency)
+              t)
+          (error (message "Error while restoring file %s" file)
+                 (set reftex-docstruct-symbol nil)
+                 nil)))
+       (t nil))) ; return nil for failure, but no exception
+
      ((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)))
-     (t
+
+     (t ; write
       (put docstruct-symbol 'modified nil)
-      (save-excursion
-        (if (file-writable-p file)
-            (with-temp-file file
-              (message "Writing parse file %s" (abbreviate-file-name file))
-              (insert ";; RefTeX parse info file\n")
-              (insert (format ";; File: %s\n" master))
-              (insert (format ";; User: %s (%s)\n\n"
-                              (user-login-name) (user-full-name)))
-              (insert "(set reftex-docstruct-symbol '(\n\n")
-              (let ((standard-output (current-buffer)))
-                (mapc
-                 (lambda (x)
-                   (cond ((eq (car x) 'toc)
-                          ;; A toc entry. Do not save the marker.
-                          ;; Save the markers  position at position 8
-                          (print (list 'toc "toc" (nth 2 x) (nth 3 x)
-                                       nil (nth 5 x) (nth 6 x) (nth 7 x)
-                                       (or (and (markerp (nth 4 x))
-                                                (marker-position (nth 4 x)))
-                                           (nth 8 x)))))
-                         ((and (not (eq t reftex-support-index))
-                               (eq (car x) 'index))
-                          ;; Don't save index entries
-                          )
-                         (t (print x))))
-                 list))
-              (insert "))\n\n"))
-          (error "Cannot write to file %s" file)))
-      t))))
+      (if is-buffer
+          t
+        (save-excursion
+          (if (and file (file-writable-p file))
+              (with-temp-file file
+                (message "Writing parse file %s" (abbreviate-file-name file))
+                (insert ";; RefTeX parse info file\n")
+                (insert (format ";; File: %s\n" master))
+                (insert (format ";; User: %s (%s)\n\n"
+                                (user-login-name) (user-full-name)))
+                (insert "(set reftex-docstruct-symbol '(\n\n")
+                (let ((standard-output (current-buffer)))
+                  (mapc
+                   (lambda (x)
+                     (cond ((eq (car x) 'toc)
+                            ;; A toc entry. Do not save the marker.
+                            ;; Save the markers  position at position 8
+                            (print (list 'toc "toc" (nth 2 x) (nth 3 x)
+                                         nil (nth 5 x) (nth 6 x) (nth 7 x)
+                                         (or (and (markerp (nth 4 x))
+                                                  (marker-position (nth 4 x)))
+                                             (nth 8 x)))))
+                           ((and (not (eq t reftex-support-index))
+                                 (eq (car x) 'index))
+                            ;; Don't save index entries
+                            )
+                           (t (print x))))
+                   list))
+                (insert "))\n\n"))
+            (error "Cannot write to file %s" file)))
+        t)))))
 
 (defun reftex-check-parse-consistency ()
   ;; Check if parse file is consistent, throw an error if not.
@@ -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"))))
 
   ;; Check for the existence of all document files
 ;;;  (let* ((all (symbol-value reftex-docstruct-symbol)))
@@ -1281,7 +1363,7 @@ reftex-select-external-document
                   (mapconcat
                    (lambda (x)
                      (format fmt (incf n) (or (car x) "")
-                             (abbreviate-file-name (cdr x))))
+                             (reftex-abbreviate-or-get-name (cdr x))))
                    xr-alist ""))
                  nil t))
           (cond
@@ -1299,21 +1381,24 @@ reftex-locate-file
   "Find FILE of type TYPE in MASTER-DIR or on the path associated with TYPE.
 If the file does not have any of the valid extensions for TYPE,
 try first the default extension and only then the naked file name.
-When DIE is non-nil, throw an error if file not found."
-  (let* ((rec-values (if reftex-search-unrecursed-path-first '(nil t) '(t)))
-         (extensions (cdr (assoc type reftex-file-extensions)))
-         (def-ext (car extensions))
-         (ext-re (concat "\\("
-                         (mapconcat #'regexp-quote extensions "\\|")
-                         "\\)\\'"))
-         (files (if (string-match ext-re file)
-                    (cons file nil)
-		  (if reftex-try-all-extensions
-		      (append (mapcar (lambda (x) (concat file x))
-				      extensions)
-			      (list file))
-		    (list (concat file def-ext) file))))
-         path old-path file1 f fs)
+When DIE is non-nil, throw an error if file not found.
+When FILE is a buffer object, return that buffer."
+  (if (bufferp file)
+      file
+    (let* ((rec-values (if reftex-search-unrecursed-path-first '(nil t) '(t)))
+           (extensions (cdr (assoc type reftex-file-extensions)))
+           (def-ext (car extensions))
+           (ext-re (concat "\\("
+                          (mapconcat #'regexp-quote extensions "\\|")
+                          "\\)\\'"))
+           (files (if (string-match ext-re file)
+                     (cons file nil)
+                   (if reftex-try-all-extensions
+                       (append (mapcar (lambda (x) (concat file x))
+                                      extensions)
+                              (list file))
+                     (list (concat file def-ext) file))))
+           path old-path file1 f fs)
     (cond
      ((file-name-absolute-p file)
       (while (setq f (pop files))
@@ -1335,7 +1420,7 @@ reftex-locate-file
 	    (setq file1 (reftex-find-file-on-path f path master-dir)))))))
     (cond (file1 file1)
           (die (error "No such file: %s" file) nil)
-          (t (message "No such file: %s (ignored)" file) nil))))
+          (t (message "No such file: %s (ignored)" file) nil)))))
 
 (defun reftex-find-file-externally (file type &optional master-dir)
   ;; Use external program to find FILE.
@@ -1741,47 +1826,54 @@ reftex-get-file-buffer-force
   ;; If MARK-TO-KILL is t and there is no live buffer, visit the file with
   ;; initializations according to `reftex-initialize-temporary-buffers',
   ;; and mark the buffer to be killed after use.
+  ;; If FILE is actually a buffer object, just return that buffer.
 
-  (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))))
+  (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)))
 
 (defun reftex-kill-temporary-buffers (&optional buffer)
   ;; Kill all buffers in the list reftex-kill-temporary-buffers.
-- 
2.39.3 (Apple Git-145)


--=-=-=--




Information forwarded to bug-auctex@HIDDEN:
bug#76615; Package auctex. Full text available.

Message received at 76615 <at> debbugs.gnu.org:


Received: (at 76615) by debbugs.gnu.org; 2 Apr 2025 22:13:43 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Apr 02 18:13:43 2025
Received: from localhost ([127.0.0.1]:59852 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1u06L8-0006DT-QQ
	for submit <at> debbugs.gnu.org; Wed, 02 Apr 2025 18:13:43 -0400
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:57328)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <monnier@HIDDEN>)
 id 1u06L6-0006DE-CY
 for 76615 <at> debbugs.gnu.org; Wed, 02 Apr 2025 18:13:41 -0400
Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1])
 by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id D0B2A80796;
 Wed,  2 Apr 2025 18:13:34 -0400 (EDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1743632013;
 bh=sOQKr/uwmK6/SzofDqN6cVwwvVmXjQk4kddTNcdFoBQ=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=h+3VO5VdZjyRIzZ+7qwcNOHsQKMWaZBkUHzdvfsBC545LXIIDlYkSL0pQAxzTv4b4
 LHEvri+mIF5B6RuXci7K6XtUH938vwn/T6Kqq3idOEA7zlN/QC2hEBap2yNtvQJqtP
 hfRzkXCGhINHF8lsF0up5tBiKoIa/HruNEAC5sCwxCIADatUtOv+rvxcofY4N3Y3Tx
 7jRN5DUrB//prWKoN6vSzuItk27fh7xoeE/l2Yqx6UhF4YPR++ZKtQAujsSQ91tQDc
 HUJlMWfTAzbd4j8v71qQV2+zB4Xqze4CrlmJDWEp0bzwAWTQiEb69oB3HpBPo3DtXy
 qOx4kR0b5dNpw==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 69B20804D8;
 Wed,  2 Apr 2025 18:13:33 -0400 (EDT)
Received: from lechazo (lechon.iro.umontreal.ca [132.204.27.242])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 558321204D5;
 Wed,  2 Apr 2025 18:13:33 -0400 (EDT)
From: Stefan Monnier <monnier@HIDDEN>
To: "Paul D. Nelson" <ultrono@HIDDEN>
Subject: Re: bug#76615: 14.0.9; error with amsmath style hooks
In-Reply-To: <uxsg7t8qoipas4.fsf@HIDDEN>
Message-ID: <jwvy0wixn84.fsf-monnier+emacs@HIDDEN>
References: <uxsg7t8qoipas4.fsf@HIDDEN>
Date: Wed, 02 Apr 2025 18:13:33 -0400
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL -0.192 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain
 KAM_ASCII_DIVIDERS 0.8 Email that uses ascii formatting dividers and possible
 spam tricks
X-SPAM-LEVEL: 
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76615
Cc: ikumi@HIDDEN, arash@HIDDEN, 76615 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> 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@HIDDEN:
bug#76615; Package auctex. Full text available.

Message received at 76615 <at> debbugs.gnu.org:


Received: (at 76615) by debbugs.gnu.org; 2 Apr 2025 20:29:47 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Apr 02 16:29:47 2025
Received: from localhost ([127.0.0.1]:59693 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1u04iX-0001Ua-Pz
	for submit <at> debbugs.gnu.org; Wed, 02 Apr 2025 16:29:47 -0400
Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]:50295)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <ultrono@HIDDEN>) id 1u04iS-0001UF-VZ
 for 76615 <at> debbugs.gnu.org; Wed, 02 Apr 2025 16:29:43 -0400
Received: by mail-ed1-x536.google.com with SMTP id
 4fb4d7f45d1cf-5e6f4b3ebe5so412556a12.0
 for <76615 <at> debbugs.gnu.org>; Wed, 02 Apr 2025 13:29:40 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1743625774; x=1744230574; darn=debbugs.gnu.org;
 h=mime-version:message-id:date:in-reply-to:subject:cc:to:from:from:to
 :cc:subject:date:message-id:reply-to;
 bh=bjcayErEzAdUg+7A0z55KKNZiHE3oHr0grK0/RZ9WRw=;
 b=fWNE+GgKaPhqE9azGxpQRRxY4lbtuMgpqrX6MjwakV8+/nPGKRcZN9VSwaDS0Tdaxj
 TEJhgaYm/ibTUD17Xq5J3TlecS12AsW/c/8XZ1azh1bZzf8A4mWQJI3Ix24tKqQ2T7dV
 8AU9HtedS4rpIWC5qv7eFdZ9aj6T5pnj8AIi7kTx0Y4cjNE5QBJL8DrzLvBuj+Sf9Ojs
 AvOkfUhLGPfqjqriX3Hd07mhil1kbzVYm915LfOX3Zyd03rt0XbnJx4nZxtt2BJfCY0k
 40hCxRERvN88IGxjoxTU6g8REC+GCUTNi02rSf8aY/bVAd4JGBAGzdzvOjF49qQj/+QO
 gQPQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1743625774; x=1744230574;
 h=mime-version:message-id:date:in-reply-to:subject:cc:to:from
 :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
 bh=bjcayErEzAdUg+7A0z55KKNZiHE3oHr0grK0/RZ9WRw=;
 b=OiL7M2cQbfciaj75ZXzXH/QKvPVB0DyE5lqOsseU7EqbW7uWaXG6shD14mFvWofoj+
 IK0OylV48HTogj3rV3yO/hcPaaD2b48bZBQLm6XckszFImoHyrE6+KtpVW76vTvEXWl+
 +MfGdBBkluv5g+CU7S41bxAEScVcKKvpkLM9eGG5sajjDpyNaZOLboH5nbRKuOcKouTx
 w0K0kmaJ82nJpHusnWWcrdicGdX3rUtNvlpxKL0yl4/ndeGubiLp8OzT4vi9CHTWbmMa
 313w9f87+Vo1btUdPxI0QsSJw3tt0hhpTHHAYIb3Tue8aF92HIy5tZm6nLzOh1erR5/O
 ihFw==
X-Forwarded-Encrypted: i=1;
 AJvYcCXAsMLMSyQchc4gnJmClbmvfRsBogb2Ubzm9m7eL1E6NG6yraElicMID6FnSs25AdrHubiPnA==@debbugs.gnu.org
X-Gm-Message-State: AOJu0YyubIKO6BeCl0KAR5V9+ktb46cBhrGEwO3slGpH49nt8naEfyvQ
 9inaSTPb1yutrbNdzYGFVsjbcDedOZiKfLzqGfFSZ4LRKtJJcgVn
X-Gm-Gg: ASbGncuHrQzgNxTRuizPZ0ZmyiDVbi/KJkKFwR4+18bcKtDd8YGr3AL5ixwz5RlLPdY
 q9VrNGTEJX/vi0JRwX50tVRDnE7qtA89+qh7nTPSQhYPdoPbl5BShUyZIzvb3R0NVmgDJsGXX6B
 zi2Zd1kYWsAitrzRFfkNnUM5/wvMGA76ybksMIFXBR6mliO3FErVZyYDyoGcjt5kw/jURJtNFB3
 f4Ou6bAT+XXMuboVur6KpuZPr2vEJ6yC3SGM1c22R/xaiXi876b4SCwoK2/wnSLgDeJcfghwuNY
 WRnS+BaxMiu4yGQwhbrJwTfEM42MhbAcV6WSvqoNXZNWB89pZSqUHjIq/xwDQPTXgrJxfuhFMPZ
 XrdoNY83ytphWkMnMRlax
X-Google-Smtp-Source: AGHT+IHwpNm+8EBy3dAW4Q7tbpXAUko6/+taBvqCf2vo5gLdEi99ZZA1cNMwDPBEmCRF8PsJGTDkcw==
X-Received: by 2002:a05:6402:1d4b:b0:5eb:cc22:aa00 with SMTP id
 4fb4d7f45d1cf-5edfd13c985mr17161127a12.19.1743625773692; 
 Wed, 02 Apr 2025 13:29:33 -0700 (PDT)
Received: from localhost (0x573d6713.static.cust.fastspeed.dk. [87.61.103.19])
 by smtp.gmail.com with UTF8SMTPSA id
 4fb4d7f45d1cf-5edc17b2d09sm8872082a12.61.2025.04.02.13.29.32
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Wed, 02 Apr 2025 13:29:32 -0700 (PDT)
From: "Paul D. Nelson" <ultrono@HIDDEN>
To: Stefan Monnier <monnier@HIDDEN>
Subject: Re: bug#76615: 14.0.9; error with amsmath style hooks
In-Reply-To: <jwvsemq4qct.fsf-monnier+emacs@HIDDEN> (message from Stefan
 Monnier on Wed, 02 Apr 2025 10:37:32 -0400)
Date: Wed, 02 Apr 2025 22:29:31 +0200
Message-ID: <uxsg7t8qoipas4.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 76615
Cc: ikumi@HIDDEN, arash@HIDDEN, 76615 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

--=-=-=
Content-Type: text/plain

Stefan Monnier <monnier@HIDDEN> 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


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=0001-Add-RefTeX-support-for-non-file-buffers.patch

From 55258242ed336880d4578737622ddb5ef851fb44 Mon Sep 17 00:00:00 2001
From: Paul Nelson <ultrono@HIDDEN>
Date: Wed, 2 Apr 2025 21:38:48 +0200
Subject: [PATCH] Add RefTeX support for non-file buffers

* lisp/textmodes/reftex.el (reftex-get-buffer-identifier)
(reftex-get-buffer-for-master, reftex-get-directory-for-master)
(reftex-file-or-buffer-name, reftex-abbreviate-or-get-name)
(reftex-get-basename-for-master, reftex-get-truename-for-master):
New helper functions that handle both files and buffer objects.
(reftex-tie-multifile-symbols): Support non-file buffers.
(reftex-TeX-master-file): Return current buffer when no file.
(reftex-access-scan-info): Remove check requiring file buffers.
(reftex-access-parse-file, reftex-check-parse-consistency): Skip
for non-file buffers.
(reftex-select-external-document): Use new helper function.
(reftex-locate-file): Return buffer objects directly.
(reftex-get-file-buffer-force): Handle buffer objects and
special 'buffer:' strings.
* lisp/textmodes/reftex-global.el (reftex-create-tags-file): Add
error handling for non-file buffers.  We leave TAGS unsupported
in non-file buffers.
(reftex-find-duplicate-labels)
(reftex-isearch-switch-to-next-file): Use new helper functions
that handle both files and buffer objects.
* lisp/textmodes/reftex-index.el (reftex-display-index): Use new
helper functions.
(reftex-index-visit-phrases-buffer): Add error handling for
non-file buffers.  We leave phrases unsupported in non-file
buffers.
* lisp/textmodes/reftex-parse.el (reftex-do-parse): Add support
for non-file buffers.
(reftex-all-document-files, reftex-where-am-I)
(reftex-notice-new): Use new helper functions.
* lisp/textmodes/reftex-ref.el (reftex-label-info-update):
Support non-file buffers.
(reftex-label-info, reftex-replace-prefix-escapes): Use new
helper functions.
* lisp/textmodes/reftex-sel.el (reftex-insert-docstruct): Use
new helper function.
* lisp/textmodes/reftex-toc.el (reftex-toc)
(reftex-recenter-toc-when-idle): Support non-file buffers.

RefTeX historically assumed that the buffers it operates on
visit files.  For non-file buffers, we follow Stefan Monnier's
suggestion of modifying reftex-TeX-master-file so that it
returns the buffer object itself.  We then modify each caller to
handle buffer objects, aided by some helper functions added to
reftex.el.
---
 lisp/textmodes/reftex-global.el |  20 +-
 lisp/textmodes/reftex-index.el  |  20 +-
 lisp/textmodes/reftex-parse.el  |  26 +--
 lisp/textmodes/reftex-ref.el    |  17 +-
 lisp/textmodes/reftex-sel.el    |   2 +-
 lisp/textmodes/reftex-toc.el    |  10 +-
 lisp/textmodes/reftex.el        | 365 +++++++++++++++++++++-----------
 7 files changed, 291 insertions(+), 169 deletions(-)

diff --git a/lisp/textmodes/reftex-global.el b/lisp/textmodes/reftex-global.el
index 20abd36192d..d706d3e9fd2 100644
--- a/lisp/textmodes/reftex-global.el
+++ b/lisp/textmodes/reftex-global.el
@@ -38,15 +38,17 @@ reftex-create-tags-file
   (interactive)
   (reftex-access-scan-info current-prefix-arg)
   (let* ((master (reftex-TeX-master-file))
-         (files  (reftex-all-document-files))
-         (cmd    (format "%s %s"
+         (files  (reftex-all-document-files)))
+    (if (bufferp master)
+        (user-error "Cannot create TAGS file for non-file buffers")
+      (let ((cmd (format "%s %s"
                          etags-program-name
                          (mapconcat #'shell-quote-argument
-				    files " "))))
-    (with-current-buffer (reftex-get-file-buffer-force master)
-      (message "Running etags to create TAGS file...")
-      (shell-command cmd)
-      (visit-tags-table "TAGS"))))
+                                    files " "))))
+        (with-current-buffer (reftex-get-file-buffer-force master)
+          (message "Running etags to create TAGS file...")
+          (shell-command cmd)
+          (visit-tags-table "TAGS"))))))
 
 ;; History of grep commands.
 (defvar reftex-grep-history nil)
@@ -144,7 +146,7 @@ reftex-find-duplicate-labels
                 (if (< 1 (length x1))
                     (append (list (car x))
                             (mapcar (lambda(x)
-                                      (abbreviate-file-name (nth 3 x)))
+                                      (reftex-abbreviate-or-get-name (nth 3 x)))
                                     x1))
                   (list nil))))))
           (reftex-uniquify-by-car (symbol-value reftex-docstruct-symbol)))))
@@ -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
diff --git a/lisp/textmodes/reftex-index.el b/lisp/textmodes/reftex-index.el
index db6ebb4caf8..47a389500f1 100644
--- a/lisp/textmodes/reftex-index.el
+++ b/lisp/textmodes/reftex-index.el
@@ -531,7 +531,7 @@ reftex-display-index
 SPC=view TAB=goto RET=goto+hide [e]dit [q]uit [r]escan [f]ollow [?]Help
 ------------------------------------------------------------------------------
 "
-               index-tag (abbreviate-file-name master)
+               index-tag (reftex-abbreviate-or-get-name master)
                (if (eq (car (car reftex-index-restriction-data)) 'toc)
                    (nth 2 (car reftex-index-restriction-data))
                  reftex-index-restriction-indicator)))
@@ -1281,14 +1281,16 @@ reftex-index-visit-phrases-buffer
   (interactive)
   (reftex-access-scan-info)
   (set-marker reftex-index-return-marker (point))
-  (let* ((master (reftex-TeX-master-file))
-         (name (concat (file-name-sans-extension master)
-                       reftex-index-phrase-file-extension)))
-    (find-file name)
-    (unless (eq major-mode 'reftex-index-phrases-mode)
-      (reftex-index-phrases-mode))
-    (if (= (buffer-size) 0)
-        (reftex-index-initialize-phrases-buffer master))))
+  (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"))
+    (let ((name (concat (file-name-sans-extension master)
+                        reftex-index-phrase-file-extension)))
+      (find-file name)
+      (unless (eq major-mode 'reftex-index-phrases-mode)
+        (reftex-index-phrases-mode))
+      (if (= (buffer-size) 0)
+          (reftex-index-initialize-phrases-buffer master)))))
 
 (defun reftex-index-initialize-phrases-buffer (&optional master)
   "Initialize the phrases buffer by creating the header.
diff --git a/lisp/textmodes/reftex-parse.el b/lisp/textmodes/reftex-parse.el
index 7795c583076..f089536c40a 100644
--- a/lisp/textmodes/reftex-parse.el
+++ b/lisp/textmodes/reftex-parse.el
@@ -74,10 +74,10 @@ reftex-do-parse
 
   (let* ((old-list (symbol-value reftex-docstruct-symbol))
          (master (reftex-TeX-master-file))
-         (true-master (file-truename master))
-         (master-dir (file-name-as-directory (file-name-directory master)))
-         (file (or file (buffer-file-name)))
-         (true-file (file-truename file))
+         (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)))
          (bibview-cache (assq 'bibview-cache old-list))
          (reftex--index-tags (cdr (assq 'index-tags old-list)))
          from-file appendix docstruct tmp)
@@ -88,7 +88,7 @@ reftex-do-parse
                          (member (list 'eof file) old-list))))
       ;; Scan whole document because no such file section exists
       (setq rescan 1))
-    (when (string= true-file true-master)
+    (when (equal true-file true-master)
       ;; Scan whole document because this file is the master
       (setq rescan 1))
 
@@ -186,7 +186,7 @@ reftex-all-document-files
 When RELATIVE is non-nil, give file names relative to directory
 of master file."
   (let* ((all (symbol-value reftex-docstruct-symbol))
-         (master-dir (file-name-directory (reftex-TeX-master-file)))
+         (master-dir (reftex-get-directory-for-master (reftex-TeX-master-file)))
          (re (concat "\\`" (regexp-quote master-dir)))
         file-list tmp file)
     (while (setq tmp (assoc 'bof all))
@@ -638,7 +638,7 @@ reftex-where-am-I
                ((not found)
                 ;; no match
                 (or
-                 (car (member (list 'bof (buffer-file-name)) docstruct))
+                 (car (member (list 'bof (reftex-get-buffer-identifier)) docstruct))
                  (not (setq cnt 2))
                  (assq 'bof docstruct)  ;; for safety reasons
                  'corrupted))
@@ -649,14 +649,15 @@ reftex-where-am-I
                ((match-end 3)
                 ;; Section
                 (goto-char (1- (match-beginning 3)))
-                (let* ((list (member (list 'bof (buffer-file-name))
+                (let* ((buffile (reftex-get-buffer-identifier))
+                       (list (member (list 'bof buffile)
                                      docstruct))
-                       (endelt (car (member (list 'eof (buffer-file-name))
+                       (endelt (car (member (list 'eof buffile)
                                             list)))
                        rtn1)
                   (while (and list (not (eq endelt (car list))))
                     (if (and (eq (car (car list)) 'toc)
-                             (string= (buffer-file-name)
+                             (string= buffile
                                       (nth 3 (car list))))
                         (cond
                          ((equal (point)
@@ -758,12 +759,13 @@ reftex-notice-new
          (when (re-search-forward (reftex-everything-regexp) nil t)
            (cond
             ((match-end 1)
-             (push (reftex-label-info (reftex-match-string 1) buffer-file-name)
+             (push (reftex-label-info (reftex-match-string 1)
+                                  (reftex-get-buffer-identifier))
                    (cdr tail)))
 
             ((match-end 3)
              (setq star (= ?* (char-after (match-end 3)))
-                   entry (reftex-section-info (buffer-file-name))
+                   entry (reftex-section-info (reftex-get-buffer-identifier))
                    level (nth 5 entry))
              ;; Insert the section info
              (push entry (cdr tail))
diff --git a/lisp/textmodes/reftex-ref.el b/lisp/textmodes/reftex-ref.el
index 30e9968a8e5..a1b9ab084ba 100644
--- 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))))
     (if (not buf)
         (list label typekey "" file comment "LOST LABEL.  RESCAN TO FIX.")
       (with-current-buffer buf
@@ -102,7 +107,7 @@ reftex-label-info
   (let* ((prefix (if (string-match "^[a-zA-Z0-9]+:" label)
                      (match-string 0 label)))
          (typekey (cdr (assoc prefix reftex-prefix-to-typekey-alist)))
-         (file (or file (buffer-file-name)))
+         (file (or file (reftex-get-buffer-identifier)))
          (trust reftex-trust-label-prefix)
          (in-comment (reftex-in-comment)))
     (if (and typekey
@@ -316,17 +321,17 @@ reftex-replace-prefix-escapes
                  ((equal letter "f")
                   (file-name-base (buffer-file-name)))
                  ((equal letter "F")
-                  (let ((masterdir (file-name-directory (reftex-TeX-master-file)))
+                  (let ((masterdir (reftex-get-directory-for-master (reftex-TeX-master-file)))
                         (file (file-name-sans-extension (buffer-file-name))))
                     (if (string-match (concat "\\`" (regexp-quote masterdir))
                                       file)
                         (substring file (length masterdir))
                       file)))
                  ((equal letter "m")
-                  (file-name-base (reftex-TeX-master-file)))
+                  (reftex-get-basename-for-master (reftex-TeX-master-file)))
                  ((equal letter "M")
                   (file-name-nondirectory
-                   (substring (file-name-directory (reftex-TeX-master-file))
+                   (substring (reftex-get-directory-for-master (reftex-TeX-master-file))
                               0 -1)))
                  ((equal letter "u")
                   (or (user-login-name) ""))
diff --git a/lisp/textmodes/reftex-sel.el b/lisp/textmodes/reftex-sel.el
index 1f1c74550a5..813a9b17532 100644
--- a/lisp/textmodes/reftex-sel.el
+++ b/lisp/textmodes/reftex-sel.el
@@ -234,7 +234,7 @@ reftex-insert-docstruct
             reftex-active-toc nil
             master-dir-re
             (concat "\\`" (regexp-quote
-                           (file-name-directory (reftex-TeX-master-file))))))
+                           (reftex-get-directory-for-master (reftex-TeX-master-file))))))
 
     (setq-local reftex-docstruct-symbol docstruct-symbol)
     (setq-local reftex-prefix
diff --git a/lisp/textmodes/reftex-toc.el b/lisp/textmodes/reftex-toc.el
index d8d09da5ed0..3a1bc2d3d10 100644
--- a/lisp/textmodes/reftex-toc.el
+++ b/lisp/textmodes/reftex-toc.el
@@ -184,14 +184,14 @@ reftex-toc
 
   (interactive)
 
-  (if (or (not (string= reftex-last-toc-master (reftex-TeX-master-file)))
+  (if (or (not (equal reftex-last-toc-master (reftex-TeX-master-file)))
           ;; FIXME: use (interactive "P") to receive current-prefix-arg as
           ;; an argument instead of using the var here, which forces us to set
           ;; current-prefix-arg in the callers.
           current-prefix-arg)
       (reftex-erase-buffer "*toc*"))
 
-  (setq reftex-last-toc-file   (buffer-file-name))
+  (setq reftex-last-toc-file   (reftex-get-buffer-identifier))
   (setq reftex-last-toc-master (reftex-TeX-master-file))
 
   (set-marker reftex-toc-return-marker (point))
@@ -211,7 +211,7 @@ reftex-toc
   (let* ((this-buf (current-buffer))
          (docstruct-symbol reftex-docstruct-symbol)
          (xr-data (assq 'xr (symbol-value reftex-docstruct-symbol)))
-         (xr-alist (cons (cons "" (buffer-file-name)) (nth 1 xr-data)))
+         (xr-alist (cons (cons "" (reftex-get-buffer-identifier)) (nth 1 xr-data)))
          (here-I-am (if reftex--rebuilding-toc
                         (get 'reftex-toc :reftex-data)
                       (car (reftex-where-am-I))))
@@ -261,7 +261,7 @@ reftex-toc
 "TABLE-OF-CONTENTS on %s
 SPC=view TAB=goto RET=goto+hide [q]uit [r]escan [l]abels [f]ollow [x]r [?]Help
 ------------------------------------------------------------------------------
-" (abbreviate-file-name reftex-last-toc-master)))
+" (reftex-abbreviate-or-get-name reftex-last-toc-master)))
 
       (if reftex-use-fonts
           (put-text-property (point-min) (point) 'font-lock-face reftex-toc-header-face))
@@ -997,7 +997,7 @@ reftex-recenter-toc-when-idle
        (not (active-minibuffer-window))
        (fboundp 'reftex-toc-mode)
        (get-buffer-window "*toc*" 'visible)
-       (string= reftex-last-toc-master (reftex-TeX-master-file))
+       (equal reftex-last-toc-master (reftex-TeX-master-file))
        (let (current-prefix-arg)
          (reftex-toc-recenter))))
 
diff --git a/lisp/textmodes/reftex.el b/lisp/textmodes/reftex.el
index fda506a6d87..ffc34b98106 100644
--- a/lisp/textmodes/reftex.el
+++ b/lisp/textmodes/reftex.el
@@ -251,6 +251,78 @@ LaTeX-label-function
 (defvar tex-main-file)
 (defvar outline-minor-mode)
 
+;;; =========================================================================
+;;;
+;;; 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)))))
+
+(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)))
+
+(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)))
+
+(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 "")))
+
+(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 "")))
+
+(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)))
+   ((stringp master)
+    (file-name-base master))
+   (t "buffer")))
+
+(defun reftex-get-truename-for-master (master)
+  "Get the canonical form of MASTER's identity.
+For file masters, returns the result of file-truename.
+For buffer objects, returns the buffer object itself."
+  (cond
+   ((bufferp master) master)
+   ((stringp master) (file-truename master))
+   (t nil)))
+
 ;;; =========================================================================
 ;;;
 ;;; 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)))
+         (index (assoc master-key reftex-master-index-list))
          (symlist reftex-multifile-symbols)
          symbol symname newflag)
     ;; Find the correct index.
@@ -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))
 
     ;; Get/create symbols and tie them.
     (while symlist
@@ -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...
@@ -389,7 +464,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)
+      (current-buffer))))
 
 (defun reftex-is-multi ()
   ;; Tell if this is a multifile document.  When not sure, say yes.
@@ -1105,11 +1182,6 @@ reftex-access-scan-info
   ;; But, when RESCAN is -1, don't rescan even if docstruct is empty.
   ;; When FILE is non-nil, parse only from that file.
 
-  ;; Error out in a buffer without a file.
-  (if (and reftex-mode
-	   (not (buffer-file-name)))
-      (error "RefTeX works only in buffers visiting a file"))
-
   ;; Make sure we have the symbols tied
   (if (eq reftex-docstruct-symbol nil)
       ;; Symbols are not yet tied: Tie them.
@@ -1157,81 +1229,103 @@ reftex-silence-toc-markers
 
 (defun reftex-access-parse-file (action)
   "Perform ACTION on the parse file (the .rel file).
-Valid actions are: readable, restore, read, kill, write."
+Valid actions are: readable, restore, read, kill, write.
+For non-file buffers, persistence operations are skipped."
   (let* ((list (symbol-value reftex-docstruct-symbol))
          (docstruct-symbol reftex-docstruct-symbol)
          (master (reftex-TeX-master-file))
          (enable-local-variables nil)
-         (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)))))
     (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)))
+
      ((eq action 'restore)
       (put reftex-docstruct-symbol 'modified nil)
       (if (eq reftex-docstruct-symbol nil)
           ;; Symbols are not yet tied: Tie them.
           (reftex-tie-multifile-symbols))
-      (if (file-exists-p file)
-          ;; load the file and return t for success
-          (condition-case nil
-              (progn (load-file file) t)
-            (error (set reftex-docstruct-symbol nil)
-                   (error "Error while loading file %s" file)))
+      (cond
+       (is-buffer
+        (error "Cannot restore for non-file buffer"))
+       ((file-exists-p file)
+        ;; load the file and return t for success
+        (condition-case nil
+            (progn (load-file file) t)
+          (error (set reftex-docstruct-symbol nil)
+                 (error "Error while loading file %s" file))))
+       (t
         ;; Throw an exception if the file does not exist
-        (error "No restore file %s" file)))
+        (error "No restore file %s" file))))
+
      ((eq action 'read)
       (put reftex-docstruct-symbol 'modified nil)
-      (if (file-exists-p file)
-          ;; load the file and return t for success
-          (condition-case nil
-              (progn
-                (load-file file)
-                (reftex-check-parse-consistency)
-                t)
-            (error (message "Error while restoring file %s" file)
-                   (set reftex-docstruct-symbol nil)
-                   nil))
-        ;; return nil for failure, but no exception
-        nil))
+      (cond
+       (is-buffer nil)
+       ((file-exists-p file)
+        ;; load the file and return t for success
+        (condition-case nil
+            (progn
+              (load-file file)
+              (reftex-check-parse-consistency)
+              t)
+          (error (message "Error while restoring file %s" file)
+                 (set reftex-docstruct-symbol nil)
+                 nil)))
+       (t nil))) ; return nil for failure, but no exception
+
      ((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)))
-     (t
+
+     (t ; write
       (put docstruct-symbol 'modified nil)
-      (save-excursion
-        (if (file-writable-p file)
-            (with-temp-file file
-              (message "Writing parse file %s" (abbreviate-file-name file))
-              (insert ";; RefTeX parse info file\n")
-              (insert (format ";; File: %s\n" master))
-              (insert (format ";; User: %s (%s)\n\n"
-                              (user-login-name) (user-full-name)))
-              (insert "(set reftex-docstruct-symbol '(\n\n")
-              (let ((standard-output (current-buffer)))
-                (mapc
-                 (lambda (x)
-                   (cond ((eq (car x) 'toc)
-                          ;; A toc entry. Do not save the marker.
-                          ;; Save the markers  position at position 8
-                          (print (list 'toc "toc" (nth 2 x) (nth 3 x)
-                                       nil (nth 5 x) (nth 6 x) (nth 7 x)
-                                       (or (and (markerp (nth 4 x))
-                                                (marker-position (nth 4 x)))
-                                           (nth 8 x)))))
-                         ((and (not (eq t reftex-support-index))
-                               (eq (car x) 'index))
-                          ;; Don't save index entries
-                          )
-                         (t (print x))))
-                 list))
-              (insert "))\n\n"))
-          (error "Cannot write to file %s" file)))
-      t))))
+      (if is-buffer
+          t
+        (save-excursion
+          (if (and file (file-writable-p file))
+              (with-temp-file file
+                (message "Writing parse file %s" (abbreviate-file-name file))
+                (insert ";; RefTeX parse info file\n")
+                (insert (format ";; File: %s\n" master))
+                (insert (format ";; User: %s (%s)\n\n"
+                                (user-login-name) (user-full-name)))
+                (insert "(set reftex-docstruct-symbol '(\n\n")
+                (let ((standard-output (current-buffer)))
+                  (mapc
+                   (lambda (x)
+                     (cond ((eq (car x) 'toc)
+                            ;; A toc entry. Do not save the marker.
+                            ;; Save the markers  position at position 8
+                            (print (list 'toc "toc" (nth 2 x) (nth 3 x)
+                                         nil (nth 5 x) (nth 6 x) (nth 7 x)
+                                         (or (and (markerp (nth 4 x))
+                                                  (marker-position (nth 4 x)))
+                                             (nth 8 x)))))
+                           ((and (not (eq t reftex-support-index))
+                                 (eq (car x) 'index))
+                            ;; Don't save index entries
+                            )
+                           (t (print x))))
+                   list))
+                (insert "))\n\n"))
+            (error "Cannot write to file %s" file)))
+        t)))))
 
 (defun reftex-check-parse-consistency ()
   ;; Check if parse file is consistent, throw an error if not.
@@ -1240,10 +1334,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"))))
 
   ;; Check for the existence of all document files
 ;;;  (let* ((all (symbol-value reftex-docstruct-symbol)))
@@ -1281,7 +1378,7 @@ reftex-select-external-document
                   (mapconcat
                    (lambda (x)
                      (format fmt (incf n) (or (car x) "")
-                             (abbreviate-file-name (cdr x))))
+                             (reftex-abbreviate-or-get-name (cdr x))))
                    xr-alist ""))
                  nil t))
           (cond
@@ -1299,21 +1396,24 @@ reftex-locate-file
   "Find FILE of type TYPE in MASTER-DIR or on the path associated with TYPE.
 If the file does not have any of the valid extensions for TYPE,
 try first the default extension and only then the naked file name.
-When DIE is non-nil, throw an error if file not found."
-  (let* ((rec-values (if reftex-search-unrecursed-path-first '(nil t) '(t)))
-         (extensions (cdr (assoc type reftex-file-extensions)))
-         (def-ext (car extensions))
-         (ext-re (concat "\\("
-                         (mapconcat #'regexp-quote extensions "\\|")
-                         "\\)\\'"))
-         (files (if (string-match ext-re file)
-                    (cons file nil)
-		  (if reftex-try-all-extensions
-		      (append (mapcar (lambda (x) (concat file x))
-				      extensions)
-			      (list file))
-		    (list (concat file def-ext) file))))
-         path old-path file1 f fs)
+When DIE is non-nil, throw an error if file not found.
+When FILE is a buffer object, return that buffer."
+  (if (bufferp file)
+      file
+    (let* ((rec-values (if reftex-search-unrecursed-path-first '(nil t) '(t)))
+           (extensions (cdr (assoc type reftex-file-extensions)))
+           (def-ext (car extensions))
+           (ext-re (concat "\\("
+                          (mapconcat #'regexp-quote extensions "\\|")
+                          "\\)\\'"))
+           (files (if (string-match ext-re file)
+                     (cons file nil)
+                   (if reftex-try-all-extensions
+                       (append (mapcar (lambda (x) (concat file x))
+                                      extensions)
+                              (list file))
+                     (list (concat file def-ext) file))))
+           path old-path file1 f fs)
     (cond
      ((file-name-absolute-p file)
       (while (setq f (pop files))
@@ -1335,7 +1435,7 @@ reftex-locate-file
 	    (setq file1 (reftex-find-file-on-path f path master-dir)))))))
     (cond (file1 file1)
           (die (error "No such file: %s" file) nil)
-          (t (message "No such file: %s (ignored)" file) nil))))
+          (t (message "No such file: %s (ignored)" file) nil)))))
 
 (defun reftex-find-file-externally (file type &optional master-dir)
   ;; Use external program to find FILE.
@@ -1741,47 +1841,58 @@ reftex-get-file-buffer-force
   ;; If MARK-TO-KILL is t and there is no live buffer, visit the file with
   ;; initializations according to `reftex-initialize-temporary-buffers',
   ;; and mark the buffer to be killed after use.
+  ;; If FILE is actually a buffer object, just return that buffer.
+  ;; If FILE is a string starting with "buffer:", get the buffer with that name.
 
-  (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))))
+  (cond
+   ((bufferp file) file)
+
+   ((and (stringp file) (string-match "\\`buffer:\\(.*\\)" file))
+    (get-buffer (match-string 1 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)))
 
 (defun reftex-kill-temporary-buffers (&optional buffer)
   ;; Kill all buffers in the list reftex-kill-temporary-buffers.
-- 
2.39.3 (Apple Git-145)


--=-=-=--




Information forwarded to bug-auctex@HIDDEN:
bug#76615; Package auctex. Full text available.

Message received at 76615 <at> debbugs.gnu.org:


Received: (at 76615) by debbugs.gnu.org; 2 Apr 2025 14:37:47 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Apr 02 10:37:46 2025
Received: from localhost ([127.0.0.1]:58757 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tzzDt-00004r-Bh
	for submit <at> debbugs.gnu.org; Wed, 02 Apr 2025 10:37:46 -0400
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:53922)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <monnier@HIDDEN>)
 id 1tzzDp-0008Vu-I2
 for 76615 <at> debbugs.gnu.org; Wed, 02 Apr 2025 10:37:42 -0400
Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 9D26010004C;
 Wed,  2 Apr 2025 10:37:34 -0400 (EDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1743604654;
 bh=2QOfUFvGaiOtVwVRv6RoxXCzeWdIqV3wo8BhmJNqasg=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=UL1253djQGKndG3dfpRnsYaZOrslfH9rt3ebz0zbEJbHSB7+ZiUyPBbXBm3wWdlsH
 PTYsrJDVzuaL+SX1RncOCDNMQkj20c0KB4Job9vYd3czDq/qiUl1gpA9jAiuNq5BK0
 JoxUx7KRKwN83l252vXXSypqWYP1wGmNdi8GFL93254yvV8sAXOJ1Sy3lNYU75bOi/
 pLTf3Rwf6fkizA2n5S1sDOm7hpVuMVxIjiLFwh2iM597KNIAl0ANwAPjrKj800joUN
 7DVC+LCJQgDFRSh3F4XdQif24k8/rM3+cW6oD94tzwJtudojuZEM8S1nMQ1D/YN8KM
 HXvVWMSS1O7RA==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id EE301100029;
 Wed,  2 Apr 2025 10:37:33 -0400 (EDT)
Received: from pastel (unknown [104.247.242.5])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id A1CF61203D7;
 Wed,  2 Apr 2025 10:37:33 -0400 (EDT)
From: Stefan Monnier <monnier@HIDDEN>
To: "Paul D. Nelson" <ultrono@HIDDEN>
Subject: Re: bug#76615: 14.0.9; error with amsmath style hooks
In-Reply-To: <uxsg7tsen44lg3.fsf@HIDDEN>
Message-ID: <jwvsemq4qct.fsf-monnier+emacs@HIDDEN>
References: <uxsg7tcyf3nsws.fsf@HIDDEN> <uxsg7tsen44lg3.fsf@HIDDEN>
Date: Wed, 02 Apr 2025 10:37:32 -0400
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL -0.366 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain
X-SPAM-LEVEL: 
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76615
Cc: Ikumi Keita <ikumi@HIDDEN>, arash@HIDDEN, 76615 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> 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@HIDDEN:
bug#76615; Package auctex. Full text available.

Message received at 76615 <at> debbugs.gnu.org:


Received: (at 76615) by debbugs.gnu.org; 1 Apr 2025 10:30:48 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Apr 01 06:30:48 2025
Received: from localhost ([127.0.0.1]:46590 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tzYtK-0006UJ-BU
	for submit <at> debbugs.gnu.org; Tue, 01 Apr 2025 06:30:48 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:46760)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <arash@HIDDEN>) id 1tzYtF-0006Nu-Fz
 for 76615 <at> debbugs.gnu.org; Tue, 01 Apr 2025 06:30:43 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <arash@HIDDEN>)
 id 1tzYt5-0003HL-5p; Tue, 01 Apr 2025 06:30:32 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To:
 From; bh=510RQz89KLWaW9tBwZngDtzSvRGsdCKyaRHizdYGQpY=; b=ZF1U76bRY4x/YzuSSkxN
 YGKOj7Fx5ybOIdlUzEZcux+IQvkemigpqS+nLkRNM0pGuLHL2eZlAEJQyA8tK9/hjIWUCRl1gi91q
 iLn98TlVdUK/7xyTevd/qne6uJp7TAIzo+OYrhscfeZA625nzcyld42JtcfnXbOjEE9rKSNez5YKQ
 G7uST2AvGVvH32QT1vh1Qa7BgLeb755ZSYdM0WUMbvbyjj82b7qCnK6q7da5greypMnAecskJbpBB
 RAhNSexl8tbHGFSbbVDBMRnNjB4HZSINCEzGnpZYX78vN+UCZ5NTJEe6nGLN1KW1yoHfQJ6hGuv0O
 ygu1NyGps14fNw==;
From: Arash Esbati <arash@HIDDEN>
To: Ikumi Keita <ikumi@HIDDEN>
Subject: Re: bug#76615: 14.0.9; error with amsmath style hooks
In-Reply-To: <10156.1743168497@localhost>
References: <uxsg7ta5983ex6.fsf@HIDDEN> <90342.1742980500@localhost>
 <m2r02iq53c.fsf@HIDDEN> <10156.1743168497@localhost>
Date: Tue, 01 Apr 2025 12:30:21 +0200
Message-ID: <m2o6xgi37m.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76615
Cc: 76615 <at> debbugs.gnu.org, "Paul D. Nelson" <ultrono@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

Hi Keita,

Ikumi Keita <ikumi@HIDDEN> writes:

> Sure. I attach the patch.

Thanks, I pushed your change to Emacs master branch (commit 90571269).

Best, Arash




Information forwarded to bug-auctex@HIDDEN:
bug#76615; Package auctex. Full text available.

Message received at 76615 <at> debbugs.gnu.org:


Received: (at 76615) by debbugs.gnu.org; 28 Mar 2025 13:28:24 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Mar 28 09:28:23 2025
Received: from localhost ([127.0.0.1]:53336 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1ty9l1-0008HD-Gj
	for submit <at> debbugs.gnu.org; Fri, 28 Mar 2025 09:28:23 -0400
Received: from smtp1a.inetd.co.jp ([210.129.88.11]:55014)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <ikumi@HIDDEN>)
 id 1ty9ky-0008H2-8Y
 for 76615 <at> debbugs.gnu.org; Fri, 28 Mar 2025 09:28:21 -0400
Received: from localhost (42-144-34-247.rev.home.ne.jp [42.144.34.247])
 by smtp1a.inetd.co.jp (Postfix) with ESMTPSA id AD4D05C;
 Fri, 28 Mar 2025 22:28:17 +0900 (JST)
From: Ikumi Keita <ikumi@HIDDEN>
To: Arash Esbati <arash@HIDDEN>
Subject: Re: bug#76615: 14.0.9; error with amsmath style hooks
In-reply-to: <m2r02iq53c.fsf@HIDDEN>
References: <uxsg7ta5983ex6.fsf@HIDDEN> <90342.1742980500@localhost>
 <m2r02iq53c.fsf@HIDDEN>
Comments: In-reply-to Arash Esbati <arash@HIDDEN>
 message dated "Thu, 27 Mar 2025 08:56:39 +0100."
X-Mailer: MH-E 8.6+git; nmh 1.8; Emacs 29.4
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
Date: Fri, 28 Mar 2025 22:28:17 +0900
Message-ID: <10156.1743168497@localhost>
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 76615
Cc: 76615 <at> debbugs.gnu.org, "Paul D. Nelson" <ultrono@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

--=-=-=
Content-Type: text/plain

Hi Arash,

>>>>> Arash Esbati <arash@HIDDEN> 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


--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
 filename=0001-Suppress-error-in-non-file-buffer.patch
Content-Description: git format patch

From 38f3f2d59611e30309046e4c115797ca1110feae Mon Sep 17 00:00:00 2001
From: Ikumi Keita <ikumi@HIDDEN>
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


--=-=-=--




Information forwarded to bug-auctex@HIDDEN:
bug#76615; Package auctex. Full text available.

Message received at 76615 <at> debbugs.gnu.org:


Received: (at 76615) by debbugs.gnu.org; 27 Mar 2025 07:56:54 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Mar 27 03:56:53 2025
Received: from localhost ([127.0.0.1]:47238 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1txi6e-0002eL-VN
	for submit <at> debbugs.gnu.org; Thu, 27 Mar 2025 03:56:53 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:48068)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <arash@HIDDEN>) id 1txi6b-0002dV-CA
 for 76615 <at> debbugs.gnu.org; Thu, 27 Mar 2025 03:56:50 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <arash@HIDDEN>)
 id 1txi6T-00049g-Sr; Thu, 27 Mar 2025 03:56:41 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To:
 From; bh=eNqy28FQshro//nzvXxhQjfsm291gVAzUc/ybFvdZNs=; b=WJ8EqY5WOxqo3h36gUTp
 qzkf62+SGKk9qZgGIZoxZO2KTggZ0xogiQToIQfd/4go9MJPlUTujZgGK2GFpxWNILI/ySLgv9H1P
 1o4rmvMXY74Z7PVXdAHCsIa372a4XF9lnrMbebEv2WL5GdXWZdb2jKaMX1LnS81OCKmuH4sAWOaLM
 vAC4geGOwEeDkPtfagzyI0p0xXIYdbyCZC4NIADRKDGrlnR0JoXXxGqKfxun5vQ0jc2HEcxDQizb0
 bjf838ejo0pjrLcK9gx80zzmEHYcH6upEBI0B3p/ISanuo/iNERt9oCvGskB4rbZVFJh3Adi4mZS4
 jYUP3RmU5n3Kvg==;
From: Arash Esbati <arash@HIDDEN>
To: Ikumi Keita <ikumi@HIDDEN>
Subject: Re: bug#76615: 14.0.9; error with amsmath style hooks
In-Reply-To: <90342.1742980500@localhost>
References: <uxsg7ta5983ex6.fsf@HIDDEN> <90342.1742980500@localhost>
Date: Thu, 27 Mar 2025 08:56:39 +0100
Message-ID: <m2r02iq53c.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76615
Cc: 76615 <at> debbugs.gnu.org, "Paul D. Nelson" <ultrono@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

Hi Keita,

Ikumi Keita <ikumi@HIDDEN> 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@HIDDEN>
> 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@HIDDEN:
bug#76615; Package auctex. Full text available.

Message received at 76615 <at> debbugs.gnu.org:


Received: (at 76615) by debbugs.gnu.org; 26 Mar 2025 09:15:10 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Mar 26 05:15:10 2025
Received: from localhost ([127.0.0.1]:41358 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1txMqs-0007FX-25
	for submit <at> debbugs.gnu.org; Wed, 26 Mar 2025 05:15:10 -0400
Received: from smtp1a.inetd.co.jp ([210.129.88.11]:49194)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <ikumi@HIDDEN>)
 id 1txMqm-0007AD-CM
 for 76615 <at> debbugs.gnu.org; Wed, 26 Mar 2025 05:15:06 -0400
Received: from localhost (42-144-34-247.rev.home.ne.jp [42.144.34.247])
 by smtp1a.inetd.co.jp (Postfix) with ESMTPSA id 42DCA5C;
 Wed, 26 Mar 2025 18:15:01 +0900 (JST)
From: Ikumi Keita <ikumi@HIDDEN>
To: "Paul D. Nelson" <ultrono@HIDDEN>
Subject: Re: bug#76615: 14.0.9; error with amsmath style hooks
In-reply-to: <uxsg7ta5983ex6.fsf@HIDDEN>
References: <uxsg7ta5983ex6.fsf@HIDDEN>
Comments: In-reply-to "Paul D. Nelson" <ultrono@HIDDEN>
 message dated "Tue, 25 Mar 2025 23:48:21 +0100."
X-Mailer: MH-E 8.6+git; nmh 1.8; Emacs 29.4
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
Date: Wed, 26 Mar 2025 18:15:00 +0900
Message-ID: <90342.1742980500@localhost>
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 76615
Cc: arash@HIDDEN, 76615 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

--=-=-=
Content-Type: text/plain

>>>>> "Paul D. Nelson" <ultrono@HIDDEN> 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@HIDDEN>
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


--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment; filename=diff
Content-Description: patch for reftex

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	Wed Mar 26 18:09:26 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.

--=-=-=--




Information forwarded to bug-auctex@HIDDEN:
bug#76615; Package auctex. Full text available.

Message received at 76615 <at> debbugs.gnu.org:


Received: (at 76615) by debbugs.gnu.org; 25 Mar 2025 22:48:32 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Mar 25 18:48:32 2025
Received: from localhost ([127.0.0.1]:40368 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1txD4S-0007DM-1S
	for submit <at> debbugs.gnu.org; Tue, 25 Mar 2025 18:48:32 -0400
Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]:47105)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <ultrono@HIDDEN>) id 1txD4P-0007D5-5H
 for 76615 <at> debbugs.gnu.org; Tue, 25 Mar 2025 18:48:29 -0400
Received: by mail-wm1-x336.google.com with SMTP id
 5b1f17b1804b1-43cf848528aso51727855e9.2
 for <76615 <at> debbugs.gnu.org>; Tue, 25 Mar 2025 15:48:29 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1742942903; x=1743547703; darn=debbugs.gnu.org;
 h=mime-version:message-id:date:in-reply-to:subject:cc:to:from:from:to
 :cc:subject:date:message-id:reply-to;
 bh=wxP0pCEOT2RjQmkzOi+4IYLDBzpDVoVktt99uPDJVZ8=;
 b=fseEuY+TwPMmYM8sAEe74IDDx/aYL8QYBlS7Isb3Q1XijBK2w223xMV01dSjBB5v66
 xjLXxS7mnB6MF6HYK4umA3b31rmWHq79zgnNtSjq9x9C/2uZZIDMS5z/IT2ZNnK648R1
 bqCxRWWO+3izhmhdXuYw+ZJXonBMfPTCY6Zl2peZp08mGnlZ/IGCUs6DSZQ+QSo/zZfy
 x6VDr/WIT9hP9pQf69qRM+EDu55/mbyaYQLldzULL7pBJA4FaLWiUYKL3iif2tg5Kt0W
 PlFpD7CJ5Cl/Tr2xTIAA5Cz39oyeBL06xPg840Z7aWd+ffO/OCIaRxj0bV48P4KDC4bA
 i7UQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1742942903; x=1743547703;
 h=mime-version:message-id:date:in-reply-to:subject:cc:to:from
 :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
 bh=wxP0pCEOT2RjQmkzOi+4IYLDBzpDVoVktt99uPDJVZ8=;
 b=XCBwxWXYF1RqmJbTRsnXMlPSsFzm5x1sx8kjTpBUhIRgCFVB9WH//5Q0iQH1M2ozj/
 1XTdv+uCAM32HSc1Z6tF3/GZbT9NgIOx/PQEZRGTEwQ+d6yE114flX580q+gsVG2WtI2
 O5HJoBowaO9AsaEV/l8WPnJOw4v/J95UriaKW2KdkfXzm6CN2OoHO/pVfOXQODfP8MuM
 BGhOxWfA/mmUgBAvQv0gAgrPd5FULe4FkZHy6K30Hy9eAX+ZmbqzmEaNkUqWL6JkCw0t
 b4hOJjkspV6ErtPjSuNJKTv1Y/snkEvtZY1CTBEvGNkzytVp6rmzE64zRmGQHcOB21MS
 e/8A==
X-Forwarded-Encrypted: i=1;
 AJvYcCW2G7oDVb6QlbW5nWp0sTDjh/45HFkEEraVuk/jOXWvRsLwDnLxSsBFjcfvCGMjlfVBa8+3ZA==@debbugs.gnu.org
X-Gm-Message-State: AOJu0YyklvD9ORhPMPD52BShcNyItdfr8YFD0sMTgazlNBcrjD5hsD/o
 bsgK9vybYUGPSTsRQxN+yuzeWldj9nONk5hGg/1tU/7278A9oMtW
X-Gm-Gg: ASbGnctdkoBcDzLDvAGUCxGpZvXCHwKA3UagD8Kiv4/oWrKa6kKBPtW3NQs16GJcsQG
 qXjXUraSA7PGYj+QUlcV3WqtJH+d7bjDAZxtYfrULXxOyV1pGoKqHRXqCn/4uGnhShG66X2vfrB
 z8M0FYSlGWbu3mF+eny7+fvk6WT0sxV2fP/NIe8SDwWBrQnO3qz2KaY2GGUUBMD+3vCjpIKZM1A
 k/l8qPxeFppGis/1BHdWwcZr8wJwpgxWsm8l8BXaMgwIwfOsTjgY9K8jc+eQNAjRFUs0274nK7R
 Drfodgw67cOR1O8I+UxXA/MRX2jlA8nhYKHMyg1i6x/IKFwIejys/591h4hIQ+UNzlEP4nJ41Ov
 dgXj03iuxmc06chN36c37
X-Google-Smtp-Source: AGHT+IHIo0MKK6dmIp3hJZprv4gAjXJhQFcBkSOQGw95EY7XAx7kuhoeMFUMPs5aLfUYeOf6H9OKHw==
X-Received: by 2002:a05:600c:1548:b0:43c:f78d:82eb with SMTP id
 5b1f17b1804b1-43d509f5985mr208897155e9.15.1742942902780; 
 Tue, 25 Mar 2025 15:48:22 -0700 (PDT)
Received: from localhost (cust-east-par-46-193-68-34.cust.wifirst.net.
 [46.193.68.34]) by smtp.gmail.com with UTF8SMTPSA id
 5b1f17b1804b1-43d43f3328bsm213523015e9.1.2025.03.25.15.48.22
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Tue, 25 Mar 2025 15:48:22 -0700 (PDT)
From: "Paul D. Nelson" <ultrono@HIDDEN>
To: Ikumi Keita <ikumi@HIDDEN>
Subject: Re: bug#76615: 14.0.9; error with amsmath style hooks
In-Reply-To: <67231.1742807409@localhost> (message from Ikumi Keita on Mon,
 24 Mar 2025 18:10:09 +0900)
Date: Tue, 25 Mar 2025 23:48:21 +0100
Message-ID: <uxsg7ta5983ex6.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 76615
Cc: arash@HIDDEN, 76615 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Hi Ikumi, your last patch looks good and seems to work fine for me.
Thanks, best,  Paul




Information forwarded to bug-auctex@HIDDEN:
bug#76615; Package auctex. Full text available.

Message received at 76615 <at> debbugs.gnu.org:


Received: (at 76615) by debbugs.gnu.org; 24 Mar 2025 09:10:17 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Mar 24 05:10:17 2025
Received: from localhost ([127.0.0.1]:54207 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1twdp3-0002Ey-0A
	for submit <at> debbugs.gnu.org; Mon, 24 Mar 2025 05:10:17 -0400
Received: from smtp1a.inetd.co.jp ([210.129.88.11]:43424)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <ikumi@HIDDEN>)
 id 1twdp0-0002Ed-Bh
 for 76615 <at> debbugs.gnu.org; Mon, 24 Mar 2025 05:10:15 -0400
Received: from localhost (42-144-34-247.rev.home.ne.jp [42.144.34.247])
 by smtp1a.inetd.co.jp (Postfix) with ESMTPSA id 835FE5C;
 Mon, 24 Mar 2025 18:10:10 +0900 (JST)
From: Ikumi Keita <ikumi@HIDDEN>
To: "Paul D. Nelson" <ultrono@HIDDEN>
Subject: Re: bug#76615: 14.0.9; error with amsmath style hooks
In-reply-to: <7443.1742474043@localhost>
References: <uxsg7ta59nhco1.fsf@HIDDEN> <7443.1742474043@localhost>
Comments: In-reply-to Ikumi Keita <ikumi@HIDDEN>
 message dated "Thu, 20 Mar 2025 21:34:03 +0900."
X-Mailer: MH-E 8.6+git; nmh 1.8; Emacs 29.4
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-ID: <67228.1742807409.1@localhost>
Date: Mon, 24 Mar 2025 18:10:09 +0900
Message-ID: <67231.1742807409@localhost>
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 76615
Cc: arash@HIDDEN, 76615 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

[ Sorry to have incomplete References: header; I deleted Paul's last post
by mistake. ]

Hi Paul,

>>>>> "Paul D. Nelson" <ultrono@HIDDEN> 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@HIDDEN:
bug#76615; Package auctex. Full text available.

Message received at 76615 <at> debbugs.gnu.org:


Received: (at 76615) by debbugs.gnu.org; 23 Mar 2025 00:53:21 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Mar 22 20:53:20 2025
Received: from localhost ([127.0.0.1]:46306 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tw9aX-00055p-D9
	for submit <at> debbugs.gnu.org; Sat, 22 Mar 2025 20:53:20 -0400
Received: from mail-ej1-x630.google.com ([2a00:1450:4864:20::630]:60564)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <ultrono@HIDDEN>) id 1tw9aQ-00054P-Pe
 for 76615 <at> debbugs.gnu.org; Sat, 22 Mar 2025 20:53:14 -0400
Received: by mail-ej1-x630.google.com with SMTP id
 a640c23a62f3a-ac28e66c0e1so487595466b.0
 for <76615 <at> debbugs.gnu.org>; Sat, 22 Mar 2025 17:53:10 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1742691184; x=1743295984; darn=debbugs.gnu.org;
 h=mime-version:message-id:date:in-reply-to:subject:cc:to:from:from:to
 :cc:subject:date:message-id:reply-to;
 bh=ds8PFcr7uVFD/12zUdjgzf7VdB5Bj5itLM0rEo7A3x0=;
 b=Gacfwjv8VAPNQrWEJiEorArHAIUBdcJtoc94t7Lt4eG+mG3be2mLZW4U0VcJ9SazoG
 dA7llJTNeCDA155gVg2bQ8IWJ8p9vE1+dIcTrvPFpt/GczEvj5oDHmZ2spnr2PHcgSog
 sk/Pn0e/BAqtBduvWJAkzxXv15Xi8bvNFtUjmXmMzXbCmXZlclJVr4KkR5UP1JTced8e
 LN2PjiJY9jGdW+J2/O/+QPitCICBZ+7Jl5r2ny4RoGV9uLn8PHQfDzxkwFH5vjEiXO19
 N4YxRb0V2zQ19Yvbu2u09JZ20CIg6tlHCDcKicAN1FpGY7H+6FcjpFIEm+1chl12VfMP
 5oCQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1742691184; x=1743295984;
 h=mime-version:message-id:date:in-reply-to:subject:cc:to:from
 :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
 bh=ds8PFcr7uVFD/12zUdjgzf7VdB5Bj5itLM0rEo7A3x0=;
 b=rc0OBfDhS+HWOU3L0BIBNebJWZsWaIbvZDn34OYifEuYHc7EVhPTttI4e+E5BDcdHJ
 9o9Cklgb5g/ZM3DZGrGxSLMeHLs/NCJwiaee0tB0ZOB3qwNSMq68l2RDXbmPnbsm/645
 jZ7hKAyNUp6i38ZN0SQiafMYdwijc9zgyXoXi3f1A4/AeXf0v2HWbhIh5QC4UtMQ+gsQ
 X/TzEZhp9jgm3F3bCYy9i3sZWbwZhQI9YvBJZxMzP4W1XAZ1bHkseTqX5RXhQQDboveP
 q2OHyadJbJ/KtSokEOBYSKKKye10FyIag/K3WRH6WVePvx9uXjvaz7flRiq7KSzi8EBN
 MGgg==
X-Forwarded-Encrypted: i=1;
 AJvYcCWLixQWs5K0sXFbMSX1tq92h2VFp2XaOCbphD11dCqAaQOBppJws3JkmFVT4x06jfQqTTahCw==@debbugs.gnu.org
X-Gm-Message-State: AOJu0Yy+9WQDs4L+MOcp0WHNomR1snKKPipp8aI0rJiupqW81+FRrTab
 lZ+xRCMd/zg94YITjGKB267wY7t1TxRlS/wAabsy3Kky4jCHBzOf
X-Gm-Gg: ASbGnct0Uq4UlUWJzLYXa4uiNOdb1j97Yy5RQubP+BcJ8pkWsbI2+GcOT4n9JEJowxH
 NqpE49hu+QZIANkGh0teTF3ThQ4caoMOtb4Bq9429Yk0ljaIMu0W2G37lvxWmVnm7AJTQYjVD8z
 +ZmlYsoLKrogBWg7+sN0+NLaJDqcgPQLUveSTTrttWWxZF9gJPPEgZbCx6wc8vqt1xHZsAK/5uZ
 5V51nsHB+R1wXp3L16EvBDXBiXHvnU9xOmCK/wgjjSiO3pTFRkhgQV9EvMXSQyWrIenqR3QcQ0M
 0lzynytAz5tmh80L0TERQL9qPpxqQxIMzb2Z1OrvvHT8z93pB6a/mXNPb5Jzvvxt12RE/Fq+CLL
 2KVuT4A3T1/x/ma5r6+iS
X-Google-Smtp-Source: AGHT+IHAEPc0I3DNU57COJ3ECEiOI2CvBCwLcsu93JqoKtJOAI3N4IguHAvCvvM7fhA/VHql7YjXDw==
X-Received: by 2002:a17:907:3da4:b0:ac3:f1dc:f3db with SMTP id
 a640c23a62f3a-ac3f21020e7mr845411166b.13.1742691183230; 
 Sat, 22 Mar 2025 17:53:03 -0700 (PDT)
Received: from localhost (0x573d6713.static.cust.fastspeed.dk. [87.61.103.19])
 by smtp.gmail.com with UTF8SMTPSA id
 a640c23a62f3a-ac3efd24f25sm430060566b.155.2025.03.22.17.53.00
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Sat, 22 Mar 2025 17:53:02 -0700 (PDT)
From: "Paul D. Nelson" <ultrono@HIDDEN>
To: Ikumi Keita <ikumi@HIDDEN>
Subject: Re: bug#76615: 14.0.9; error with amsmath style hooks
In-Reply-To: <7443.1742474043@localhost> (message from Ikumi Keita on Thu,
 20 Mar 2025 21:34:03 +0900)
Date: Sun, 23 Mar 2025 01:53:00 +0100
Message-ID: <uxsg7tsen44lg3.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 76615
Cc: arash@HIDDEN, 76615 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

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@HIDDEN:
bug#76615; Package auctex. Full text available.

Message received at 76615 <at> debbugs.gnu.org:


Received: (at 76615) by debbugs.gnu.org; 20 Mar 2025 12:34:11 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Mar 20 08:34:11 2025
Received: from localhost ([127.0.0.1]:56008 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tvF6A-0003eH-NC
	for submit <at> debbugs.gnu.org; Thu, 20 Mar 2025 08:34:11 -0400
Received: from smtp1a.inetd.co.jp ([210.129.88.11]:34860)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <ikumi@HIDDEN>)
 id 1tvF67-0003e6-Jy
 for 76615 <at> debbugs.gnu.org; Thu, 20 Mar 2025 08:34:08 -0400
Received: from localhost (42-144-34-247.rev.home.ne.jp [42.144.34.247])
 by smtp1a.inetd.co.jp (Postfix) with ESMTPSA id 813595C;
 Thu, 20 Mar 2025 21:34:04 +0900 (JST)
From: Ikumi Keita <ikumi@HIDDEN>
To: "Paul D. Nelson" <ultrono@HIDDEN>
Subject: Re: bug#76615: 14.0.9; error with amsmath style hooks
In-reply-to: <uxsg7ta59nhco1.fsf@HIDDEN>
References: <uxsg7ta59nhco1.fsf@HIDDEN>
Comments: In-reply-to "Paul D. Nelson" <ultrono@HIDDEN>
 message dated "Fri, 14 Mar 2025 08:09:18 -0700."
X-Mailer: MH-E 8.6+git; nmh 1.8; Emacs 29.4
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-ID: <7440.1742474043.1@localhost>
Content-Transfer-Encoding: quoted-printable
Date: Thu, 20 Mar 2025 21:34:03 +0900
Message-ID: <7443.1742474043@localhost>
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 76615
Cc: arash@HIDDEN, 76615 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Hi Paul,

>>>>> "Paul D. Nelson" <ultrono@HIDDEN> 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 appli=
cation."
   ;; `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@HIDDEN:
bug#76615; Package auctex. Full text available.

Message received at 76615 <at> debbugs.gnu.org:


Received: (at 76615) by debbugs.gnu.org; 14 Mar 2025 15:09:36 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Mar 14 11:09:36 2025
Received: from localhost ([127.0.0.1]:35541 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tt6fH-0001an-Vq
	for submit <at> debbugs.gnu.org; Fri, 14 Mar 2025 11:09:36 -0400
Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]:46388)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <ultrono@HIDDEN>) id 1tt6fE-0001aU-OG
 for 76615 <at> debbugs.gnu.org; Fri, 14 Mar 2025 11:09:33 -0400
Received: by mail-ed1-x535.google.com with SMTP id
 4fb4d7f45d1cf-5e5b6f3025dso3237916a12.1
 for <76615 <at> debbugs.gnu.org>; Fri, 14 Mar 2025 08:09:32 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1741964966; x=1742569766; darn=debbugs.gnu.org;
 h=mime-version:message-id:date:in-reply-to:subject:cc:to:from:from:to
 :cc:subject:date:message-id:reply-to;
 bh=oo+wHXJgcHR76noEenSnUtKfx9cCMq68jQn3mQXRTKo=;
 b=C0qfI/u9tsAcNXXav7E6BnzfE8WPyP0weKusxRXsNqC5MWg9bBWPclJa/PZKA99Itf
 /hwS+CqCYcTH5S6jU476ejQh2Epx1Owcobaw9S3Q1R0A/HhVKAgJ9PpNfQWS5lpWnR7L
 aInh2Dwy8LoC7sGjF7VnKB6zuEUZ5cPox4CXbormW/uMhYqfJOXtZCMGXom4VszQH5Hq
 UmxCHpfTnm/zJ1vNyyVZE9Jt/d/b9ym1GVCXktmbss79OuWCuo6TJkXG5com6DjUrfNs
 Lmt3st4Qs3U8bGEvXvcE+ooR/uiL3aKpblhW9ELJjsdQWnzUaKbJZ9EDfCxLz2YwnS5X
 LCYw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1741964966; x=1742569766;
 h=mime-version:message-id:date:in-reply-to:subject:cc:to:from
 :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
 bh=oo+wHXJgcHR76noEenSnUtKfx9cCMq68jQn3mQXRTKo=;
 b=ICO9uLa8UaQnabH2GgXvzN3lykiZS/L6biH5ojgD7nFoIx4K7aaQlZK2nDIl3BlxjN
 qvhAiei5auJ7z0FldMEAPm3kPiGqDmNSOSelekYpPai7239t1trJ0huRbUHhK1TzSu6x
 rhM4oDO3NWAuk/E+DpgQkTRaUSMMXXRQYKtfTKe43Psd04QIl9PBXELXtk9geQC9cg0z
 oYV7NxHdEnyTLzDYOw3mq6x/H95p4vptztEder7g8bRSnsTpeaKyDMDLjjmVTneVVbDN
 Ff5A/KaZpMdmpw6Yd9HAJ8z9Yflen6TGNBnDkcflpvlb48VCRtTcla3usDjXd/TrzW5Z
 UNyw==
X-Forwarded-Encrypted: i=1;
 AJvYcCVyJjpAZYnHHlV3JXqQdP+tuhusf0HMRGu6p30FKs7dmdXCYZTDtK7YjtR+59UYzo5oTBjoNQ==@debbugs.gnu.org
X-Gm-Message-State: AOJu0YxwRNII4sItttj7kVCjLdu4ea8xZTVVe8ZcoNokomjjrJbs5Xc7
 MHsDNU0d8jlCWx5hIjVBrTev59ErzvzuqVM6dhbgx9SaR6m8L7mwNU+bo4dtN+g=
X-Gm-Gg: ASbGncv8JXFwIL+VN+CHWHjFYBQ+YnCvFhI8f1Bs9ttaR9M+YZ8+IZYsfFSYpzRg+92
 aaNNN3d1lhyFacWoYIC5NlSbFKQxTFB/SutNmkkKC8wb4e863H05D3oxjSZTj/KRtVDvCipQKNX
 vbPocUY9tTkSaf27jzY0Ja9LWUJXExXfUSqjmrh7tuDxDkuIorUY5Cm08TL5mH4+5YYQvoprPpK
 ymVD7TvZUAaZAwbo2Wd6/nzySngS+HL/nMHz6fhw109zXDmdaFcGZNV60WDmeEDiqMv/Z0PwnSB
 HDI0GBWlaaPQ6+UyQ1VlG6TfqIwvzmxHxct7N8eBcbMIGmgofv3/p9uFwA==
X-Google-Smtp-Source: AGHT+IGsJe/Ey9AAocZ+ypneFxdmgz1RTbReuKHaA0y92VZLfkl7s9Sd5eNyRFNPzH+xS/eEyg28Lw==
X-Received: by 2002:a05:6402:13d2:b0:5de:dd6b:a7b0 with SMTP id
 4fb4d7f45d1cf-5e89f346c97mr3402334a12.1.1741964965734; 
 Fri, 14 Mar 2025 08:09:25 -0700 (PDT)
Received: from localhost ([37.96.65.75]) by smtp.gmail.com with UTF8SMTPSA id
 4fb4d7f45d1cf-5e8169bcad3sm2116093a12.47.2025.03.14.08.09.22
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 14 Mar 2025 08:09:24 -0700 (PDT)
From: "Paul D. Nelson" <ultrono@HIDDEN>
To: Ikumi Keita <ikumi@HIDDEN>
Subject: Re: bug#76615: 14.0.9; error with amsmath style hooks
In-Reply-To: <57868.1740852100@localhost> (message from Ikumi Keita on Sun,
 02 Mar 2025 03:01:40 +0900)
Date: Fri, 14 Mar 2025 08:09:18 -0700
Message-ID: <uxsg7ta59nhco1.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 76615
Cc: arash@HIDDEN, 76615 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

--=-=-=
Content-Type: text/plain

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



--=-=-=
Content-Type: text/x-patch
Content-Disposition: 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@HIDDEN:
bug#76615; Package auctex. Full text available.

Message received at 76615 <at> debbugs.gnu.org:


Received: (at 76615) by debbugs.gnu.org; 1 Mar 2025 18:01:50 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Mar 01 13:01:50 2025
Received: from localhost ([127.0.0.1]:43188 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1toR9p-0005Uo-J6
	for submit <at> debbugs.gnu.org; Sat, 01 Mar 2025 13:01:50 -0500
Received: from smtp1a.inetd.co.jp ([210.129.88.11]:40196)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <ikumi@HIDDEN>)
 id 1toR9k-0005Tw-GU
 for 76615 <at> debbugs.gnu.org; Sat, 01 Mar 2025 13:01:47 -0500
Received: from localhost (42-144-34-247.rev.home.ne.jp [42.144.34.247])
 by smtp1a.inetd.co.jp (Postfix) with ESMTPSA id 0FE885C;
 Sun,  2 Mar 2025 03:01:41 +0900 (JST)
From: Ikumi Keita <ikumi@HIDDEN>
To: "Paul D. Nelson" <ultrono@HIDDEN>
Subject: Re: bug#76615: 14.0.9; error with amsmath style hooks
In-reply-to: <uxsg7tbjuljjbu.fsf@HIDDEN>
References: <uxsg7tbjuljjbu.fsf@HIDDEN>
Comments: In-reply-to "Paul D. Nelson" <ultrono@HIDDEN>
 message dated "Sat, 01 Mar 2025 08:33:57 +0100."
X-Mailer: MH-E 8.6+git; nmh 1.8; Emacs 29.4
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-ID: <57867.1740852100.1@localhost>
Date: Sun, 02 Mar 2025 03:01:40 +0900
Message-ID: <57868.1740852100@localhost>
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 76615
Cc: arash@HIDDEN, 76615 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Hi Paul,

>>>>> "Paul D. Nelson" <ultrono@HIDDEN> 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@HIDDEN:
bug#76615; Package auctex. Full text available.

Message received at 76615 <at> debbugs.gnu.org:


Received: (at 76615) by debbugs.gnu.org; 1 Mar 2025 07:34:11 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Mar 01 02:34:11 2025
Received: from localhost ([127.0.0.1]:59880 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1toHMQ-0007hJ-92
	for submit <at> debbugs.gnu.org; Sat, 01 Mar 2025 02:34:11 -0500
Received: from mail-ed1-x52f.google.com ([2a00:1450:4864:20::52f]:46293)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <ultrono@HIDDEN>) id 1toHMN-0007gT-8P
 for 76615 <at> debbugs.gnu.org; Sat, 01 Mar 2025 02:34:08 -0500
Received: by mail-ed1-x52f.google.com with SMTP id
 4fb4d7f45d1cf-5e4b410e48bso4306660a12.0
 for <76615 <at> debbugs.gnu.org>; Fri, 28 Feb 2025 23:34:07 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1740814441; x=1741419241; darn=debbugs.gnu.org;
 h=mime-version:message-id:date:in-reply-to:subject:cc:to:from:from:to
 :cc:subject:date:message-id:reply-to;
 bh=B8Tj/oAE4uZBKQQBHFGcWhgj5dWM7W0L/Ox0K1p0bzE=;
 b=JQpZYYBEmo5f145U12EN2G3ifp1X02/4huaDJY55osbriJH0Y4wxCyvqb/osPrcy1T
 wCRPqZowD9JObQXX9xgAsGCyaqAtLbCTQ5aZIRbMyKWUbSqXHxt6moGF7uGyOMZlHlCZ
 hddNldM8sVm5nGx0X9apn88Z7bmSWyriu6sVsZ42dozYVOenShCfN6Ije+ZM6J234gau
 UodIzl5LfOKO0mh8Q9WJy7j+Varspwl86dGCkhdDU3fV4ZxqZ4rBcvMzjU8Lv/ydRVcf
 D49zIOiubdVjcBJiiQbadhNMuS032vRV2EK3g3/F4w8VtCypLlyg9cRHgqlQ+KsVo+Ae
 o4pQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1740814441; x=1741419241;
 h=mime-version:message-id:date:in-reply-to:subject:cc:to:from
 :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
 bh=B8Tj/oAE4uZBKQQBHFGcWhgj5dWM7W0L/Ox0K1p0bzE=;
 b=Ck8tXvOEfosr3+WDYvSc0aCZEv5MosU/XPQE0/h6kF+ob4h0HmECdAN6jtGSZQ67C+
 CDItdhZkFdiN790H9GGKO+SPUn7DuUqfSpEKR9BIZyAp4xq7DpiiqWKIm2Q7CHsd/ISd
 +RBp/jnnymZb+xwDuytpdEIY2dTGKl9sjcwwAAmoGThgY+7r6g6VWE0/xMeXzpLyK7Qe
 YfDGuJJcJ0sEx8XOVf/hm8Kfj74WSjn1LcZnDvhf3DE67+1LyobFjiVbUm4hIzfc7yIk
 ttyaCJF/E3fwJ3+2wjQK/pUZaeV52STFZ5v3F6YxafYEx0Tqpaob8aLcEEQpgns/DPyc
 eqlQ==
X-Forwarded-Encrypted: i=1;
 AJvYcCVWyjcC2DX6B0b9ThOreOgrWNwZnbS8r5ttEkMt/PD19c9CknEiEDtvI8DDBE4LdZqvrK+BnA==@debbugs.gnu.org
X-Gm-Message-State: AOJu0YyY+2+PuiVsksVeRnWes3W6tAPx9+rXGpr+9YJIoJzHehgpl0pi
 cTN0j9DSlAkqELYSjv/bjkEHngOtFIMVkZwyDLOR5AURkd+5PDTb
X-Gm-Gg: ASbGncuhUKybo0bqRAEZW6ta8Wim00mUci7i+hzCkzxQjtYUgCZcTYpRVA02VZHtsku
 qF0cArAMy/TH4hshnfS8xB5kJvfCXxKU7NYMPAklavpSj82jvGSO1fEzv0vthz3W1NSRClWDvGj
 X8La1JMcHqSSD1zdatkRGDFRk2efzhshN0p2O+0+Oy+RmIMMDfsL0iKfx8c7sNWHqU23lM3B7vx
 Ps2G98iSsQR0jSy7IXu+PZcv1lnCseyq33Y0S3OPrAk//hCJzP2DTf+dXc5Ux+ExF2WJJWxYzq2
 Ukb73QdROc/Pfrmxn88fXFgRX+qrGq9gmq6WANWvNEaTOdeJobKiUvg3vd8oHEy4coVYlYzYO/c
 x5T5zUzjTJYA=
X-Google-Smtp-Source: AGHT+IHLsTbRZg6O/LdqVALkDFBGvQxKH3US1cwkKjXmUwqIY5BX4IhJIfRCXMjh4dgDwBNKQevosQ==
X-Received: by 2002:a05:6402:26ce:b0:5de:a6a8:5ebc with SMTP id
 4fb4d7f45d1cf-5e4d6ad41femr5775538a12.3.1740814440360; 
 Fri, 28 Feb 2025 23:34:00 -0800 (PST)
Received: from localhost (0x573d669a.static.cust.fastspeed.dk. [87.61.102.154])
 by smtp.gmail.com with UTF8SMTPSA id
 4fb4d7f45d1cf-5e4c3b4a81asm3612434a12.9.2025.02.28.23.33.58
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 28 Feb 2025 23:33:59 -0800 (PST)
From: "Paul D. Nelson" <ultrono@HIDDEN>
To: Ikumi Keita <ikumi@HIDDEN>
Subject: Re: bug#76615: 14.0.9; error with amsmath style hooks
In-Reply-To: <55236.1740800359@localhost> (message from Ikumi Keita on Sat,
 01 Mar 2025 12:39:19 +0900)
Date: Sat, 01 Mar 2025 08:33:57 +0100
Message-ID: <uxsg7tbjuljjbu.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 76615
Cc: arash@HIDDEN, 76615 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

--=-=-=
Content-Type: text/plain


>> 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).


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment; filename=changes.patch
Content-Description: changes

diff --git a/style/alphanum.el b/style/alphanum.el
index 318281b4..37ff8f8b 100644
--- a/style/alphanum.el
+++ b/style/alphanum.el
@@ -92,10 +92,11 @@
    ;; this won't work in multifile documents, but at least there is
    ;; something.
 
-   (if (fboundp 'reftex-add-section-levels)
-       (reftex-add-section-levels
-        '(("toc" .  reftex-get-section-level-alphanum)
-          ("sub" .  reftex-get-section-level-alphanum)))))
+   (when (and buffer-file-truename
+              (fboundp 'reftex-add-section-levels))
+     (reftex-add-section-levels
+      '(("toc" .  reftex-get-section-level-alphanum)
+        ("sub" .  reftex-get-section-level-alphanum)))))
  TeX-dialect)
 
 ;; Local Variables:
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))
diff --git a/style/beamer.el b/style/beamer.el
index fe1e4611..4afa2973 100644
--- a/style/beamer.el
+++ b/style/beamer.el
@@ -605,7 +605,8 @@ also be a string.  Then the length of the string is used."
     (insert LaTeX-title TeX-grcl)
     (LaTeX-newline)
     ;; If RefTeX is available, tell it that we've just made a new section
-    (and (fboundp 'reftex-notice-new-section)
+    (and buffer-file-truename
+         (fboundp 'reftex-notice-new-section)
          (reftex-notice-new-section))))
 
 (defvar LaTeX-beamer-class-options-list
diff --git a/style/biblatex.el b/style/biblatex.el
index 8b2c6b7a..c8d58740 100644
--- a/style/biblatex.el
+++ b/style/biblatex.el
@@ -672,7 +672,8 @@ for citation keys."
 
    ;; Tell RefTeX: If package option `natbib' is given, activate that
    ;; format, otherwise stick with `biblatex':
-   (when (and LaTeX-reftex-cite-format-auto-activate
+   (when (and buffer-file-truename
+              LaTeX-reftex-cite-format-auto-activate
               (fboundp 'reftex-set-cite-format))
      (if (or (LaTeX-provided-package-options-member "biblatex" "natbib")
              (LaTeX-provided-package-options-member "biblatex" "natbib=true"))
@@ -708,22 +709,22 @@ for citation keys."
    ;;; Preamble Options
    LaTeX-biblatex-executebibliographyoptions-options
    '(;;; Load-time Options
-    ("backend" ("biber" "bibtex" "bibtexu" "bibtex8"))
-    ("style" BibLaTeX-global-style-files)
-    ("bibstyle" BibLaTeX-global-style-files)
-    ("citestyle" BibLaTeX-global-style-files)
-    ("natbib" ("true" "false"))
-    ("mcite" ("true" "false"))
+     ("backend" ("biber" "bibtex" "bibtexu" "bibtex8"))
+     ("style" BibLaTeX-global-style-files)
+     ("bibstyle" BibLaTeX-global-style-files)
+     ("citestyle" BibLaTeX-global-style-files)
+     ("natbib" ("true" "false"))
+     ("mcite" ("true" "false"))
     ;;; Entry Options
-    ;; Preamble/Type/Entry Options
-    ("useauthor" ("true" "false"))
-    ("useeditor" ("true" "false"))
-    ("usetranslator" ("true" "false"))
-    ("useprefix" ("true" "false"))
-    ("indexing" ("true" "false" "cite" "bib"))
-    ;; Type/Entry Options are not available globally.
-    ;; Legacy Options (deprecated)
-    ("openbib")))
+     ;; Preamble/Type/Entry Options
+     ("useauthor" ("true" "false"))
+     ("useeditor" ("true" "false"))
+     ("usetranslator" ("true" "false"))
+     ("useprefix" ("true" "false"))
+     ("indexing" ("true" "false" "cite" "bib"))
+     ;; Type/Entry Options are not available globally.
+     ;; Legacy Options (deprecated)
+     ("openbib")))
   "Package options for the biblatex package.")
 
 (defun LaTeX-biblatex-package-options nil
diff --git a/style/breqn.el b/style/breqn.el
index f2784bf9..5b4db486 100644
--- a/style/breqn.el
+++ b/style/breqn.el
@@ -102,7 +102,8 @@ The keys \"label\" and \"labelprefix\" are omitted.")
    ;; dseries   == equation   -- dseries* == unnumbered
    ;; dgroup    == align      -- dgroup*  == unnumbered
    ;; darray    == eqnarray   -- darray*  == unnumbered
-   (when (fboundp 'reftex-add-label-environments)
+   (when (and buffer-file-truename
+              (fboundp 'reftex-add-label-environments))
      (dolist (env '("dmath" "dseries" "dgroup"))
        (reftex-add-label-environments `((,env ?e nil nil t))))
      (reftex-add-label-environments '(("darray" ?e nil nil eqnarray-like))))
diff --git a/style/cleveref.el b/style/cleveref.el
index 129d4ce1..ceed42d6 100644
--- a/style/cleveref.el
+++ b/style/cleveref.el
@@ -209,7 +209,8 @@ string."
                               'function))
 
    ;; Activate RefTeX reference style.
-   (and LaTeX-reftex-ref-style-auto-activate
+   (and buffer-file-truename
+        LaTeX-reftex-ref-style-auto-activate
         (fboundp 'reftex-ref-style-activate)
         (reftex-ref-style-activate "Cleveref")))
  TeX-dialect)
diff --git a/style/empheq.el b/style/empheq.el
index 31c22eaf..ffbb8e92 100644
--- a/style/empheq.el
+++ b/style/empheq.el
@@ -252,7 +252,8 @@ number of ampersands if possible."
    (add-to-list 'LaTeX-item-list '("empheq" . LaTeX-empheq-item-equation) t)
 
    ;; Reftex support: Use `reftex-add-label-environments'
-   (when (fboundp 'reftex-add-label-environments)
+   (when (and buffer-file-truename
+              (fboundp 'reftex-add-label-environments))
      (reftex-add-label-environments '(("empheq" ?e nil nil t))))
 
    (TeX-add-symbols
@@ -398,7 +399,8 @@ number of ampersands if possible."
          (add-to-list 'LaTeX-label-alist `(,env . LaTeX-amsmath-label) t)))
 
      ;; RefTeX support: Add original definitions with `reftex-add-label-environments'
-     (when (fboundp 'reftex-add-label-environments)
+     (when (and buffer-file-truename
+                (fboundp 'reftex-add-label-environments))
        (reftex-add-label-environments
         '(("AmSalign"     ?e nil nil eqnarray-like)
           ("AmSequation"  ?e nil nil t)
diff --git a/style/exam.el b/style/exam.el
index 64179192..ee250dae 100644
--- a/style/exam.el
+++ b/style/exam.el
@@ -87,7 +87,8 @@ Arguments NAME and TYPE are the same as for the function
        (add-to-list 'LaTeX-label-alist
                     (cons env 'LaTeX-exam-label))
        ;; to RefTeX with `reftex-add-label-environments'
-       (when (fboundp 'reftex-add-label-environments)
+       (when (and buffer-file-truename
+                  (fboundp 'reftex-add-label-environments))
          (reftex-add-label-environments
           `((,env ,LaTeX-exam-reftex-quick-id-key ,LaTeX-exam-label
                   "~\\ref{%s}" nil
diff --git a/style/fancyref.el b/style/fancyref.el
index d2d87bf5..6b71a7cd 100644
--- a/style/fancyref.el
+++ b/style/fancyref.el
@@ -101,7 +101,8 @@
      (font-latex-add-keywords '(("fref" "[{") ("Fref" "[{")) 'reference))
 
    ;; Activate RefTeX reference style.
-   (and LaTeX-reftex-ref-style-auto-activate
+   (and buffer-file-truename
+        LaTeX-reftex-ref-style-auto-activate
         (fboundp 'reftex-ref-style-activate)
         (reftex-ref-style-activate "Fancyref")))
  TeX-dialect)
diff --git a/style/harvard.el b/style/harvard.el
index 36e2e471..431e72b5 100644
--- a/style/harvard.el
+++ b/style/harvard.el
@@ -101,7 +101,8 @@
                LaTeX-item-list))
 
    ;; Tell RefTeX
-   (when (and LaTeX-reftex-cite-format-auto-activate
+   (when (and buffer-file-truename
+              LaTeX-reftex-cite-format-auto-activate
               (fboundp 'reftex-set-cite-format))
      (reftex-set-cite-format 'harvard)))
  TeX-dialect)
diff --git a/style/hyperref.el b/style/hyperref.el
index 868acd33..03f7575f 100644
--- a/style/hyperref.el
+++ b/style/hyperref.el
@@ -341,7 +341,8 @@
          (TeX-run-style-hooks "backref"))))
 
    ;; Activate RefTeX reference style.
-   (and LaTeX-reftex-ref-style-auto-activate
+   (and buffer-file-truename
+        LaTeX-reftex-ref-style-auto-activate
         (fboundp 'reftex-ref-style-activate)
         (reftex-ref-style-activate "Hyperref")))
  TeX-dialect)
diff --git a/style/imakeidx.el b/style/imakeidx.el
index 0d6a626c..ae0efce5 100644
--- a/style/imakeidx.el
+++ b/style/imakeidx.el
@@ -93,7 +93,8 @@
          (append
           '(("|see{\\([^{}\n\r]*\\)" 1 LaTeX-index-entry-list))
           TeX-complete-list))
-   (and (fboundp 'reftex-add-index-macros)
+   (and buffer-file-truename
+        (fboundp 'reftex-add-index-macros)
         (reftex-add-index-macros '(default)))
 
    ;; Fontification
diff --git a/style/index.el b/style/index.el
index 1e5657e6..9e370fad 100644
--- a/style/index.el
+++ b/style/index.el
@@ -75,7 +75,8 @@
           TeX-complete-list))
 
    ;; RefTeX support
-   (and (fboundp 'reftex-add-index-macros)
+   (and buffer-file-truename
+        (fboundp 'reftex-add-index-macros)
         (reftex-add-index-macros '(index))))
  TeX-dialect)
 
diff --git a/style/jurabib.el b/style/jurabib.el
index 0aa6966d..532a3cfa 100644
--- a/style/jurabib.el
+++ b/style/jurabib.el
@@ -153,7 +153,8 @@
                                 'variable))
 
      ;; Tell RefTeX (Thanks, Carsten)
-     (when (and LaTeX-reftex-cite-format-auto-activate
+     (when (and buffer-file-truename
+                LaTeX-reftex-cite-format-auto-activate
                 (fboundp 'reftex-set-cite-format))
        ;; Check if RefTeX supports jurabib.
        (if (assoc 'jurabib reftex-cite-format-builtin)
diff --git a/style/listings.el b/style/listings.el
index e03b8216..4738d687 100644
--- a/style/listings.el
+++ b/style/listings.el
@@ -349,7 +349,8 @@
                                       (LaTeX-extract-key-value-label))
                              1 LaTeX-auto-label))
       ;; Tell RefTeX
-      (when (fboundp 'reftex-add-label-environments)
+      (when (and buffer-file-truename
+                 (fboundp 'reftex-add-label-environments))
         (reftex-add-label-environments
          `((,env ?l "lst:" "~\\ref{%s}"
                  LaTeX-keyval-caption-reftex-context-function
@@ -431,7 +432,8 @@
    ;; RefTeX support lstlistings environment via
    ;; `reftex-label-alist-builtin'.  We add the same thing here only
    ;; with our function as 5th element:
-   (when (fboundp 'reftex-add-label-environments)
+   (when (and buffer-file-truename
+              (fboundp 'reftex-add-label-environments))
      (reftex-add-label-environments
       '(("lstlisting" ?l "lst:" "~\\ref{%s}"
          LaTeX-keyval-caption-reftex-context-function
diff --git a/style/makeidx.el b/style/makeidx.el
index 680a16b7..0f7bbb3e 100644
--- a/style/makeidx.el
+++ b/style/makeidx.el
@@ -45,7 +45,8 @@
           TeX-complete-list))
 
    ;; RefTeX support
-   (and (fboundp 'reftex-add-index-macros)
+   (and buffer-file-truename
+        (fboundp 'reftex-add-index-macros)
         (reftex-add-index-macros '(default)))
 
    ;; Fontification
diff --git a/style/mathtools.el b/style/mathtools.el
index 853093d3..55039731 100644
--- a/style/mathtools.el
+++ b/style/mathtools.el
@@ -145,7 +145,8 @@
                    `(,env . LaTeX-item-equation) t)
       (add-to-list 'LaTeX-label-alist
                    `(,env . LaTeX-amsmath-label) t)
-      (when (fboundp 'reftex-add-label-environments)
+      (when (and buffer-file-truename
+                 (fboundp 'reftex-add-label-environments))
         (reftex-add-label-environments `((,env ?e nil nil t)))))))
 
 (add-hook 'TeX-auto-prepare-hook #'LaTeX-mathtools-auto-prepare t)
@@ -473,7 +474,8 @@ Put line break macro on the last line.  Next, insert an ampersand."
                  LaTeX-label-alist))
 
    ;; RefTeX support: Add env's with `reftex-add-label-environments'
-   (when (fboundp 'reftex-add-label-environments)
+   (when (and buffer-file-truename
+              (fboundp 'reftex-add-label-environments))
      (let ((envs '(("lgathered"  ?e nil nil t)
                    ("rgathered"  ?e nil nil t)
                    ("multlined"  ?e nil nil t))))
diff --git a/style/minted.el b/style/minted.el
index 655e9a4f..94a2aa1a 100644
--- a/style/minted.el
+++ b/style/minted.el
@@ -440,7 +440,8 @@ a list of strings."
      (add-to-list (make-local-variable 'LaTeX-indent-environment-list)
                   '("listing" current-indentation) t)
      (add-to-list 'LaTeX-label-alist '("listing" . LaTeX-listing-label) t)
-     (when (fboundp 'reftex-add-label-environments)
+     (when (and buffer-file-truename
+                (fboundp 'reftex-add-label-environments))
        (reftex-add-label-environments
         '(("listing" ?l "lst:" "~\\ref{%s}" caption nil nil)))))
 
diff --git a/style/minted2.el b/style/minted2.el
index 687b195c..08ddcc09 100644
--- a/style/minted2.el
+++ b/style/minted2.el
@@ -421,7 +421,8 @@ a list of strings."
      (add-to-list (make-local-variable 'LaTeX-indent-environment-list)
                   '("listing" current-indentation) t)
      (add-to-list 'LaTeX-label-alist '("listing" . LaTeX-listing-label) t)
-     (when (fboundp 'reftex-add-label-environments)
+     (when (and buffer-file-truename
+                (fboundp 'reftex-add-label-environments))
        (reftex-add-label-environments
         '(("listing" ?l "lst:" "~\\ref{%s}" caption nil nil)))))
 
diff --git a/style/multind.el b/style/multind.el
index a4e921bd..0bad853b 100644
--- a/style/multind.el
+++ b/style/multind.el
@@ -59,7 +59,8 @@
           TeX-complete-list))
 
    ;; RefTeX support
-   (and (fboundp 'reftex-add-index-macros)
+   (and buffer-file-truename
+        (fboundp 'reftex-add-index-macros)
         (reftex-add-index-macros '(multind)))
 
    ;; Fontification
diff --git a/style/natbib.el b/style/natbib.el
index e04de458..f08565d0 100644
--- a/style/natbib.el
+++ b/style/natbib.el
@@ -168,7 +168,8 @@
                               'function))
 
    ;; Tell RefTeX
-   (when (and LaTeX-reftex-cite-format-auto-activate
+   (when (and buffer-file-truename
+              LaTeX-reftex-cite-format-auto-activate
               (fboundp 'reftex-set-cite-format))
      (reftex-set-cite-format 'natbib)))
  TeX-dialect)
diff --git a/style/newfloat.el b/style/newfloat.el
index e3824a82..2fff45b4 100644
--- a/style/newfloat.el
+++ b/style/newfloat.el
@@ -117,13 +117,15 @@ If `caption.el' is loaded, add the new floating environment to
       (cond ((string-equal type "figure")
              (LaTeX-add-environments `(,flt LaTeX-env-figure))
              (add-to-list 'LaTeX-label-alist `(,flt . LaTeX-figure-label) t)
-             (when (fboundp 'reftex-add-label-environments)
+             (when (and buffer-file-truename
+                      (fboundp 'reftex-add-label-environments))
                (reftex-add-label-environments
                 `((,flt ?f ,LaTeX-figure-label "~\\ref{%s}" caption nil nil)))))
             ((string-equal type "table")
              (LaTeX-add-environments `(,flt LaTeX-env-figure))
              (add-to-list 'LaTeX-label-alist `(,flt . LaTeX-table-label) t)
-             (when (fboundp 'reftex-add-label-environments)
+             (when (and buffer-file-truename
+                      (fboundp 'reftex-add-label-environments))
                (reftex-add-label-environments
                 `((,flt ?t ,LaTeX-table-label "~\\ref{%s}" caption nil nil)))))
             ((string-equal type "verbatim")
@@ -131,7 +133,8 @@ If `caption.el' is loaded, add the new floating environment to
              (add-to-list (make-local-variable 'LaTeX-indent-environment-list)
                           `(,flt current-indentation) t)
              (add-to-list 'LaTeX-label-alist `(,flt . LaTeX-listing-label) t)
-             (when (fboundp 'reftex-add-label-environments)
+             (when (and buffer-file-truename
+                      (fboundp 'reftex-add-label-environments))
                (reftex-add-label-environments
                 `((,flt ?l "lst:" "~\\ref{%s}" caption nil nil)))))
             (t
diff --git a/style/subcaption.el b/style/subcaption.el
index 4ae2975d..2c6e98c5 100644
--- a/style/subcaption.el
+++ b/style/subcaption.el
@@ -215,7 +215,8 @@ outer-pos adjusted."
    (add-to-list 'LaTeX-label-alist '("subtable" . LaTeX-table-label) t)
 
    ;; Introduce env's to RefTeX if loaded
-   (when (fboundp 'reftex-add-label-environments)
+   (when (and buffer-file-truename
+              (fboundp 'reftex-add-label-environments))
      (reftex-add-label-environments
       `(("subfigure" ?f ,LaTeX-figure-label "~\\ref{%s}" caption)
         ("subtable"  ?t ,LaTeX-table-label  "~\\ref{%s}" caption))))
diff --git a/style/varioref.el b/style/varioref.el
index e7f95f7f..4c9ffb26 100644
--- a/style/varioref.el
+++ b/style/varioref.el
@@ -88,7 +88,8 @@
                               'reference))
 
    ;; Activate RefTeX reference style.
-   (and LaTeX-reftex-ref-style-auto-activate
+   (and buffer-file-truename
+        LaTeX-reftex-ref-style-auto-activate
         (fboundp 'reftex-ref-style-activate)
         (reftex-ref-style-activate "Varioref")))
  TeX-dialect)

--=-=-=--




Information forwarded to bug-auctex@HIDDEN:
bug#76615; Package auctex. Full text available.

Message received at 76615 <at> debbugs.gnu.org:


Received: (at 76615) by debbugs.gnu.org; 1 Mar 2025 03:39:27 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Feb 28 22:39:26 2025
Received: from localhost ([127.0.0.1]:57396 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1toDhG-0004Ps-LV
	for submit <at> debbugs.gnu.org; Fri, 28 Feb 2025 22:39:26 -0500
Received: from smtp1a.inetd.co.jp ([210.129.88.11]:38970)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <ikumi@HIDDEN>)
 id 1toDhD-0004PR-Ux
 for 76615 <at> debbugs.gnu.org; Fri, 28 Feb 2025 22:39:25 -0500
Received: from localhost (42-144-34-247.rev.home.ne.jp [42.144.34.247])
 by smtp1a.inetd.co.jp (Postfix) with ESMTPSA id D44DA5C;
 Sat,  1 Mar 2025 12:39:20 +0900 (JST)
From: Ikumi Keita <ikumi@HIDDEN>
To: "Paul D. Nelson" <ultrono@HIDDEN>
Subject: Re: bug#76615: 14.0.9; error with amsmath style hooks
In-reply-to: <uxsg7tplj2jbod.fsf@HIDDEN>
References: <uxsg7tplj2jbod.fsf@HIDDEN>
Comments: In-reply-to "Paul D. Nelson" <ultrono@HIDDEN>
 message dated "Fri, 28 Feb 2025 17:06:58 +0100."
X-Mailer: MH-E 8.6+git; nmh 1.8; Emacs 29.4
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-ID: <55235.1740800359.1@localhost>
Date: Sat, 01 Mar 2025 12:39:19 +0900
Message-ID: <55236.1740800359@localhost>
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 76615
Cc: arash@HIDDEN, 76615 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Hi Paul,

>>>>> "Paul D. Nelson" <ultrono@HIDDEN> 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@HIDDEN:
bug#76615; Package auctex. Full text available.

Message received at 76615 <at> debbugs.gnu.org:


Received: (at 76615) by debbugs.gnu.org; 28 Feb 2025 16:07:12 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Feb 28 11:07:12 2025
Received: from localhost ([127.0.0.1]:51396 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1to2tL-0005hH-AU
	for submit <at> debbugs.gnu.org; Fri, 28 Feb 2025 11:07:12 -0500
Received: from mail-ed1-x52b.google.com ([2a00:1450:4864:20::52b]:55696)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <ultrono@HIDDEN>) id 1to2tH-0005gN-RK
 for 76615 <at> debbugs.gnu.org; Fri, 28 Feb 2025 11:07:08 -0500
Received: by mail-ed1-x52b.google.com with SMTP id
 4fb4d7f45d1cf-5dedd4782c6so4188832a12.3
 for <76615 <at> debbugs.gnu.org>; Fri, 28 Feb 2025 08:07:07 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1740758821; x=1741363621; darn=debbugs.gnu.org;
 h=mime-version:message-id:date:in-reply-to:subject:cc:to:from:from:to
 :cc:subject:date:message-id:reply-to;
 bh=Qz/0E2f6UYvJOJc3nX0N2sADjs8Wfwa5wovo6OPRdRw=;
 b=QmCAsAG+nY22nS8lzMTlzPV6m/AkTqTuxirKXsc+3L6NAGUno9mMQP3OaSSmqUUZ7c
 CSbePVPh3h0HN8ZyiVZnJ+eyahNfgRtXvDIM9QfeK+v6pIdPVpQ8eFM8t4e0+ZlitQUT
 FBce4f/Q44C8Duh092C7SvBVB9/TUqQGPDzvgRxdxT2j8+35vHvq7htd3Xa/LNi55H1v
 g1C3InCkJF35JeUgLDVyYjAi4VMZhRTS7HmuMq0LhpH8TZdzFixIB9rj5PAmJHfmb+cB
 4gp083BbrOKTkWVNIWvgqmAF8Nf/eH07JUDVW6oZ24yZMFrKWLLSskarEltB9QYyfs+0
 ZlOg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1740758821; x=1741363621;
 h=mime-version:message-id:date:in-reply-to:subject:cc:to:from
 :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
 bh=Qz/0E2f6UYvJOJc3nX0N2sADjs8Wfwa5wovo6OPRdRw=;
 b=DgKXmLluCc5NaVbVqoTGzvfW/Am/6LkDXXvsk9rXjvui8+tzOY4FRGenYui3+BmdZA
 0jvmjn238zTbEM62Xi8eqZCOWQIbW2OzHJv+gXSVASFVhYKNZ5N6Y0J/jLDq5l8UU+8J
 0g8VI1WqEENfcK//TBySyFjIyO4X+nFksoAZ/YuKyQOQxYrwRo6gUjWNYcCIypLPqpkd
 p/T0wm9b+m334YLDBbCcBfRITHPRRNCqFDtOjeRsWoHjMAxb+L6WNl2ChX0Wmu1UjKKc
 zQEmzg6p+LMD75hRtUlG1r8GOaePJ1sJDi5OqFkSk2pu4ajIw/6bG5fV/ZINsa55Oe7K
 73Ug==
X-Forwarded-Encrypted: i=1;
 AJvYcCW8omzTMrUaIlEMn4zyqYVpMCwo2mn0q+4GQ8QzfOXS0pwnpMfe8g3lvAUUeaupT59WCyOMqg==@debbugs.gnu.org
X-Gm-Message-State: AOJu0YzYgioAy6YpMx2J2YrNAxykjGiwTvPd3VuRrlVcRxwywdTTcjJC
 diwGRPD+wOlhSRHV6cVvPQTaUjR6fg7IqlRp1XjFpNsOwatJeVQ5MllZGcKQ6i4=
X-Gm-Gg: ASbGncvefHtfXSX1iFXI6qdziu8MOKvPMgCNdA50FOvec+8giWFz1nA/De+jsQV3Jat
 1KtD+hkD92+VP9QmOf+quinGCFP618mQkRgThY26w6ld94fcT8lbfgvDXIK9heWc5pUyVWiEMLv
 reYh0olbgxYtNmCrOvxvO3H+0rDbXvlXDQwIENevPGsoc3mx/MO/YnL45FrrYvHbGDWF9OAPOIm
 WIM8SVbYBJwzL4QvsXK7KlOWImsogR0UywVkGDgJj849ZDby7CbTeQvbIvvKH3oW80L5HJxElOH
 lyF6T3p1TQLR6KBErIG0H1+dPmH3R/bMBNzHU4S0KjPg+wtE6MYN
X-Google-Smtp-Source: AGHT+IGS1K+7UZf/T9+iqZVdKZlwfVJ82mmetirD00DuR2bK3nWTtbMdIn1VUJ2hxWqV+2/dqyz/cA==
X-Received: by 2002:a05:6402:5242:b0:5e4:9348:72d4 with SMTP id
 4fb4d7f45d1cf-5e4d6b6fccamr3696700a12.24.1740758820510; 
 Fri, 28 Feb 2025 08:07:00 -0800 (PST)
Received: from localhost (users-1190.st.net.au.dk. [130.225.0.251])
 by smtp.gmail.com with UTF8SMTPSA id
 4fb4d7f45d1cf-5e4c3b4aad0sm2699291a12.2.2025.02.28.08.06.58
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 28 Feb 2025 08:06:59 -0800 (PST)
From: "Paul D. Nelson" <ultrono@HIDDEN>
To: Ikumi Keita <ikumi@HIDDEN>
Subject: Re: bug#76615: 14.0.9; error with amsmath style hooks
In-Reply-To: <54589.1740758226@localhost> (message from Ikumi Keita on Sat,
 01 Mar 2025 00:57:06 +0900)
Date: Fri, 28 Feb 2025 17:06:58 +0100
Message-ID: <uxsg7tplj2jbod.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 76615
Cc: arash@HIDDEN, 76615 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

--=-=-=
Content-Type: text/plain

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@HIDDEN> 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


--=-=-=
Content-Type: text/plain
Content-Disposition: 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@HIDDEN:
bug#76615; Package auctex. Full text available.

Message received at 76615 <at> debbugs.gnu.org:


Received: (at 76615) by debbugs.gnu.org; 28 Feb 2025 15:57:18 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Feb 28 10:57:18 2025
Received: from localhost ([127.0.0.1]:51268 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1to2jm-0004jk-0V
	for submit <at> debbugs.gnu.org; Fri, 28 Feb 2025 10:57:18 -0500
Received: from smtp1a.inetd.co.jp ([210.129.88.11]:38182)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <ikumi@HIDDEN>)
 id 1to2je-0004iY-SL
 for 76615 <at> debbugs.gnu.org; Fri, 28 Feb 2025 10:57:11 -0500
Received: from localhost (42-144-34-247.rev.home.ne.jp [42.144.34.247])
 by smtp1a.inetd.co.jp (Postfix) with ESMTPSA id B4EDC6A;
 Sat,  1 Mar 2025 00:57:07 +0900 (JST)
From: Ikumi Keita <ikumi@HIDDEN>
To: "Paul D. Nelson" <ultrono@HIDDEN>, Arash Esbati <arash@HIDDEN>
Subject: Re: bug#76615: 14.0.9; error with amsmath style hooks
In-reply-to: <m21pvi8q1p.fsf@HIDDEN>
References: <uxsg7tcyf3nsws.fsf@HIDDEN> <m21pvi8q1p.fsf@HIDDEN>
Comments: In-reply-to Arash Esbati <arash@HIDDEN>
 message dated "Fri, 28 Feb 2025 08:52:02 +0100."
X-Mailer: MH-E 8.6+git; nmh 1.8; Emacs 29.4
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-ID: <54588.1740758226.1@localhost>
Date: Sat, 01 Mar 2025 00:57:06 +0900
Message-ID: <54589.1740758226@localhost>
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 76615
Cc: 76615 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Hi Paul and Arash,

>>>>> Arash Esbati <arash@HIDDEN> writes:
> "Paul D. Nelson" <ultrono@HIDDEN> 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@HIDDEN> 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@HIDDEN:
bug#76615; Package auctex. Full text available.

Message received at 76615 <at> debbugs.gnu.org:


Received: (at 76615) by debbugs.gnu.org; 28 Feb 2025 15:54:24 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Feb 28 10:54:24 2025
Received: from localhost ([127.0.0.1]:51218 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1to2gy-0004OC-82
	for submit <at> debbugs.gnu.org; Fri, 28 Feb 2025 10:54:24 -0500
Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531]:49559)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <ultrono@HIDDEN>) id 1to2gw-0004NT-82
 for 76615 <at> debbugs.gnu.org; Fri, 28 Feb 2025 10:54:22 -0500
Received: by mail-ed1-x531.google.com with SMTP id
 4fb4d7f45d1cf-5e058ca6806so3529572a12.3
 for <76615 <at> debbugs.gnu.org>; Fri, 28 Feb 2025 07:54:22 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1740758055; x=1741362855; darn=debbugs.gnu.org;
 h=mime-version:message-id:date:in-reply-to:subject:cc:to:from:from:to
 :cc:subject:date:message-id:reply-to;
 bh=9t9NtdG5dWdjGMq57UNgeF+kVXWVdvDNgaNsOb0ZuTA=;
 b=lHddxBLVEgmiQpdw6pNebrVyWZ+OifBimq4xAMleL++dfwpxh/xlQgDmCknpdhKqAe
 6Gqs7n3u/DFO7xJTLyAxXobDlt4Cpv+6L46Mgc7yDZvih0gHNZT3h5woYRz0s3t6cW0Z
 j9H1qJynOOMSN9EEcstf2mI4iIcwhg8U7TrsbFoWrkyBT9W95tEP+qPhYltTBdJ/MFu8
 3xVwVPNRgWTvWIF/oTCPHsZ7ImwIxfyzfWL+bsCkmRF8jTe1UkpG8G6wiz37lZKkbW6F
 qs+twTIjPkIiOnlEDtzOj2+/boxY3VV+5/qVCyOyjcrPEdqZre37RisvwEljl2krs4zF
 U3ow==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1740758055; x=1741362855;
 h=mime-version:message-id:date:in-reply-to:subject:cc:to:from
 :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
 bh=9t9NtdG5dWdjGMq57UNgeF+kVXWVdvDNgaNsOb0ZuTA=;
 b=vLg/SUUcMoXJLu+7RkwNQJ+74y++VC9Wwuo+0s2Ycnc2MxiJ0nOPlyGk5+OXs27SxC
 S/8AKkswcGzy12qX1FzTYK9q77F7plRv+WuQf9LG7RHPLxS2p7yos5a4HCtVLFdPbN99
 JHXgGyqhvGKd2tjRfIrP408IH1/XP85ip1WgUKYtMfVzqLzgzCkQIgkn6jIeeVyurCT7
 NWkTmxx/xYT8M06T22Hh9xuJFDg20WgoWX11EvqPvopHylA+f/H6yernny1IJVl2z4rm
 Z7UTzL9D52XvSZyPTVle9FsGA2zyrvwoESL7VQrY6LhnVlJ5RtfVjW1wnN/XGz8ZstNl
 d31A==
X-Forwarded-Encrypted: i=1;
 AJvYcCU5bjylURmjPu3qAVl5M5he7XxjpratL24lv5MMwjcNpVmbVKOhrZeTbvQsTcxmMcaNqQReIA==@debbugs.gnu.org
X-Gm-Message-State: AOJu0YwKvKv5PxzvOK+1XTlaOgv/lAlQ4AteQx/2ueJZesv7hmPqLZuD
 GChFHytqYMCpCF2KNa60NsAzGKWhD+4DE9II6IUZgwIHloegoiSC
X-Gm-Gg: ASbGncvejHy8QY2vGFp0VB/VnVIqF2He74MWguFYZcItMKq0gya4c6dgRBinaNXZDvx
 Vninyme+tzleRsZsX7urJ58QktbZWdJZp5hWkUPuE0hMP9mDHiLwMA5Ycgkw8PCU7x10uZx8ot0
 VyGr8xg4SeZ/nTI8S/ylEkmVd3ZPqpVxyFrblh8b0CmR/pg5mPCRHPhtgYr304gxhJCXXoHRnoG
 Pkm2lcpTAQwFC0GDNIWqOPtTeCcl0p0bUeyiq1JbX4sIqW8q3+zO0aVjIb+tygFpP7tjlg0vLPg
 t1kjVrnsZXYd17zmg/MOQ5Dbq4phqJCQ0Gf7lC9q1fgeaXpx4f3Q
X-Google-Smtp-Source: AGHT+IGj0fzkem7f9E3A3Cs64jiC0j1qhspVtHrVRjlOEGiBFunbNQLaTzHIcoUnx3RzxsfThP5bDQ==
X-Received: by 2002:a17:907:7ba7:b0:ab7:83c2:bdb7 with SMTP id
 a640c23a62f3a-abf26826359mr482800166b.49.1740758055117; 
 Fri, 28 Feb 2025 07:54:15 -0800 (PST)
Received: from localhost (users-1190.st.net.au.dk. [130.225.0.251])
 by smtp.gmail.com with UTF8SMTPSA id
 a640c23a62f3a-abf0c74fb00sm307778866b.130.2025.02.28.07.54.14
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 28 Feb 2025 07:54:14 -0800 (PST)
From: "Paul D. Nelson" <ultrono@HIDDEN>
To: "Paul D. Nelson" <ultrono@HIDDEN>
Subject: Re: bug#76615: 14.0.9; error with amsmath style hooks
In-Reply-To: <uxsg7t4j0eyu0i.fsf@HIDDEN> (ultrono@HIDDEN)
Date: Fri, 28 Feb 2025 16:54:13 +0100
Message-ID: <uxsg7tsenyjc9m.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 76615
Cc: arash@HIDDEN, 76615 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

--=-=-=
Content-Type: text/plain

"Paul D. Nelson" <ultrono@HIDDEN> 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.


--=-=-=
Content-Type: text/plain
Content-Disposition: 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@HIDDEN:
bug#76615; Package auctex. Full text available.

Message received at 76615 <at> debbugs.gnu.org:


Received: (at 76615) by debbugs.gnu.org; 28 Feb 2025 15:22:07 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Feb 28 10:22:07 2025
Received: from localhost ([127.0.0.1]:50803 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1to2Bi-0001NM-Et
	for submit <at> debbugs.gnu.org; Fri, 28 Feb 2025 10:22:07 -0500
Received: from mail-ed1-x532.google.com ([2a00:1450:4864:20::532]:55672)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <ultrono@HIDDEN>) id 1to2Ba-0001Lm-Te
 for 76615 <at> debbugs.gnu.org; Fri, 28 Feb 2025 10:22:02 -0500
Received: by mail-ed1-x532.google.com with SMTP id
 4fb4d7f45d1cf-5dedd4782c6so4090169a12.3
 for <76615 <at> debbugs.gnu.org>; Fri, 28 Feb 2025 07:21:58 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1740756112; x=1741360912; darn=debbugs.gnu.org;
 h=mime-version:message-id:date:in-reply-to:subject:cc:to:from:from:to
 :cc:subject:date:message-id:reply-to;
 bh=+EGkDhPhtX3uZAfBLKpZIY5igXiCjPJGgMBImggvkPE=;
 b=DUChTx9EW21Uk57n6yK/TDzMdSrNx0P8BSIeWI2K6MhC9M5uAlfJ8GR1UV+ycSIC0+
 40xRlFc7kLKeKYsHjPZzQs2O7fy/2WFpTuvHCIVzXgV6XMMxnI9l7ipSmNHlEorkNgmH
 4LchnJmeo72zqFlfMvZszZAiuXFH5ns+DU0cCofrENTZBsWfaCylQpMfe0Rykb6RvqeP
 hhq+SVbJbGFUBSieToVPppvWbJVE9Q1sbT4LXvn7+LS9M63XTgxzwS8U0c+FcW4NlGNH
 WvRis4GFe7lIkK6MZryOjnfnI03s3h81WA5FnRFPQAAB2gBG1N/QqVgu8v+5ViVYHJLa
 4FUA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1740756112; x=1741360912;
 h=mime-version:message-id:date:in-reply-to:subject:cc:to:from
 :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
 bh=+EGkDhPhtX3uZAfBLKpZIY5igXiCjPJGgMBImggvkPE=;
 b=RMVFpzrdNySCpvWqGjJ/keCcdHNNUajit4jOzJkBNFFlAx1k7OiBdY51LWuTO267uH
 cd1bnSZJEUW7gj7vqElXIL2xllqy0ukGUoQJHny5Kuytlj38JKFtBtY13Pt+Om5wIvo6
 ylye006CtxjGjvQRc7QVpbDcesfv2C0NHGRYYDo7TxfUtAOwku+uOg6uSpa0gg/4sZ8H
 7lvilVM6Nk0ddmJz1obz+29P0Ak1nIB3GkMpp2nosLqqP1Qg3BUbyOa4rCsFzBoyN8E8
 SIlraijeVsTlXFllAYDmh+BTZSTO8oKwiYUBfGTWlVLaRtPP4lLKUEdwCCKheTPF3MAp
 Ipbw==
X-Gm-Message-State: AOJu0Yx2QUcQ+ncXcnUCBJAIrS9EI9HGICKJLxUrGuXjCrUgEcVNZLkQ
 /+rO1a3E+v6Jc/hL81o3ASv4NVmXGrFvdv1KgvrDjwiEM+Xv/rPn
X-Gm-Gg: ASbGncvXovc9hPNj36er4O+1xV4DM3IiehvmYE6fdmHhnrP6Kb/JdW8Dv/5/Xk0qnpp
 j2MGETPVawCmNJHVXrbvcqL6uALgnZorHXQmt6AOlqCzU1gTdLwb5iUWIPzjS1PGZoW+d6/1PqL
 3F2NZ9Y9AcbNlozCVXsMVVSAF+T3WOigdqu3kEq5uHLw7rhWn3H4X6Uc74/vJ1c/cdxlj1rSwvo
 xuSeTSxuByZt/6Iui7y0iCqhSwJ2bpFipjCZGdcxqjsx1Lkpy9hB0UKsxv+g4DXtSj+BrRU6mMm
 xshZw/7GKYc8y979PiWRb9+Xiqrc0x8mtr1NDI82Gz6E77ncRXjU
X-Google-Smtp-Source: AGHT+IEXEM6ZT+AuOVdQpz4bMHG2zQPzG+33JXyAnW0PE3aQOfE2ilJh04AspcZn3+noijK7sSzDww==
X-Received: by 2002:a05:6402:40ca:b0:5e0:4276:c39e with SMTP id
 4fb4d7f45d1cf-5e4d6b86d7dmr2944875a12.30.1740756112138; 
 Fri, 28 Feb 2025 07:21:52 -0800 (PST)
Received: from localhost (users-1190.st.net.au.dk. [130.225.0.251])
 by smtp.gmail.com with UTF8SMTPSA id
 4fb4d7f45d1cf-5e4c3b6ce0csm2666725a12.24.2025.02.28.07.21.50
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 28 Feb 2025 07:21:50 -0800 (PST)
From: "Paul D. Nelson" <ultrono@HIDDEN>
To: Arash Esbati <arash@HIDDEN>
Subject: Re: bug#76615: 14.0.9; error with amsmath style hooks
In-Reply-To: <m21pvi8q1p.fsf@HIDDEN> (message from Arash Esbati
 on Fri, 28 Feb 2025 08:52:02 +0100)
Date: Fri, 28 Feb 2025 16:21:49 +0100
Message-ID: <uxsg7t4j0eyu0i.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 76615
Cc: 76615 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

--=-=-=
Content-Type: text/plain

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


--=-=-=
Content-Type: text/plain
Content-Disposition: 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@HIDDEN:
bug#76615; Package auctex. Full text available.

Message received at 76615 <at> debbugs.gnu.org:


Received: (at 76615) by debbugs.gnu.org; 28 Feb 2025 07:52:16 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Feb 28 02:52:16 2025
Received: from localhost ([127.0.0.1]:44537 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tnvAN-0002VU-O5
	for submit <at> debbugs.gnu.org; Fri, 28 Feb 2025 02:52:16 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10]:44922)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <arash@HIDDEN>) id 1tnvAK-0002Uo-LM
 for 76615 <at> debbugs.gnu.org; Fri, 28 Feb 2025 02:52:13 -0500
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <arash@HIDDEN>)
 id 1tnvAF-0006iM-7O; Fri, 28 Feb 2025 02:52:07 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To:
 From; bh=lorg4s7pFd3tG3G8hdxPD1ncX7hmnekRriH7M1upJjY=; b=o934EVztxhiUFnzX/tsa
 HotDzaCIil/rViU0MqGqkcRq4N5/s7tk/NucHk9DsnuxSN/bKW/ptLT4wQF6rES9dpIPjciK7COwk
 CNdbwkV8a/5q0VviMmWWMtob39QuaXROJWhTR/ZeBHKIreD5Mnur3OTUlG865wjKaT9e/i1ebloK+
 wB1+OJKcx6N+L4lp2CZKSNHWLdSMg6MENhp9UvYpK52mPdZ+ztyFhR7RWZROGQGThG1sYzwFOiMMV
 nYHmT6gqyYvUtByDuXFENsweMLSqgBbywcv7NBzIpZC4RjXSnakv1/3dGOnu3pdE2OhyIAJFf42Qq
 KaXMR//aufPN7Q==;
From: Arash Esbati <arash@HIDDEN>
To: "Paul D. Nelson" <ultrono@HIDDEN>
Subject: Re: bug#76615: 14.0.9; error with amsmath style hooks
In-Reply-To: <uxsg7tcyf3nsws.fsf@HIDDEN>
References: <uxsg7tcyf3nsws.fsf@HIDDEN>
Date: Fri, 28 Feb 2025 08:52:02 +0100
Message-ID: <m21pvi8q1p.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76615
Cc: 76615 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

Hi Paul,

"Paul D. Nelson" <ultrono@HIDDEN> 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@HIDDEN:
bug#76615; Package auctex. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 27 Feb 2025 18:30:04 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Feb 27 13:30:03 2025
Received: from localhost ([127.0.0.1]:37667 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tnie2-000122-7W
	for submit <at> debbugs.gnu.org; Thu, 27 Feb 2025 13:30:03 -0500
Received: from lists.gnu.org ([2001:470:142::17]:59194)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <ultrono@HIDDEN>) id 1tnid7-0000zm-Ho
 for submit <at> debbugs.gnu.org; Thu, 27 Feb 2025 13:29:06 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <ultrono@HIDDEN>) id 1tnid0-0000n7-6h
 for bug-auctex@HIDDEN; Thu, 27 Feb 2025 13:28:58 -0500
Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <ultrono@HIDDEN>) id 1tnicy-0000uM-7b
 for bug-auctex@HIDDEN; Thu, 27 Feb 2025 13:28:57 -0500
Received: by mail-ed1-x531.google.com with SMTP id
 4fb4d7f45d1cf-5ded1395213so1924404a12.2
 for <bug-auctex@HIDDEN>; Thu, 27 Feb 2025 10:28:55 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1740680934; x=1741285734; darn=gnu.org;
 h=mime-version:message-id:date:subject:to:from:from:to:cc:subject
 :date:message-id:reply-to;
 bh=jpzAZsgbiZKwOOpf1batrBS08JqKAsXj55JavpZC0UI=;
 b=N0c7e1Q3QqV5ffwu75R7O2l0rqE8dK/lZ1QF4nJzy1EbCXv28FP2WlwgZWLWvudV4j
 7sKLdQqAJEOvUXBx8Y5tCS2AhBR+5KcmcZZfseQY+IhXbs9q5qugdFq6lVbzqku6zlx8
 0VzCEHg+sBvAJSz3feFa4xryX3XI87ljdpESTXvTV1Nt2FEjEOYZZULUB3TPqkVmCcQa
 cxGbeMub/iVH7KnNmsD7ZZZ2d+dQJ7kbe/qzvtXwpvoBQXRgfxsKAzRaAjQzZW2VADw5
 AWzEOaekRCMK5ZYeN+WH6bYIsbDL5q7ItWgDLBi9U5zsZPtltf+jPAWAAW+NGGbrvOqv
 /7yA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1740680934; x=1741285734;
 h=mime-version:message-id:date:subject:to:from:x-gm-message-state
 :from:to:cc:subject:date:message-id:reply-to;
 bh=jpzAZsgbiZKwOOpf1batrBS08JqKAsXj55JavpZC0UI=;
 b=rf6Vh9XcN+t2yTQEiBZEcqHozcF0dO44oJJDEUIWxRwpNHkJxzD/qS8tNjcDtTciIu
 4Nrrn/N7KlJR5PIgHzmfm9TFnhf0IV7gnIpYg/ZEH9i57WdwdWytEtFUYhUMqBO6j3mE
 Z2D+US9kql6Lg3v+fCqg3AHIRgCY9HEtgHr47fbZJPalEaIUp6wAkarBMns1ph18D1sR
 4BnhhBzxAn+AwXbMhTdZRVarxMvHwFbJqNSE1JkFOmOVzRGCQjMQkjza2mmKjuityOhe
 gCSxf19GMZWXm+daQc3HskP0tO5rGVtWft9Qoh0AjC5P791m5dPhQ+2CnP+ZVXGtfw3O
 VBTQ==
X-Gm-Message-State: AOJu0YyaB1Oetdzn3veWkE7+hUJEVr+F0Iqv3kyzgL+UMtp5U1+y1vT6
 neXpYIdUNqo58XoceilEocIxJ6ixoSgQhvCuqCz9Ivghci87w1mMNlf+mSMZvCA=
X-Gm-Gg: ASbGncvJXFh3D8xccDc04htDaZNV1WOFLUXY2fscFxvWsqRAPiKO2wTPylwPv84V9lT
 sZ3d2md/mHYJvIrL+h8UdIB/wKs676WGrzwfLvLqf5MCU3kPbxrx9wpw1wsci0Ow/VjFAOK9oTl
 Q9Ke+uGfT/xTh2xQUURBTAiQ8Urt0wYd5i+2KTQEuxbo7OV76GZOlL3WXltRdeFQS46Fmr4n48k
 fvEKxzyN7G3hQTGP9562kAfWd73qBVkJYBM9/aQc7WJ94cdb0Hgfmbahq9EFSRES1HPDNXI2H7P
 S6vPRuKfAzNGprc3LwBXRUo4Lb9W1qfGPnWaNTsWaMgPtjBPFoDZ
X-Google-Smtp-Source: AGHT+IE8RJGXkjMS1wES0v14yEikMMePBkPcfy3CMfWLmrT7SWb43ROE6vDwlRHDt4DtkIW5OLu5rw==
X-Received: by 2002:a05:6402:2790:b0:5e4:d229:ad3d with SMTP id
 4fb4d7f45d1cf-5e4d6afa4c4mr89470a12.16.1740680933861; 
 Thu, 27 Feb 2025 10:28:53 -0800 (PST)
Received: from localhost (users-1190.st.net.au.dk. [130.225.0.251])
 by smtp.gmail.com with UTF8SMTPSA id
 4fb4d7f45d1cf-5e4c3b6dbbbsm1466472a12.22.2025.02.27.10.28.51
 for <bug-auctex@HIDDEN>
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Thu, 27 Feb 2025 10:28:52 -0800 (PST)
From: "Paul D. Nelson" <ultrono@HIDDEN>
To: bug-auctex@HIDDEN
Subject: 14.0.9; error with amsmath style hooks
Date: Thu, 27 Feb 2025 19:28:51 +0100
Message-ID: <uxsg7tcyf3nsws.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain
Received-SPF: pass client-ip=2a00:1450:4864:20::531;
 envelope-from=ultrono@HIDDEN; helo=mail-ed1-x531.google.com
X-Spam_score_int: -20
X-Spam_score: -2.1
X-Spam_bar: --
X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001,
 RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,
 SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: 1.0 (+)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.0 (/)

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"))
 )




Acknowledgement sent to "Paul D. Nelson" <ultrono@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-auctex@HIDDEN. Full text available.
Report forwarded to bug-auctex@HIDDEN:
bug#76615; Package auctex. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Fri, 4 Apr 2025 19:15:02 UTC

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