2016-04-20 23:12 GMT+02:00 Matthew Leach <[email protected]>:
>> 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.
>                            ^^^^^^^
>                            Should this be VAR-VAL?

Yes, thanks for pointing this out.

>>
>> + +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 ""))
>
> If we are going to be extending this idea for other variables, maybe we
> could have a macro that builds the TeX-command-extra-options form to be
> written to the auto-save file?  Performing these checks for every
> variable may become a little cumbersome.

I'm not sure I understand what you mean here.

Before you replied, I was about to send the improved patch that you
can find attached to this email.  I have only a doubt: whether to run
`hack-local-variables' in `TeX-auto-store' or not (it's commented in
my patch).  It ensures that a change to a local variable in master
file is immediately written to the auto-saved file (otherwise one
needs to reparse the file twice), but running that function may also
be considered an overhead.

Comments (from anyone!) welcome.

Bye,
Mosè
diff --git a/tex.el b/tex.el
index b85a72a..6e1f977 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 sym-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 sym-val) (pop sym-val)))))
+
 ;;; Style Paths
 
 (defcustom TeX-style-global (expand-file-name "style" TeX-data-directory)
@@ -3988,22 +3998,39 @@ 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))
+           shared-variables)
+       ;; If we are parsing master file, retrieve variables to be shared among
+       ;; the whole document.
+       (when master
+         ;; (hack-local-variables) ;; <= !!!!!
+         (dolist (var '(TeX-engine TeX-PDF-mode TeX-command-extra-options
+                                   TeX-PDF-from-DVI ConTeXt-Mark-version))
+           ;; Add the variable only if it has a local binding.
+           (when (local-variable-p var)
+             (push (cons var (symbol-value var)) shared-variables))))
        (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
+          shared-variables
+          (insert "\n   (TeX-add-document-variables"
+                  (mapconcat (lambda (sym-val)
+                               (concat "\n    '" (prin1-to-string (car 
sym-val))
+                                       "\n    " (prin1-to-string (cdr 
sym-val))))
+                             shared-variables "")
+                  ")"))
          (when class-opts
            (insert "\n   (TeX-add-to-alist 'LaTeX-provided-class-options\n"
                    "                     '" (prin1-to-string class-opts) ")"))
_______________________________________________
auctex-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/auctex-devel

Reply via email to