From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Madhu Newsgroups: gmane.emacs.bugs Subject: bug#74208: 31.0.50; minibuffer read-file-name-default mutates global value of default-directory incorrectly Date: Sun, 10 Nov 2024 06:27:00 +0530 (IST) Message-ID: <20241110.062700.1848871414792572122.enometh@meer.net> References: <20241105.073924.1479117425130782406.enometh@meer.net> Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Sun_Nov_10_06_27_00_2024_142)--" Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34730"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 74208@debbugs.gnu.org To: monnier@iro.umontreal.ca Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Nov 10 01:58:26 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 1t9wHZ-0008mA-JX for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 10 Nov 2024 01:58:26 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t9wHE-00022O-Rn; Sat, 09 Nov 2024 19:58:04 -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 1t9wHC-00021x-W6 for bug-gnu-emacs@gnu.org; Sat, 09 Nov 2024 19:58: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 1t9wHC-000388-NZ for bug-gnu-emacs@gnu.org; Sat, 09 Nov 2024 19:58: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:References:In-Reply-To:From:Date:To:Subject; bh=YfHO5JBoKBbV8wsMKQhs/lfJeT9ebJTeMq3A669UFkc=; b=e6uumvDTWngfaOLPZIme2ZHN9TdTCiCaJQYqLIiEAQQGAub9MrBbkg7TzqciDcpz+zlWs4XRXFDOYZgzt5m0kKoNhC6fPasjREnoXSPUhX4Lev+jQeuF74xVh0nxQL7jd5VPQthI7bci/LpF5x24B/SAbAuz//BTcmahsbIs2dXe5ovcZiJ6pOqW7NXt/IhpgVBYPH//jbbGAWVuf6BslT+usuC4xK9jJBKwRWLxQJcHH1HaIMpEbKjycDJG4dV2H9DCfakWvKsYZzhG93BYT9EkhoqV4uQ8yaY3H9l5J/tMEsGAe7fTbxV0FkgZ48V2PnUDLbJ4Vbpe+SmODrC7eA==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1t9wHC-000198-B9 for bug-gnu-emacs@gnu.org; Sat, 09 Nov 2024 19:58:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Madhu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 10 Nov 2024 00:58: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.17312002524347 (code B ref 74208); Sun, 10 Nov 2024 00:58:02 +0000 Original-Received: (at 74208) by debbugs.gnu.org; 10 Nov 2024 00:57:32 +0000 Original-Received: from localhost ([127.0.0.1]:54942 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t9wGh-000183-Ra for submit@debbugs.gnu.org; Sat, 09 Nov 2024 19:57:32 -0500 Original-Received: from smtp0.ctinetworks.com ([205.166.61.207]:55348) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t9wGe-00017t-1H for 74208@debbugs.gnu.org; Sat, 09 Nov 2024 19:57:29 -0500 X-ctinetworks-Watermark: 1732064244.55231@k/Da2ALokb7LuRAA9jic9A X-ctinetworks-Envelope-From: enometh@meer.net X-ctinetworks-VirusCheck: Found to be clean X-ctinetworks-Message-ID: CB77D601C.A3D10 Original-Received: from localhost (unknown [117.254.36.91]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: enometh@meer.net) by smtp0.ctinetworks.com (Postfix) with ESMTPSA id CB77D601C; Sat, 9 Nov 2024 19:57:22 -0500 (EST) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp0.ctinetworks.com CB77D601C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meer.net; s=ctidkims1; t=1731200243; bh=YfHO5JBoKBbV8wsMKQhs/lfJeT9ebJTeMq3A669UFkc=; h=Date:To:Cc:Subject:From:In-Reply-To:References:From; b=Bwlpb2bnB8PAqDedWhhDTyLVz1MJh9zkiecqUPBmnwtvx+e6QESq3Yorp6AEATIci itKfvLwoaGmrI/ZHLuCUWvP3cdpiWoUMkc21WZPrAQWmcFGQh5Sq7Zh3OTAwpNbOrX ETdzJi/xraiAUcIO6jDkadoiqRKtG+bVGd6fCKHs= In-Reply-To: X-Mailer: Mew version 6.9 on Emacs 31.0.50 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:295161 Archived-At: ----Next_Part(Sun_Nov_10_06_27_00_2024_142)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit [snip: I hope the context can be seen on the bug-list] * Stefan Monnier > 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. Ah yes I missed that, (though I haven't worked out yet how it works) > 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 still think the default-difectory should be let-bound so the binding is undone when the dynamic scope exits. I have not worked out where the default-directory is being restored to the original value, but i know it is possible for the global value to be set incorrectly (e.g. after a M-: (debug), quit - -in the recursive minibuffer which would do a non-local exit.) > I'm leaning towards declaring the `shell-command` behavior above as > a feature rather than a bug. We could avoid still binding default-directory to a non-directory. Using the logic of expand-file-name, how about the following: [shouldn't binding it before the call to `minibuffer-with-setup-hook' be equivalent to a top level let in a hypothetical (with-minibuffer-setup-hook FN &body BODY), or setting it via FN] ----Next_Part(Sun_Nov_10_06_27_00_2024_142)-- Content-Type: Text/X-Patch; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="0001-minibuffer.el-read-file-name-default-avoid-setting-i.patch" >From ff4a2e046a66f7b364ad570c7dce11dab4987155 Mon Sep 17 00:00:00 2001 From: Madhu Date: Tue, 5 Nov 2024 07:19:55 +0530 Subject: [PATCH] minibuffer.el: (read-file-name-default): avoid setting incorrect default-directory * minibuffer.el: (read-file-name-default): bind default-directory (in dynamic scope) instead of modifying it. try to bind it to a valid directory. (e.g. don't set it to a url when calling (ffap) at a url). --- lisp/minibuffer.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index c970752ec2a..672f7b2b318 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -3668,10 +3668,11 @@ read-file-name-default ;; changing `default-directory' in the current buffer, ;; we don't let-bind it. (let ((dir (file-name-as-directory - (expand-file-name dir)))) + (expand-file-name dir))) + (default-directory (if (file-name-absolute-p dir) + dir default-directory))) (minibuffer-with-setup-hook (lambda () - (setq default-directory dir) ;; When the first default in `minibuffer-default' ;; duplicates initial input `insdef', ;; reset `minibuffer-default' to nil. -- 2.46.0.27.gfa3b914457 ----Next_Part(Sun_Nov_10_06_27_00_2024_142)----