> I used
> patch -p1 < indirect2.patch
> in the top directory of the local git repo and took care of the rejected
> hunks manually.
>

Thanks Ikuya, I did this just now and tried the patch out (and have
attached the master-relative patch that I obtained after merging, in
case it's of convenience for anyone else).

For me, previews work fine in indirect buffers with this patch (based
on 20 mins of usage).  I don't see anything like what you described
(previews appearing in the base buffer).

If I undo the effects of the patch for bug#70307, then preview-latex
fails on indirect buffers when the master file does not appear in the
same folder as the current tex file, but that's also not quite what
you're encountering.

Paul
From c59e27287116c4873748868686e69b7edff06145 Mon Sep 17 00:00:00 2001
From: Paul Nelson <[email protected]>
Date: Tue, 23 Apr 2024 15:53:52 +0200
Subject: [PATCH] indirect2 patch

---
 bib-cite.el                   |   2 +-
 latex.el                      |   4 +-
 preview.el.in                 |   4 +-
 style/catchfilebetweentags.el |   2 +-
 style/pdfsync.el              |   2 +-
 tex-info.el                   |   2 +-
 tex.el                        | 295 ++++++++++++++++++----------------
 toolbar-x.el                  |   6 +-
 8 files changed, 163 insertions(+), 154 deletions(-)

diff --git a/bib-cite.el b/bib-cite.el
index 5a7de98f..7b425cac 100644
--- a/bib-cite.el
+++ b/bib-cite.el
@@ -1903,7 +1903,7 @@ If no master file, then return current default."
                     ;; rather than            \input file
                     (re-search-forward "^[ \t]*\\\\\\(include\\|input\\){"
                                        nil t))))
