Hi Arash and all,

2016-12-11 23:29 GMT+01:00 Arash Esbati <arash.esbati...@gmail.com>:
> Hi Mosè,
>
> Mosè Giordano <m...@gnu.org> writes:
>
>> this question http://emacs.stackexchange.com/q/29081/620 shows that it
>> could be useful to visit the master file when creating a new file, in
>> order to grab some variables from it, like the major mode.  What do
>> you think?  Anything against this feature?
>
> Sounds reasonable to me.

Good.  If no objection will come in the next few days I'll apply the
attached patch.

Bye,
Mosè
diff --git a/tex.el b/tex.el
index e192899..1b5f2cb 100644
--- a/tex.el
+++ b/tex.el
@@ -2513,7 +2513,9 @@ name of master file if it cannot be determined otherwise."
 	   (file-name-directory buffer-file-name)))))))
 
 (defun TeX-add-local-master ()
-  "Add local variable for `TeX-master'."
+  "Add local variable for `TeX-master'.
+
+Get `major-mode' from master file and enable it."
   (when (and (buffer-file-name)
 	     (string-match TeX-one-master
 			   (file-name-nondirectory (buffer-file-name)))
@@ -2526,20 +2528,27 @@ name of master file if it cannot be determined otherwise."
 						   "End:")))
 	  (beginning-of-line 1)
 	  (insert prefix "TeX-master: " (prin1-to-string TeX-master) "\n"))
-      (let ((comment-prefix (cond ((eq major-mode 'texinfo-mode) "@c ")
-				  ((eq major-mode 'doctex-mode) "% ")
-				  (t "%%% ")))
-	    (mode (concat (and (boundp 'japanese-TeX-mode) japanese-TeX-mode
-			       "japanese-")
-			  (substring (symbol-name major-mode) 0 -5))))
+      (let* ((mode (if (stringp TeX-master)
+		       (with-current-buffer
+			   (find-file-noselect
+			    (TeX-master-file TeX-default-extension))
+			 major-mode)
+		     major-mode))
+	     (comment-prefix (cond ((eq mode 'texinfo-mode) "@c ")
+				   ((eq mode 'doctex-mode) "% ")
+				   (t "%%% ")))
+	     (mode-string (concat (and (boundp 'japanese-TeX-mode) japanese-TeX-mode
+				       "japanese-")
+				  (substring (symbol-name mode) 0 -5))))
 	(newline)
 	(when (eq major-mode 'doctex-mode)
 	  (insert comment-prefix TeX-esc "endinput\n"))
 	(insert
 	 comment-prefix "Local Variables:\n"
-	 comment-prefix "mode: " mode "\n"
+	 comment-prefix "mode: " mode-string "\n"
 	 comment-prefix "TeX-master: " (prin1-to-string TeX-master) "\n"
-	 comment-prefix "End:\n")))))
+	 comment-prefix "End:\n")
+	(funcall mode)))))
 
 (defun TeX-local-master-p ()
   "Return non-nil if there is a `TeX-master' entry in local variables spec.
_______________________________________________
auctex-devel mailing list
auctex-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/auctex-devel

Reply via email to