diff --git a/lisp/international/latexenc.el b/lisp/international/latexenc.el index 6e2306449bc..66e3faa37b9 100644 --- a/lisp/international/latexenc.el +++ b/lisp/international/latexenc.el @@ -155,14 +155,16 @@ latexenc-find-file-coding-system (when (re-search-forward "^%+ *\\(TeX-master\\|tex-main-file\\): *\"\\(.+\\)\"" nil t) - (let ((file (match-string 2))) - (dolist (ext `("" ,(if (boundp 'TeX-default-extension) - (concat "." TeX-default-extension) - "") - ".tex" ".ltx" ".dtx" ".drv")) - (if (and (null latexenc-main-file) ;Stop at first. - (file-exists-p (concat file ext))) - (setq latexenc-main-file (concat file ext))))))) + (let ((var (match-string 1)) + (file (match-string 2))) + (when (safe-local-variable-p (intern var) file) + (dolist (ext `("" ,(if (boundp 'TeX-default-extension) + (concat "." TeX-default-extension) + "") + ".tex" ".ltx" ".dtx" ".drv")) + (if (and (null latexenc-main-file) ;Stop at first. + (file-exists-p (concat file ext))) + (setq latexenc-main-file (concat file ext)))))))) ;; try tex-modes tex-guess-main-file (when (and (not latexenc-dont-use-tex-guess-main-file-flag) (not latexenc-main-file)) diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el index 02ee1242c72..e7b1522751f 100644 --- a/lisp/textmodes/tex-mode.el +++ b/lisp/textmodes/tex-mode.el @@ -89,6 +89,7 @@ tex-main-file if the variable is non-nil." :type '(choice (const :tag "None" nil) file) + :safe #'stringp :group 'tex-file) ;;;###autoload @@ -2213,6 +2214,10 @@ tex-guess-main-file header-re (+ (point) 10000) t)))) (throw 'found (expand-file-name buffer-file-name)))))))) +(unless (get 'TeX-master 'safe-local-variable) ;Don't override AUCTeX's setting. + (put 'TeX-master 'safe-local-variable + (lambda (x) (or (booleanp x) (stringp x))))) + (defun tex-main-file () "Return the relative name of the main file." (let* ((file (or tex-main-file