(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.
This commit is contained in:
Stefan Monnier
2026-04-08 15:19:06 -04:00
parent 7c5ab95f03
commit 666955dfa0
2 changed files with 14 additions and 7 deletions

View File

@@ -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."

View File

@@ -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: