From 666955dfa0e8420a0e6d47d4482d08c7840cd9f8 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Wed, 8 Apr 2026 15:19:06 -0400 Subject: [PATCH] (dired-at-point-prompter): Fix bug#80545 * lisp/ffap.el (ffap-read-file-or-url): Add `read-dir` argument to indicate we expect a directory as return value. Avoid `read-file-name` when we want a directory and the dialog UI might prevent us from doing so. (dired-at-point-prompter): Use the new arg. --- lisp/dired.el | 5 +++-- lisp/ffap.el | 16 +++++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lisp/dired.el b/lisp/dired.el index 4aded86e40d..353190347db 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -1237,8 +1237,9 @@ If DIRNAME is already in a Dired buffer, that buffer is used without refresh." (prog1 (pop-to-buffer-same-window (dired-noselect dirname switches)) (dired--display-ls-error))) -;; This is needed to let clicks on the menu bar invoke Dired even if -;; some feature remaps the Dired command to another command. +;; This lets clicks on the menu bar invoke Dired even if some feature +;; remaps the Dired command to another command that does not handle this +;; situation correctly (e.g. earlier versions of `dired-at-point-prompter'). ;;;###autoload (defun dired-from-menubar (dirname &optional switches) "Edit an existing directory." diff --git a/lisp/ffap.el b/lisp/ffap.el index 800437d69c9..2e88adfaf4a 100644 --- a/lisp/ffap.el +++ b/lisp/ffap.el @@ -1607,7 +1607,7 @@ which may actually result in an URL rather than a filename." (otherwise (apply operation args))))) -(defun ffap-read-file-or-url (prompt guess) +(defun ffap-read-file-or-url (prompt guess &optional read-dir) "Read file or URL from minibuffer, with PROMPT and initial GUESS." (let ((elem (cons ffap-url-regexp #'ffap--url-file-handler))) (unwind-protect @@ -1623,9 +1623,14 @@ which may actually result in an URL rather than a filename." (setq guess default-directory)) (unless (ffap-file-remote-p guess) (setq guess (abbreviate-file-name (expand-file-name guess)))) - (read-file-name prompt - (file-name-directory guess) nil nil - (file-name-nondirectory guess)))) + (funcall + ;; Copied from `dired-read-dir-and-switches'. + (if (and read-dir (next-read-file-uses-dialog-p)) + #'read-directory-name + #'read-file-name) + prompt + (file-name-directory guess) nil nil + (file-name-nondirectory guess)))) ;; Remove the special handler manually. We used to just let-bind ;; file-name-handler-alist to preserve its value, but that caused ;; other modifications to be lost (e.g. when Tramp gets loaded @@ -2158,7 +2163,8 @@ If `dired-at-point-require-prefix' is set, the prefix meaning is reversed." ((file-regular-p guess) (file-name-directory guess)) (guess)))) - (and guess (ffap-highlight)))) + (and guess (ffap-highlight))) + 'read-dir) (ffap-highlight t))) ;;; ffap-dired-other-*, ffap-list-directory commands: