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#74208: 31.0.50; minibuffer read-file-name-default mutates global value of default-directory incorrectly Date: Sat, 09 Nov 2024 11:11:19 -0500 Message-ID: References: <20241105.073924.1479117425130782406.enometh@meer.net> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3257"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 74208@debbugs.gnu.org To: Madhu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Nov 09 17:12:23 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 1t9o4U-0000ik-F7 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 09 Nov 2024 17:12:22 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t9o4E-00059k-2c; Sat, 09 Nov 2024 11:12:06 -0500 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 1t9o4B-00059S-6k for bug-gnu-emacs@gnu.org; Sat, 09 Nov 2024 11:12:03 -0500 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 1t9o4A-0006S0-Pk for bug-gnu-emacs@gnu.org; Sat, 09 Nov 2024 11:12:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=7zzefgZj/SUS0KAxZ9DGyVo/ZaGniYWxetaxbpI0d7o=; b=R+Md5cKqLGY5aIS3XljzXosoSqbjW1KqbVceJyOJf7OG9+cHjl2bl5jlEMpdn48CRla25ZpVQ0GRQPL3YHU7GAyI9FKKIY0k/nKMWtsbQBcyYBrxckXS8KPdTEssBkwlrPiwZJZ+GCebZO1DDVQHwfc0GYQz6dJnC9HNrPj1yWvtkBQbN1aR0V7WnIPu8o5Ag7VIRe4tBkj6q8XsaxWKtDNKyW6P9xAr65P+CPtLkxDoPS+T6JY+Bhh1YyawhkUUihh9D0CTY/fFaclHs6GF4a1Qf+kQd3pjt3yL6nEkuW/6FM1dQL0V03At7KGDmoQLXuqYJakBxH9JC+eizQSA3g==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1t9o4A-00031V-KS for bug-gnu-emacs@gnu.org; Sat, 09 Nov 2024 11:12:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 09 Nov 2024 16:12:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74208 X-GNU-PR-Package: emacs Original-Received: via spool by 74208-submit@debbugs.gnu.org id=B74208.173116869011570 (code B ref 74208); Sat, 09 Nov 2024 16:12:02 +0000 Original-Received: (at 74208) by debbugs.gnu.org; 9 Nov 2024 16:11:30 +0000 Original-Received: from localhost ([127.0.0.1]:54144 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t9o3e-00030Y-8m for submit@debbugs.gnu.org; Sat, 09 Nov 2024 11:11:30 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:23861) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t9o3b-00030J-UU for 74208@debbugs.gnu.org; Sat, 09 Nov 2024 11:11:28 -0500 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 9A62D440BEA; Sat, 9 Nov 2024 11:11:21 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1731168680; bh=FVDpGRg3vqPuhKPgQLLHiDChuB6bNX9NgBbQ7WUV9t8=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=Z57kDhe2lJKCOKbuThm7kqC1T0aeufSHHGuHDCks1G23rO3y10n7xkC0Aapz+tfG8 4j8hqu1bsnuajhr8xrk8u033YMgfmvC963neXiA4pyM6nwxPWDf6dNPWuFhCr0qkEd JxYkmKgbBhPq4I33Z1Lcd/RoBpy07fCTokehabHJAiNIIXt+cQjwhgyb9hd+fCGVK1 lrQAl5iwB7F6YF4ROWzH1TgnR2WcEgtgdVRrZpl6KrpymvZcO0Sr/mq8T5/xdA/GBD wQRx+sdaPsHZ0P4N6p7rAsEWbn7W8i3L+dBEi9bFxEguvqZRGeTGSPI6E7ggCe0PEO W6bVFPwMU4ZKg== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 6F21C440B86; Sat, 9 Nov 2024 11:11:20 -0500 (EST) Original-Received: from pastel (104-195-225-43.cpe.teksavvy.com [104.195.225.43]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 45317120403; Sat, 9 Nov 2024 11:11:20 -0500 (EST) In-Reply-To: <20241105.073924.1479117425130782406.enometh@meer.net> (Madhu's message of "Tue, 05 Nov 2024 07:39:24 +0530 (IST)") 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:295140 Archived-At: > To demonstrate the problem, in emacs -Q > > (insert "http://example.com") > (setq enable-recursive-minibuffers t) > > position point at in the middle of the string http://example.com > M-: (ffap) > > ;; while waiting for input > M-: default-directory > ;; => default-directory is bound to "http://example.com" > M-: (shell-command "echo foo") > ; ;=> > ;; Debugger entered--Lisp error: (file-missing "Setting current directory" "No such file or directory" "http://example.com/") > > I think this can be addressed by binding default-directory before > modifying it. IIRC the `setq` is really there to set the value of `default-directory` during the whole duration of the completion, not just during the setup hook. This is needed/used if the user modifies the minibuffer's content to hold only a relative file name, at which point we need that default directory info in order to perform completions. > ``` > diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el > --- a/lisp/minibuffer.el > +++ b/lisp/minibuffer.el > @@ -3671,6 +3671,7 @@ read-file-name-default > (expand-file-name dir)))) > (minibuffer-with-setup-hook > (lambda () > + (let ((default-directory default-directory)) > (setq default-directory dir) > ;; When the first default in `minibuffer-default' > ;; duplicates initial input `insdef', > @@ -3689,7 +3690,7 @@ read-file-name-default > (with-current-buffer > (window-buffer (minibuffer-selected-window)) > (read-file-name--defaults dir initial)))) > - (set-syntax-table minibuffer-local-filename-syntax)) > + (set-syntax-table minibuffer-local-filename-syntax))) > (completing-read prompt 'read-file-name-internal > pred require-match insdef > 'file-name-history default-filename))) > ``` The let+setq could be simplified to (let ((default-directory dir)) but none of the code within this `let` uses `default-directory` since there are only calls to `car/cdr`, `setq`, and `set-syntax-table`, none of which touch file names, so we may as well remove the (setq default-directory dir) instead. I'm leaning towards declaring the `shell-command` behavior above as a feature rather than a bug. Stefan