all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Madhu <enometh@meer.net>
To: michael.albinus@gmx.de
Cc: 74208@debbugs.gnu.org
Subject: bug#74208: 31.0.50; minibuffer read-file-name-default mutates global value of default-directory incorrectly
Date: Sun, 08 Dec 2024 16:19:24 +0530 (IST)	[thread overview]
Message-ID: <20241208.161924.1904937058365373006.enometh@meer.net> (raw)
In-Reply-To: <87y10qv9y1.fsf@gmx.de>

[-- Attachment #1: Type: Text/Plain, Size: 1044 bytes --]

*  Michael Albinus <michael.albinus@gmx.de> <87y10qv9y1.fsf@gmx.de>
Wrote on Sun, 08 Dec 2024 09:46:30 +0100
>
> unhandled-file-name-directory expects, that special constructs in
> FILENAME are handled via a file name handler. Per default,
> "https://www.gnu.org/" is not covered by a file name handler, so I
> believe it is a non-valid value for default-directory.
>
> See
>
> --8<---------------cut here---------------start------------->8---
> (progn
>   (url-handler-mode)
>   (let ((default-directory "https://www.gnu.org/"))
>     (unhandled-file-name-directory default-directory)))
> => nil
> --8<---------------cut here---------------end--------------->8---
>
> Whether nil is a proper value to be returned is questionable. However,
> call-process and friends are able to handle a nil default-directory.

Thanks, something like the attached? the implementation of "turn on
url-handler-mode temporarily" looks a bit gross but i guess it can't
be avoided.  should call to turn it on be outside the
minibuffer-setup-hook? --Regards, Madhu


[-- Attachment #2: 0001-minibuffer.el-read-file-name-default-handle-default-.patch --]
[-- Type: Text/X-Patch, Size: 3045 bytes --]

From 91c22af6c317855370eb405f8daf6f56c68c4f9f Mon Sep 17 00:00:00 2001
From: Madhu <enometh@net.meer>
Date: Tue, 5 Nov 2024 07:19:55 +0530
Subject: [PATCH] minibuffer.el: (read-file-name-default): handle
 default-directory urls

* minibuffer.el: (read-file-name-default): bind default-directory
(in dynamic scope) instead of modifying it, protect setting against
non-local exits. Turn on url-handler-mode temporarily, so any calls to
call-process and friends do not fail because the default-directory is a
URL. (bug#24708)
---
 lisp/minibuffer.el | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index c970752ec2a..607a118dd53 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -3667,11 +3667,18 @@ read-file-name-default
                   ;; just use `default-directory', but in order to avoid
                   ;; changing `default-directory' in the current buffer,
                   ;; we don't let-bind it.
-                  (let ((dir (file-name-as-directory
-                              (expand-file-name dir))))
+                  (let* ((dir (file-name-as-directory
+                               (expand-file-name dir)))
+                         (default-directory dir)
+                         (orig-uhm url-handler-mode))
                     (minibuffer-with-setup-hook
                         (lambda ()
-                          (setq default-directory dir)
+                          ;; turn on url-handler-mode temporarily so
+                          ;; call-process and friends don't fail on on a
+                          ;; encountering a url default-directory
+                          ;; (bug#74208)
+                          (unless orig-uhm
+                            (url-handler-mode 1))
                           ;; When the first default in `minibuffer-default'
                           ;; duplicates initial input `insdef',
                           ;; reset `minibuffer-default' to nil.
@@ -3690,9 +3697,12 @@ read-file-name-default
                                      (window-buffer (minibuffer-selected-window))
 				   (read-file-name--defaults dir initial))))
 			  (set-syntax-table minibuffer-local-filename-syntax))
-                      (completing-read prompt 'read-file-name-internal
-                                       pred require-match insdef
-                                       'file-name-history default-filename)))
+                      (unwind-protect
+                          (completing-read prompt 'read-file-name-internal
+                                           pred require-match insdef
+                                           'file-name-history default-filename)
+                        (unless orig-uhm
+                          (url-handler-mode -1)))))
                 ;; If DEFAULT-FILENAME not supplied and DIR contains
                 ;; a file name, split it.
                 (let ((file (file-name-nondirectory dir))
-- 
2.46.0.27.gfa3b914457


  reply	other threads:[~2024-12-08 10:49 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-05  2:09 bug#74208: 31.0.50; minibuffer read-file-name-default mutates global value of default-directory incorrectly Madhu
2024-11-09 11:11 ` Eli Zaretskii
2024-11-09 16:11 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-10  0:57   ` Madhu
2024-11-10  6:00     ` Eli Zaretskii
2024-11-10  7:00       ` Madhu
2024-11-10 10:00         ` Eli Zaretskii
2024-11-10 10:41           ` Madhu
2024-11-10 10:45             ` Eli Zaretskii
2024-11-10 11:17               ` Madhu
2024-11-10 11:26                 ` Eli Zaretskii
2024-11-10 16:54         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-11  2:17           ` Madhu
2024-11-11  3:40             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-23 12:25               ` Eli Zaretskii
2024-11-23 14:56                 ` Madhu
2024-11-24  3:00                 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-24  7:19                   ` Eli Zaretskii
2024-12-07 12:20                     ` Eli Zaretskii
2024-12-07 17:23                       ` Madhu
2024-12-07 18:27                         ` Eli Zaretskii
2024-12-08  8:46                         ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-08 10:49                           ` Madhu [this message]
2024-12-08 11:33                             ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-08 11:59                               ` Madhu
2024-12-08 15:13                                 ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-08 16:26                                   ` Madhu
2024-12-08 17:28                                     ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-08 23:42                                       ` Madhu
2024-12-09  8:17                                         ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241208.161924.1904937058365373006.enometh@meer.net \
    --to=enometh@meer.net \
    --cc=74208@debbugs.gnu.org \
    --cc=michael.albinus@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.