Hi Matt,

2016-04-17 13:40 GMT+02:00 Matthew Leach <matt...@mattleach.net>:
> Mosè Giordano <m...@gnu.org> writes:
>
>> Hi Matt,
>
> Hi Mosè,
>
>> 2016-04-16 23:57 GMT+02:00 Matthew Leach <matt...@mattleach.net>:
>>> Would `TeX-document-variables' be stored exclusively in the TeX-master's
>>> auto-save file or all the auto-save files for a document?  If it is the
>>> latter, we would need to ensure the alists are synchronised for all
>>> auto-save files in a document, do you know of an easy way to do this?
>>
>> No no, only in master's auto-save file.
>
> That's good.  I think the other way would have been rather difficult.
>
>>>> , with the name of a variable as key and its value as value.  This
>>>> should be used only for certain variables, above all (or only) those
>>>> related to TeXing options (engine, extra options,
>>>> `ConTeXt-Mark-version', etc).
>>>
>>> How would the user set and edit a variable document wide?  Would we
>>> provide a new interactive setter function that would write that to the
>>> `TeX-document-variables' alist?
>>
>> My simple idea was to set the variables as usual (either manually or
>> with `add-file-local-variable', I have no new special tool in mind),
>> but with this new framework users need to set them only once in the
>> master file, instead of every single file part of the document.
>
> That sounds reasonable.  I presume that if a user wanted to change an
> already-set variable, they would change it as normal in the TeX-master
> file and our code to write the auto-save file would handle this?
>
>>>> Every function that needs to access those variable should check this
>>>> alist first fallbacking onto the (local) value of the variable if not
>>>> present in `TeX-document-variables'.  We can define a function similar
>>>> to `TeX-process-get-variable' to get the value of the variable from
>>>> the alist.
>>>
>>> Rather than modifying all the places where these values are accessed,
>>> couldn't we check the alist and set the buffer-local variables when a
>>> buffer is loaded?  When reading the alist, we could exclude variables
>>> that we don't allow.
>>
>> Sounds reasonable.  Actually, you suggested me the idea of not
>> creating a new alist, but rather defining a new function that sets the
>> relevant variables locally.  Much like `TeX-add-symbols' or
>> `LaTeX-add-environments'.
>
> Ah, I see.  Yes I think that could work quite well.  Could this be
> defined with TeX-auto-add-type or would we need to define a new macro?
>
>> I can try and write down a proof-of-concept, but probably later next
>> week.
>
> That sounds good - I shall wait and see :-).

please find attached my proposal.  It's only a proof-of-concept to show
how my idea works, it should then be extended to include other options
(for example, `TeX-engine', `TeX-PDF-mode', `TeX-PDF-from-DVI',
`ConTeXt-Mark-version', please suggest other relevant variables).

Bye,
Mosè
diff --git a/tex.el b/tex.el
index b85a72a..b3e9465 100644
--- a/tex.el
+++ b/tex.el
@@ -2513,6 +2513,16 @@ Return nil otherwise."
     (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move)
     (re-search-forward "^%+ *TeX-master:" nil t)))
 
+(defun TeX-add-document-variables (&rest var-val)
+  "Set first element of SYM-VAL to the next one, and so on.
+
+The variables are set if current file is not the master.  This is
+used to store variables shared among the whole document into the
+auto-saved file."
+  (unless (equal TeX-master t)
+    (while var-val
+      (set (pop var-val) (pop var-val)))))
+
 ;;; Style Paths
 
 (defcustom TeX-style-global (expand-file-name "style" TeX-data-directory)
@@ -3988,22 +3998,29 @@ If TEX is a directory, generate style files for all 
files in the directory."
                            LaTeX-provided-class-options))
            (pkg-opts (if (boundp 'LaTeX-provided-package-options)
                          LaTeX-provided-package-options))
-           (tex-cmd-opts TeX-command-extra-options)
            (verb-envs (when (boundp 'LaTeX-verbatim-environments-local)
                         LaTeX-verbatim-environments-local))
            (verb-macros-delims (when (boundp 
'LaTeX-verbatim-macros-with-delims-local)
                                  LaTeX-verbatim-macros-with-delims-local))
            (verb-macros-braces (when (boundp 
'LaTeX-verbatim-macros-with-braces-local)
                                  LaTeX-verbatim-macros-with-braces-local))
-           (dialect TeX-style-hook-dialect))
+           (dialect TeX-style-hook-dialect)
+           (master (equal TeX-master t))
+           tex-cmd-opts)
+       (when master
+         (setq tex-cmd-opts TeX-command-extra-options))
        (TeX-unload-style style)
        (with-current-buffer (generate-new-buffer file)
          (erase-buffer)
          (insert "(TeX-add-style-hook\n \""
                  style "\"\n (lambda ()")
-         (unless (string= tex-cmd-opts "")
-           (insert "\n   (setq TeX-command-extra-options\n"
-                   "         " (prin1-to-string tex-cmd-opts) ")"))
+         (and
+          ;; Save only if current file is the master.
+          master
+          (null (string= tex-cmd-opts ""))
+          (insert "\n   (TeX-add-document-variables"
+                  "\n    'TeX-command-extra-options\n"
+                  "    " (prin1-to-string tex-cmd-opts) ")"))
          (when class-opts
            (insert "\n   (TeX-add-to-alist 'LaTeX-provided-class-options\n"
                    "                     '" (prin1-to-string class-opts) ")"))
_______________________________________________
auctex-devel mailing list
auctex-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/auctex-devel

Reply via email to