Subject: bug#55511: 13.1.3; TeX-auto-store issues with complex paths

From: Ikumi Keita <[email-masked]>
Date: Tue, 24 May 2022 22:44:55 +0900

Hi Tassilo,

>>>>> Tassilo Horn <[email-masked]> writes:
> I've lost track in this discussion but is the plan to have many auto/
> directories in the directories where the included tex files reside or do
> you want to resemble the path to included files below the single auto/
> directory next to the master document?

My idea is to have a new user option to choose one from those two plans.
The attached patch implements this idea. The current behavior is the
latter one.

> If it's the former, there could be the possibility that the current user
> has no write permissions everywhere.  It could also be annoying in cases
> where the included files reside on a network share or a VCS checkout
> which will become dirty due to AUCTeX writing there.

Indeed.

Best,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine

diff --git a/tex.el b/tex.el
index 8b76f98d..74832ad7 100644
--- a/tex.el
+++ b/tex.el
@@ -3963,6 +3963,15 @@ Generated by `TeX-auto-add-type'.")
   :group 'TeX-parse
   :type 'boolean)
 
+(defcustom TeX-auto-save-aggregate t
+  "Non-nil means saving in \"auto\" subdirectory of master file.
+
+Save in each \"auto\" subdirectory otherwise.
+
+Subdirectory name is actually taken from `TeX-auto-local'."
+  :group 'TeX-parse
+  :type 'boolean)
+
 (defun TeX-auto-write ()
   "Save all relevant TeX information from the current buffer."
   (if TeX-auto-untabify
@@ -3973,7 +3982,9 @@ Generated by `TeX-auto-add-type'.")
                      (file-name-as-directory TeX-auto-local)
                      (TeX-strip-extension nil TeX-all-extensions t)
                      ".el")
-                    (TeX-master-directory)))
+                    (if TeX-auto-save-aggregate
+                        (TeX-master-directory)
+                      default-directory)))
              (dir (file-name-directory file)))
         ;; Create auto directory if possible.
         (if (not (file-exists-p dir))