-           (buffer-file-name))
+           (TeX-buffer-file-name))
           (t
            nil))))
     (cond
diff --git a/latex.el b/latex.el
index c5965b05..9e769e97 100644
--- a/latex.el
+++ b/latex.el
@@ -2569,7 +2569,7 @@ string."
 Initial input is the name of the file being visited in the
 current buffer, with extension.  If OPTIONAL is non-nil, insert
 it as an optional argument.  Use PROMPT as the prompt string."
-  (let ((name (file-name-nondirectory buffer-file-name)))
+  (let ((name (file-name-nondirectory (TeX-buffer-file-name))))
     (TeX-argument-insert
      (TeX-read-string
       (TeX-argument-prompt optional
@@ -2590,7 +2590,7 @@ current buffer, without extension.  If OPTIONAL is non-nil,
 insert it as an optional argument.  Use PROMPT as the prompt
 string."
   (let ((name (file-name-sans-extension
-               (file-name-nondirectory buffer-file-name))))
+               (file-name-nondirectory (TeX-buffer-file-name)))))
     (TeX-argument-insert
      (TeX-read-string
       (TeX-argument-prompt optional
diff --git a/preview.el.in b/preview.el.in
index 1f65f728..98d23c47 100644
--- a/preview.el.in
+++ b/preview.el.in
@@ -3073,8 +3073,8 @@ pp")
        #'desktop-buffer-preview-misc-data)
   (add-hook 'pre-command-hook #'preview-mark-point nil t)
   (add-hook 'post-command-hook #'preview-move-point nil t)
-  (when buffer-file-name
-    (let* ((filename (expand-file-name buffer-file-name))
+  (when (TeX-buffer-file-name)
+    (let* ((filename (expand-file-name (TeX-buffer-file-name)))
            format-cons)
       (when (string-match (concat "\\." TeX-default-extension "\\'")
                           filename)
diff --git a/style/catchfilebetweentags.el b/style/catchfilebetweentags.el
index 6354f15f..fb63bb7d 100644
--- a/style/catchfilebetweentags.el
+++ b/style/catchfilebetweentags.el
@@ -67,7 +67,7 @@ ENVIRONMENT is ignored."
   ;; several external files to a singular one.
   (let* ((file (file-name-sans-extension
                 (file-name-nondirectory
-                 (buffer-file-name (current-buffer)))))
+                 (TeX-buffer-file-name (current-buffer)))))
          (fn (when LaTeX-catchfilebetweentags-use-numeric-label
                (LaTeX-catchfilebetweentags-counter-inc)))
          (tag (concat file ":"
diff --git a/style/pdfsync.el b/style/pdfsync.el
index 122f0eb9..e52baf4d 100644
--- a/style/pdfsync.el
+++ b/style/pdfsync.el
@@ -37,7 +37,7 @@
   (let* ((line (line-number-at-pos))
          (master (TeX-active-master))
          (file (file-name-sans-extension
-                (file-relative-name (buffer-file-name)
+                (file-relative-name (TeX-buffer-file-name)
                                     (file-name-directory master))))
          (pdfsync-file (concat master ".pdfsync"))
          (buf-live-p (get-file-buffer pdfsync-file))
diff --git a/tex-info.el b/tex-info.el
index 9f919ee3..2a65c3a9 100644
--- a/tex-info.el
+++ b/tex-info.el
@@ -700,7 +700,7 @@ value of `Texinfo-mode-hook'."
   (set (make-local-variable 'TeX-style-hook-dialect) :texinfo)
 
   (add-hook 'find-file-hook (lambda ()
-                              (unless (file-exists-p (buffer-file-name))
+                              (unless (file-exists-p (TeX-buffer-file-name))
                                 (TeX-master-file nil nil t)))
             nil t)
 
diff --git a/tex.el b/tex.el
index 985cb71e..1bfa65f2 100644
--- a/tex.el
+++ b/tex.el
@@ -673,7 +673,7 @@ string."
     ;; case the file is in a different subdirectory
     ("%b" TeX-current-file-name-master-relative)
     ;; Okular forward PDF search requires absolute path.
-    ("%a" (lambda nil (prin1-to-string (expand-file-name (buffer-file-name)))))
+    ("%a" (lambda nil (prin1-to-string (expand-file-name (TeX-buffer-file-name)))))
     ;; the following is for preview-latex.
     ("%m" preview-create-subdirectory)
     ;; LaTeXMk support
@@ -801,12 +801,12 @@ emacs 24.1 and is then later run by emacs 24.5."
 (advice-add 'hack-one-local-variable :after #'TeX--call-minor-mode)
 (defun TeX--call-minor-mode (var val &rest _)
   "Call minor mode function if minor mode variable is found."
-    ;; Instead of checking for each mode explicitly `minor-mode-list'
-    ;; could be used.  But this may make the byte compiler pop up.
-    (when (memq var '(TeX-PDF-mode
-                      TeX-source-correlate-mode TeX-interactive-mode
-                      TeX-fold-mode LaTeX-math-mode))
-      (funcall var (if (symbol-value val) 1 0))))
+  ;; Instead of checking for each mode explicitly `minor-mode-list'
+  ;; could be used.  But this may make the byte compiler pop up.
+  (when (memq var '(TeX-PDF-mode
+                    TeX-source-correlate-mode TeX-interactive-mode
+                    TeX-fold-mode LaTeX-math-mode))
+    (funcall var (if (symbol-value val) 1 0))))
 
 (defvar TeX-overlay-priority-step 16
   "Numerical difference of priorities between nested overlays.
@@ -1251,7 +1251,7 @@ viewer."
            (format "/org/%s/%s/Window/0" de app)
            (format "org.%s.%s.Window" de app)
            "SyncView"
-           (buffer-file-name)
+           (TeX-buffer-file-name)
            (list :struct :int32 (1+ (TeX-current-offset))
                  ;; FIXME: Using `current-column' here is dubious.
                  ;; Most of CJK letters count as occupying 2 columns,
@@ -1820,7 +1820,7 @@ Else, return nil."
       (when (re-search-forward "!offset(\\([---0-9]+\\))" nil t)
         (let ((offset (string-to-number (match-string-no-properties 1))))
           (when TeX-region-orig-buffer
-            (list (expand-file-name (buffer-file-name TeX-region-orig-buffer))
+            (list (expand-file-name (TeX-buffer-file-name TeX-region-orig-buffer))
                   (+ line offset) col)))))))
 
 (defcustom TeX-raise-frame-function #'raise-frame
@@ -2040,11 +2040,11 @@ enabled and the `synctex' binary is available."
   "Return the page corresponding to the position in the current buffer.
 This method assumes that the document was compiled with SyncTeX
 enabled and the `synctex' binary is available."
-  (let* ((file (file-relative-name (buffer-file-name)
+  (let* ((file (file-relative-name (TeX-buffer-file-name)
                                    (file-name-directory
                                     (TeX-active-master))))
          (abs-file (concat (expand-file-name (or (file-name-directory (TeX-active-master))
-                                                 (file-name-directory (buffer-file-name))))
+                                                 (file-name-directory (TeX-buffer-file-name))))
                            "./" file)))
     ;; It's known that depending on synctex version one of
     ;; /absolute/path/./foo/bar.tex, foo/bar.tex, or ./foo/bar.tex (relative to
@@ -2195,20 +2195,20 @@ for backward compatibility."
   "The name of the BibTeX entry in `TeX-command-list'."
   :group 'TeX-command-name
   :type 'string)
-  (make-variable-buffer-local 'TeX-command-BibTeX)
+(make-variable-buffer-local 'TeX-command-BibTeX)
 
 (defcustom TeX-command-Biber "Biber"
   "The name of the Biber entry in `TeX-command-list'."
   :group 'TeX-command-name
   :type 'string)
-  (make-variable-buffer-local 'TeX-command-Biber)
+(make-variable-buffer-local 'TeX-command-Biber)
 
 (defcustom TeX-command-Show "View"
   "The default command to show (view or print) a TeX file.
 Must be the car of an entry in `TeX-command-list'."
   :group 'TeX-command-name
   :type 'string)
-  (make-variable-buffer-local 'TeX-command-Show)
+(make-variable-buffer-local 'TeX-command-Show)
 
 (defcustom TeX-command-Print "Print"
   "The name of the Print entry in `TeX-command-Print'."
@@ -2379,7 +2379,7 @@ this variable to \"<none>\"."
              (TeX-add-local-master))
             ((or
               ;; Default `read-file-name' proposes and buffer visits a file.
-              (string= (expand-file-name name) (buffer-file-name))
+              (string= (expand-file-name name) (TeX-buffer-file-name))
               ;; Default of `read-file-name' and buffer does not visit a file.
               (string= name default-directory)
               ;; User typed <RET> in an empty minibuffer.
@@ -2406,80 +2406,84 @@ name of master file if it cannot be determined otherwise."
   (interactive)
   (if (eq extension t)
       (setq extension TeX-default-extension))
-  (let ((my-name (if (buffer-file-name)
-                     (TeX-strip-extension nil (list TeX-default-extension) t)
-                   "<none>")))
-    (save-excursion
-      (save-restriction
-        (widen)
-        (goto-char (point-min))
-        (cond
-         ((and TeX-transient-master
-               (or (not TeX-master) (eq TeX-master 'shared)))
-          (setq TeX-master TeX-transient-master))
-         ;; Special value 't means it is own master (a free file).
-         ((equal TeX-master my-name)
-          (setq TeX-master t))
-
-         ;; For files shared between many documents.
-         ((and (eq 'shared TeX-master) ask)
-          (setq TeX-master
-                (let* ((default (TeX-dwim-master))
-                       (name (read-file-name
-                              (format "Master file (default %s): "
-                                      (or default "this file"))
-                              nil default)))
-                  (cond ((string= name default)
-                         default)
-                        ((or
-                          ;; Default `read-file-name' proposes and
-                          ;; buffer visits a file.
-                          (string= (expand-file-name name)
-                                   (buffer-file-name))
-                          ;; Default of `read-file-name' and
-                          ;; buffer does not visit a file.
-                          (string= name default-directory)
-                          ;; User typed <RET> in an empty minibuffer.
-                          (string= name ""))
-                         t)
-                        (t
-                         (TeX-strip-extension
-                          name (list TeX-default-extension) 'path))))))
-
-         ;; We might already know the name.
-         ((or (eq TeX-master t) (stringp TeX-master)) TeX-master)
-
-         ;; Ask the user (but add it as a local variable).
-         (ask (TeX-master-file-ask)))))
-
-    (let ((name (if (stringp TeX-master)
-                    TeX-master
-                  my-name)))
-
-      (if (TeX-match-extension name)
-          ;; If it already has an extension...
-          (if (equal extension TeX-default-extension)
-              ;; Use instead of the default extension
-              (setq extension nil)
-            ;; Otherwise drop it.
-            (setq name (TeX-strip-extension name))))
-
-      (let* ((reg (TeX--clean-extensions-regexp t))
-             (is-output-ext (and reg
-                                 (or (string-match-p reg (concat "." extension))
-                                     (string= "prv" extension))))
-             (output-dir (and is-output-ext
-                              (TeX--master-output-dir
-                               (file-name-directory name)
-                               nondirectory))))
-        (if output-dir
-            (setq name (concat output-dir (file-name-nondirectory name)))
-          ;; Remove directory if needed.
-          (if nondirectory
-              (setq name (file-name-nondirectory name)))))
-      (if extension
-          (concat name "." extension)
-        name))))
+  (with-current-buffer
+      ;; In case this is an indirect buffer:
+      (or (buffer-base-buffer) (current-buffer))
+    (let ((my-name (if (TeX-buffer-file-name)
+                       (TeX-strip-extension nil (list TeX-default-extension) t)
+                     "<none>")))
+      (save-excursion
+        (save-restriction
+          (widen)
+          (goto-char (point-min))
+          (cond
+           ((and TeX-transient-master
+                 (or (not TeX-master) (eq TeX-master 'shared)))
+            (setq TeX-master TeX-transient-master))
+
+           ;; Special value 't means it is own master (a free file).
+           ((equal TeX-master my-name)
+            (setq TeX-master t))
+
+           ;; For files shared between many documents.
+           ((and (eq 'shared TeX-master) ask)
+            (setq TeX-master
+                  (let* ((default (TeX-dwim-master))
+                         (name (read-file-name
+                                (format "Master file (default %s): "
+                                        (or default "this file"))
+                                nil default)))
+                    (cond ((string= name default)
+                           default)
+                          ((or
+                            ;; Default `read-file-name' proposes and
+                            ;; buffer visits a file.
+                            (string= (expand-file-name name)
+                                     (TeX-buffer-file-name))
+                            ;; Default of `read-file-name' and
+                            ;; buffer does not visit a file.
+                            (string= name default-directory)
+                            ;; User typed <RET> in an empty minibuffer.
+                            (string= name ""))
+                           t)
+                          (t
+                           (TeX-strip-extension
+                            name (list TeX-default-extension) 'path))))))
+
+           ;; We might already know the name.
+           ((or (eq TeX-master t) (stringp TeX-master)) TeX-master)
+
+           ;; Ask the user (but add it as a local variable).
+           (ask (TeX-master-file-ask)))))
+
+      (let ((name (if (stringp TeX-master)
+                      TeX-master
+                    my-name)))
+
+        (if (TeX-match-extension name)
+            ;; If it already has an extension...
+            (if (equal extension TeX-default-extension)
+                ;; Use instead of the default extension
+                (setq extension nil)
+              ;; Otherwise drop it.
+              (setq name (TeX-strip-extension name))))
+
+        (let* ((reg (TeX--clean-extensions-regexp t))
+               (is-output-ext (and reg
+                                   (or (string-match-p reg (concat "." extension))
+                                       (string= "prv" extension))))
+               (output-dir (and is-output-ext
+                                (TeX--master-output-dir
+                                 (file-name-directory name)
+                                 nondirectory))))
+          (if output-dir
+              (setq name (concat output-dir (file-name-nondirectory name)))
+            ;; Remove directory if needed.
+            (if nondirectory
+                (setq name (file-name-nondirectory name)))))
+        (if extension
+            (concat name "." extension)
+          name)))))
 
 (defun TeX-master-directory ()
   "Directory of master file."
@@ -2488,17 +2492,15 @@ name of master file if it cannot be determined otherwise."
     (substitute-in-file-name
      (expand-file-name
       (let ((dir (file-name-directory (TeX-master-file))))
-        (if dir (directory-file-name dir) "."))
-      (and buffer-file-name
-           (file-name-directory buffer-file-name)))))))
+        (if dir (directory-file-name dir) ".")))))))
 
 (defun TeX-add-local-master ()
   "Add local variable for `TeX-master'.
 
 Get `major-mode' from master file and enable it."
-  (when (and (buffer-file-name)
+  (when (and (TeX-buffer-file-name)
              (string-match TeX-one-master
-                           (file-name-nondirectory (buffer-file-name)))
+                           (file-name-nondirectory (TeX-buffer-file-name)))
              (not buffer-read-only))
     (goto-char (point-max))
     (if (re-search-backward "^\\([^\n]+\\)Local Variables:"
@@ -2935,7 +2937,7 @@ implement dialect sets as bitmaps."  )
 
 (defsubst TeX-shdex-not (arg)
   "NOT operator for style hook dialect expressions."
-   (lognot (TeX-shdex-eval arg)))
+  (lognot (TeX-shdex-eval arg)))
 
 (defsubst TeX-shdex-in-p (dialect dialect-set)
   "Test whether dialect DIALECT is in dialect set DIALECT-SET."
@@ -2996,7 +2998,7 @@ found in DIALECT-LIST and return the list thereof."
         (when (memq (pop dialect-list-1) dialect-list)
           (push hook ret)
           (setq dialect-list-1 nil)))
-    ret)))
+      ret)))
 
 (defun TeX-unload-style (style &optional dialect-list)
   "Forget that we once loaded STYLE.
@@ -3087,9 +3089,9 @@ FORCE is not nil."
     (TeX-run-style-hooks (TeX-strip-extension nil nil t))
     ;; Run parent style hooks if it has a single parent that isn't itself.
     (if (or (not (memq TeX-master '(nil t)))
-            (and (buffer-file-name)
+            (and (TeX-buffer-file-name)
                  (string-match TeX-one-master
-                               (file-name-nondirectory (buffer-file-name)))))
+                               (file-name-nondirectory (TeX-buffer-file-name)))))
         (TeX-run-style-hooks (TeX-master-file)))
     (if (and TeX-parse-self
              (null (cdr-safe (assoc (TeX-strip-extension nil nil t)
@@ -3881,7 +3883,7 @@ Not intended for direct use for user."
   (add-hook 'find-file-hook
             (lambda ()
               ;; Check if we are looking at a new or shared file.
-              (when (or (not (file-exists-p (buffer-file-name)))
+              (when (or (not (file-exists-p (TeX-buffer-file-name)))
                         (eq TeX-master 'shared))
                 (TeX-master-file nil nil t))
               (TeX-update-style t)) nil t))
@@ -4035,7 +4037,7 @@ separate type of information in the parser."
          (local (intern (concat prefix "-" name "-list")))
          (change (intern (concat prefix "-" name "-changed")))
          (vardoc (concat "Information about " names
-                          " in the current buffer.
+                         " in the current buffer.
 Generated by `TeX-auto-add-type'."))
          ;; Avoid clash between LaTeX environments and ConTeXt
          ;; environments in keys of `TeX-auto-parser'.
@@ -4347,7 +4349,7 @@ It can also be a name of a variable having such value."
                                (sexp :tag "Groups")
                                symbol)))
   :group 'TeX-parse)
-  (make-variable-buffer-local 'TeX-auto-regexp-list)
+(make-variable-buffer-local 'TeX-auto-regexp-list)
 
 (defun TeX-auto-add-regexp (regexp)
   "Add REGEXP to `TeX-auto-regexp-list' if not already a member."
@@ -4395,7 +4397,7 @@ alter the numbering of any ordinary, non-shy groups.")
   "Maximal length of TeX file (in characters) that will be parsed."
   :group 'TeX-parse
   :type 'integer)
-  (make-variable-buffer-local 'TeX-auto-parse-length)
+(make-variable-buffer-local 'TeX-auto-parse-length)
 
 (defcustom TeX-auto-x-parse-length 0
   "Maximum length of TeX file that will be parsed additionally.
@@ -4403,7 +4405,7 @@ Use `TeX-auto-x-regexp-list' for parsing the region between
 `TeX-auto-parse-length' and this value."
   :group 'TeX-parse
   :type 'integer)
-  (make-variable-buffer-local 'TeX-auto-x-parse-length)
+(make-variable-buffer-local 'TeX-auto-x-parse-length)
 
 (defcustom TeX-auto-x-regexp-list 'LaTeX-auto-label-regexp-list
   "List of regular expressions used for additional parsing.
@@ -4421,7 +4423,7 @@ See `TeX-auto-x-parse-length'."
                                (sexp :tag "Groups")
                                symbol)))
   :group 'TeX-parse)
-  (make-variable-buffer-local 'TeX-auto-x-regexp-list)
+(make-variable-buffer-local 'TeX-auto-x-regexp-list)
 
 (defun TeX-regexp-group-count (regexp)
   "Return number of groups in a REGEXP.  This is not foolproof:
@@ -4573,7 +4575,7 @@ Check for potential LaTeX environments."
   :group 'TeX-file-extension
   :type 'string)
 
-  (make-variable-buffer-local 'TeX-default-extension)
+(make-variable-buffer-local 'TeX-default-extension)
 
 (defvar TeX-doc-extensions
   '("dvi" "pdf" "ps" "txt" "html" "dvi\\.gz" "pdf\\.gz" "ps\\.gz" "txt\\.gz"
@@ -4637,7 +4639,7 @@ STRING defaults to the name of the current buffer.
 EXTENSIONS defaults to `TeX-file-extensions'."
 
   (if (null string)
-      (setq string (or (buffer-file-name) "<none>")))
+      (setq string (or (TeX-buffer-file-name) "<none>")))
 
   (if (null extensions)
       (setq extensions TeX-file-extensions))
@@ -4920,7 +4922,7 @@ to look backward for."
 (defun TeX-current-file-name-master-relative ()
   "Return current filename, relative to master directory."
   (file-relative-name
-   (buffer-file-name)
+   (TeX-buffer-file-name)
    (TeX-master-directory)))
 
 (defun TeX-near-bobp ()
@@ -5948,16 +5950,16 @@ suffix to be used in math mode.
 An optional fourth (or sixth) element means always replace if t."
   :group 'TeX-macro
   :type '(repeat
-           (group
-            :value (?\C-a "" "")
-            (character :tag "Key")
-            (string :tag "Prefix")
-            (string :tag "Suffix")
-            (option (group
-                     :inline t
-                     (string :tag "Math Prefix")
-                     (string :tag "Math Suffix")))
-            (option (sexp :format "Replace\n" :value t)))))
+          (group
+           :value (?\C-a "" "")
+           (character :tag "Key")
+           (string :tag "Prefix")
+           (string :tag "Suffix")
+           (option (group
+                    :inline t
+                    (string :tag "Math Prefix")
+                    (string :tag "Math Suffix")))
+           (option (sexp :format "Replace\n" :value t)))))
 
 (defvar TeX-font-replace-function #'TeX-font-replace
   "Determines the function which is called when a font should be replaced.")
@@ -6269,18 +6271,19 @@ this list.")
 Save buffer first including style information.
 With optional argument ARG, also reload the style hooks."
   (interactive "*P")
-  (if arg
-      (dolist (var TeX-normal-mode-reset-list)
-        (set var nil)))
-  (let ((gc-cons-percentage 0.5))
-    (let ((TeX-auto-save t))
-      (if (buffer-modified-p)
-          (save-buffer)
-        (TeX-auto-write)))
-    (normal-mode)
-    ;; See also addition to `find-file-hook' in `TeX-mode'.
-    (when (eq TeX-master 'shared) (TeX-master-file nil nil t))
-    (TeX-update-style t)))
+  (with-current-buffer (or (buffer-base-buffer) (current-buffer))
+    (if arg
+        (dolist (var TeX-normal-mode-reset-list)
+          (set var nil)))
+    (let ((gc-cons-percentage 0.5))
+      (let ((TeX-auto-save t))
+        (if (buffer-modified-p)
+            (save-buffer)
+          (TeX-auto-write)))
+      (normal-mode)
+      ;; See also addition to `find-file-hook' in `TeX-mode'.
+      (when (eq TeX-master 'shared) (TeX-master-file nil nil t))
+      (TeX-update-style t))))
 
 (defgroup TeX-quote nil
   "Quoting in AUCTeX."
@@ -6730,7 +6733,7 @@ NAME may be a package, a command, or a document."
         (buffers (buffer-list)))
     (while buffers
       (let* ((buffer (car buffers))
-             (name (buffer-file-name buffer)))
+             (name (TeX-buffer-file-name buffer)))
         (setq buffers (cdr buffers))
         (when (and name (string-match regexp name))
           (save-excursion (switch-to-buffer buffer) (ispell-buffer))
@@ -7096,7 +7099,7 @@ pinned region will get unpinned and vice versa."
                   TeX-region-extra)))
     (TeX-region-create (TeX-region-file TeX-default-extension)
                        (buffer-substring-no-properties begin end)
-                       (file-name-nondirectory (buffer-file-name))
+                       (file-name-nondirectory (TeX-buffer-file-name))
                        (TeX-current-offset begin))))
 
 (defun TeX-command-region (&optional override-confirm)
@@ -7588,14 +7591,14 @@ ORIGINALS which are modified but not saved yet."
                 (setq existingoriginals (cons filepath existingoriginals)))))))
     (while buffers
       (let* ((buffer (car buffers))
-             (name (buffer-file-name buffer)))
+             (name (TeX-buffer-file-name buffer)))
         (setq buffers (cdr buffers))
         (if (and name (member name existingoriginals))
             (progn
               (and (buffer-modified-p buffer)
                    (or (not TeX-save-query)
                        (y-or-n-p (concat "Save file "
-                                         (buffer-file-name buffer)
+                                         (TeX-buffer-file-name  buffer)
                                          "? ")))
                    (with-current-buffer buffer (save-buffer)))))))
     (dolist (eo existingoriginals)
@@ -8172,7 +8175,7 @@ run of `TeX-run-format', use
                  ;; `default-directory', then we have to expand `file' file-name
                  ;; in the same directory of `TeX-command-buffer'.
                  (assoc (with-current-buffer TeX-command-buffer
-                            (expand-file-name (TeX-active-master "idx")))
+                          (expand-file-name (TeX-active-master "idx")))
                         LaTeX-idx-changed-alist))
       (setq LaTeX-idx-changed-alist (delq element LaTeX-idx-changed-alist)))
     (if TeX-process-asynchronous
@@ -8326,7 +8329,7 @@ reasons.  Use `TeX-run-function' instead."
       (goto-char (point-max))
       (insert "\n" mode-name (if (and result (zerop result))
                                  " finished" " exited") " at "
-              (substring (current-time-string) 0 -5))
+                                 (substring (current-time-string) 0 -5))
       (setq mode-line-process ": exit")
 
       ;; Do command specific actions.
@@ -8479,10 +8482,10 @@ Return nil only if no errors were found."
     ;; bug#55065, restore point to the initial position.
     (goto-char (point-min))
     (let (dvi2pdf)
-        (if (with-current-buffer TeX-command-buffer
-           (and TeX-PDF-mode (setq dvi2pdf (TeX-PDF-from-DVI))))
-         (setq TeX-command-next dvi2pdf)
-       (setq TeX-command-next TeX-command-Show)))
+      (if (with-current-buffer TeX-command-buffer
+            (and TeX-PDF-mode (setq dvi2pdf (TeX-PDF-from-DVI))))
+          (setq TeX-command-next dvi2pdf)
+        (setq TeX-command-next TeX-command-Show)))
     nil))
 
 ;; This regexp should catch warnings of the type
@@ -8851,9 +8854,9 @@ user query is skipped and the process is aborted right away."
 
 (defun TeX-command-mode-line (process)
   "Format the mode line for a buffer containing output from PROCESS."
-    (setq mode-line-process (concat ": "
-                                    (symbol-name (process-status process))))
-    (force-mode-line-update))
+  (setq mode-line-process (concat ": "
+                                  (symbol-name (process-status process))))
+  (force-mode-line-update))
 
 (defun TeX-command-filter (process string)
   "Filter to process normal output."
@@ -10283,7 +10286,7 @@ forward, if negative)."
   "List of errors to be used in the error overview.")
 
 (define-derived-mode TeX-error-overview-mode tabulated-list-mode
-                     "TeX errors"
+  "TeX errors"
   "Major mode for listing TeX errors."
   :syntax-table nil :abbrev-table nil :interactive nil
   (setq tabulated-list-format [("File" 25 nil)
@@ -10430,6 +10433,12 @@ warnings and bad boxes"
                               #'TeX-master-file))))
     (error "Unable to find what command to run")))
 
+(defun TeX-buffer-file-name (&optional BUFFER)
+  "Return name of file BUFFER is visiting, or nil if none.
+No argument or nil as argument means use the current buffer.
+If BUFFER is indirect, return the file that the base buffer is visiting."
+  (buffer-file-name (or (buffer-base-buffer BUFFER) BUFFER)))
+
 (provide 'tex)
 
 ;; Local Variables:
diff --git a/toolbar-x.el b/toolbar-x.el
index d97035fd..f8e8ae91 100644
--- a/toolbar-x.el
+++ b/toolbar-x.el
@@ -1462,11 +1462,11 @@ line of buttons.  The only property supported for this button is
                  :command save-buffer
                  :enable (and
                            (buffer-modified-p)
-                           (buffer-file-name)
+                           (buffer-file-name (buffer-base-buffer))
                            (not (window-minibuffer-p
                                  (frame-selected-window menu-updating-frame))))
                  :help "Save current buffer to its file"
-                 :visible (or buffer-file-name
+                 :visible (or (buffer-file-name (buffer-base-buffer))
                               (not (eq 'special
                                        (get major-mode 'mode-class)))))
 
@@ -1476,7 +1476,7 @@ line of buttons.  The only property supported for this button is
                          (window-minibuffer-p
                           (frame-selected-window menu-updating-frame)))
                 :help "Write current buffer to another file"
-                :visible (or buffer-file-name
+                :visible (or (buffer-file-name (buffer-base-buffer))
                              (not (eq 'special (get major-mode 'mode-class)))))
 
     (undo :image "undo"
-- 
2.39.3 (Apple Git-145)

_______________________________________________
bug-auctex mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-auctex

Reply via email to