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: Sun, 10 Nov 2024 22:40:27 -0500 Message-ID: References: <86msi7ljb0.fsf@gnu.org> <20241110.123007.483734644166546380.enometh@meer.net> <20241111.074725.1221470735788072992.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="6586"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: eliz@gnu.org, 74208@debbugs.gnu.org To: Madhu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Nov 11 04:41:18 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 1tALIk-0001WJ-6H for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 11 Nov 2024 04:41:18 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tALIW-0001RR-Nt; Sun, 10 Nov 2024 22:41: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 1tALIV-0001RI-1Q for bug-gnu-emacs@gnu.org; Sun, 10 Nov 2024 22:41: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 1tALIU-0007s7-PD for bug-gnu-emacs@gnu.org; Sun, 10 Nov 2024 22:41: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=AaicXoqFX9jdkDLOQCDEa7mJWXO8k92XAHTL5QVNdiQ=; b=eTV7CeGO5I/mfqVpoOdoH8qa7YZNQ7vsPy0P1qb87i0YQkyVSMsZj/yGcO3P5AnYt7QQvegYpKHIfe4mOzNJ+viGkRGxRM/7e5HktyCjV/5i8PBKFUBRU4m9Jt0AG4Ebn0p8od7B7Ff402/sx7jfzWrJ3Vw4Mqkg4mtyRElhX0VQop3cbdXttJXgeNCtgqLP6IzGXdhh5k9PfjQVC3/yrA3i9o5XPp14yPREjnEPpMBFqhFksRphsMuM0fB+VZj5XNmf270ML0k7hDhk0q2+CyIunU9wOndTRols1zjEUK5byK+5XXJPdzbVjZuGXmPRAgeR9FSBRoMUrfrso+H6TA==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tALIU-0006VE-9U for bug-gnu-emacs@gnu.org; Sun, 10 Nov 2024 22:41: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: Mon, 11 Nov 2024 03:41: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.173129643924947 (code B ref 74208); Mon, 11 Nov 2024 03:41:02 +0000 Original-Received: (at 74208) by debbugs.gnu.org; 11 Nov 2024 03:40:39 +0000 Original-Received: from localhost ([127.0.0.1]:57363 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tALI7-0006UI-6u for submit@debbugs.gnu.org; Sun, 10 Nov 2024 22:40:39 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:13493) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tALI4-0006U3-0i for 74208@debbugs.gnu.org; Sun, 10 Nov 2024 22:40:38 -0500 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id DC59C100417; Sun, 10 Nov 2024 22:40:28 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1731296428; bh=ksLAJHI57xt7ViFssEbBNze3CW+WVT6a9/s7uc0xkSM=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=CHHeve7ATbCpi/wqd1Z1hZQDxJF1I8JWq31dvlodkuuu75CisB3IB+q0EG1RwbSGD q6a/Wuv5vXNEkuxDPgNA3fMHzWgFDq7s+TyuIz1c7jJUxqOtjM6XBgma45aMkLFx9I hayjOYMqRJXE8B5vvqGCyvMXV0SnX/AANfDLvirhe230l8i1sUwnSe1BJ4H4Hz9ExF BKTalzujGTrfzDxAVivYlYGoyhJRV2MdqhzMDIubYmvXKFbQABPYPYGjbU+XJ1zEsb z6NStK1kGr8lRGFZQE8a3Unct6w3MMF/arYhrqupLbG19sG1t/QxUzQDXnQXb+02SA J1/Y/ogHH0NfQ== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 11BC21001D9; Sun, 10 Nov 2024 22:40:28 -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 DB0AA12020E; Sun, 10 Nov 2024 22:40:27 -0500 (EST) In-Reply-To: <20241111.074725.1221470735788072992.enometh@meer.net> (Madhu's message of "Mon, 11 Nov 2024 07:47:25 +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:295213 Archived-At: >>> The problem is that the parameter DIR == "http://example.com" was >>> getting bound to default-directory with undesirable results. > >> It can also have desirable results sometimes (depends on the URL at point >> and what kind of support for URLs you have in your Emacs, admittedly). >> Do you happen to have a more realistic scenario than your "echo foo" >> that lets us better judge the severity of the problem, and maybe other >> ways to solve the actual problem? > > Are you saying it is ok for emacs to make all calls to `call-prcoess' > to unconditionally fail --- when emacs is waiting for input at the > minibuffer? the calls to call-process can come from anywhere, from > timers, or from outside via emacsclient, etc. `default-directory` can point to random places, including non-existing directories, HTTP places (e.g. if you enable `url-handler-mode`), so code like timers need to take this possibility into account, yes. The ffap minibuffer discussed here is just one of many other ways to get into this situation. > I already posted that any hypothetical completion facilites are > singularly useless for the task of ffap (url) -- to get the url at > point into the minibuffer and maybe manually edit it. If these > facilities exist and you are using them, I'd like to see an example. diff --git a/lisp/url/url-handlers.el b/lisp/url/url-handlers.el index 9edc7865a74..17013345c25 100644 --- a/lisp/url/url-handlers.el +++ b/lisp/url/url-handlers.el @@ -375,18 +375,48 @@ url-insert-file-contents-literally (kill-buffer buffer) nil)) -(defun url-file-name-completion (url _directory &optional _predicate) - ;; Even if it's not implemented, it's not an error to ask for completion, - ;; in case it's available (bug#14806). - ;; (error "Unimplemented") - url) +(defun url-file-name-completion (url directory &optional predicate) + (let ((all (url-file-name-all-completions url directory))) + (if (null all) + ;; If `url' is the empty string, don't return nil, so as to prevent + ;; partial-completion from recursing into the parent directory. + (if (equal url "") url) + (try-completion url all predicate)))) (put 'file-name-completion 'url-file-handlers #'url-file-name-completion) -(defun url-file-name-all-completions (_file _directory) - ;; Even if it's not implemented, it's not an error to ask for completion, - ;; in case it's available (bug#14806). - ;; (error "Unimplemented") - nil) +(defvar url-handler-temp-buf) + +(defun url-file-name-all-completions (file directory) + ;; FIXME: Cache the "directory" buffers between completion requests. + (let ((buf (get-file-buffer directory))) + (unless buf + (setq buf (ignore-errors (find-file-noselect directory))) + (when buf + (with-current-buffer buf + (set (make-local-variable 'url-handler-temp-buf) t)))) + (when buf + (unwind-protect + (with-current-buffer buf + (save-excursion + (let ((all ()) + (case-fold-search t) + ;; FIXME: Handle URL-quoting. + (regexp (format "