From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#70409: 30.0.50; `latexenc-find-file-coding-system` uses `TeX-master` before we know it's safe Date: Mon, 15 Apr 2024 18:42:36 -0400 Message-ID: Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26611"; mail-complaints-to="usenet@ciao.gmane.io" Cc: monnier@iro.umontreal.ca To: 70409@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Apr 16 00:44:14 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rwV3d-0006jR-KA for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 16 Apr 2024 00:44:13 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rwV3I-0000uF-QK; Mon, 15 Apr 2024 18:43:52 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rwV3H-0000tq-8j for bug-gnu-emacs@gnu.org; Mon, 15 Apr 2024 18:43:51 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rwV3H-0008FT-0R for bug-gnu-emacs@gnu.org; Mon, 15 Apr 2024 18:43:51 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rwV3S-0007T1-Er; Mon, 15 Apr 2024 18:44:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: monnier@iro.umontreal.ca, bug-gnu-emacs@gnu.org Resent-Date: Mon, 15 Apr 2024 22:44:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 70409 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org X-Debbugs-Original-Xcc: monnier@iro.umontreal.ca Original-Received: via spool by submit@debbugs.gnu.org id=B.171322098828273 (code B ref -1); Mon, 15 Apr 2024 22:44:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 15 Apr 2024 22:43:08 +0000 Original-Received: from localhost ([127.0.0.1]:40070 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rwV2Y-0007Ll-EE for submit@debbugs.gnu.org; Mon, 15 Apr 2024 18:43:08 -0400 Original-Received: from lists.gnu.org ([2001:470:142::17]:47044) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rwV2S-0007Ji-Kw for submit@debbugs.gnu.org; Mon, 15 Apr 2024 18:43:04 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rwV2B-0000jZ-9v for bug-gnu-emacs@gnu.org; Mon, 15 Apr 2024 18:42:43 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rwV29-00085C-7O for bug-gnu-emacs@gnu.org; Mon, 15 Apr 2024 18:42:42 -0400 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id F0F4380A6B; Mon, 15 Apr 2024 18:42:38 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1713220957; bh=szhegStluImvn2hWZqUUnpUnoK65J/z/30T9kFhcOLI=; h=From:To:Subject:Date:From; b=mmfUl9NMkvEdnTaNtkj2Jr+2EHuJTtY+QlMI3fg2Me95aXnrzrF4M4yRFhRIj83xf PoHYNDZgeeewsTrDNLy1J0yuY9ELSTniHWxFCsJvQ6xXRQviCuS1bpcFZa0omjuoxp qGqUVV/nKEW5veV6YiMWeCOu1o/c6ZbyY4wDJCdza0HAqJrr6iNN68KQl6aFlQ77Qh Pyx2EkmOo8n9IwMN1de70HeBlFtNQWsi1GiAgdkqQFPYOpxG5TPEIPp20+NoCirIvq p946vM7J+9Fkk1+zB2jVpPyEpug0JzCK2b4E270je6qBJiW92ovND9w3G3SJPSyZ0o kyDQYjuVo5JOQ== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id C7F548004C; Mon, 15 Apr 2024 18:42:37 -0400 (EDT) Original-Received: from pastel (unknown [45.72.201.215]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id A96851202D7; Mon, 15 Apr 2024 18:42:37 -0400 (EDT) Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:283400 Archived-At: --=-=-= Content-Type: text/plain Package: Emacs Version: 30.0.50 If I open a file `foo.tex` with a local variable setting of `TeX-master: "paper.tex"` and that `paper.tex` file has a local variable setting of `TeX-master: t`, I get the funny behavior that Emacs first asks me whether to obey the `TeX-master: t` setting of `paper.tex` before asking me whether to obey the `TeX-master: "paper.tex"` setting of `foo.tex`, even though it obviously had to use the `TeX-master: "paper.tex"` setting in order to decide to open the `paper.tex` file (and ask me about its `TeX-master: t`). The corresponding backtrace looks as below: Debugger entered--Lisp error: (minibuffer-quit) #() read-char-from-minibuffer("Please type y, n, ! or i, or C-v/M-v to scroll: " (33 105 121 110 32)) read-char-choice("Please type y, n, ! or i, or C-v/M-v to scroll: " (33 105 121 110 32)) hack-local-variables-confirm(((TeX-master . t)) ((TeX-master . t)) nil nil) hack-local-variables-filter(((TeX-master . t)) nil) hack-local-variables(no-mode) run-mode-hooks(latex-mode-hook) latex-mode() set-auto-mode-0(latex-mode nil) set-auto-mode() normal-mode(t) after-find-file(nil nil) find-file-noselect-1(# ".../paper.tex" t nil ".../paper.tex" (3064599 65026)) find-file-noselect("paper.tex" t) latexenc-find-file-coding-system((insert-file-contents ".../foo.tex" t nil nil nil)) insert-file-contents(".../foo.tex" t) find-file-noselect-1(# ".../foo.tex" nil nil ".../foo.tex" (3064581 65026)) find-file-noselect(".../foo.tex") command-line-1((".../foo.tex")) command-line() normal-top-level() showing that the problem is that `latexenc-find-file-coding-system` is the function that opens `paper.tex` before the users had a chance to confirm that they think this is safe. I suggest the patch below which makes `latexenc-find-file-coding-system` use `safe-local-variable-p` before using a file-local setting, and also adds corresponding `safe-local-variable` settings for `TeX-master` and `tex-main-file`. Stefan --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=tex-master.diff 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 --=-=-=--