* lisp/ffap.el (ffap-read-file-or-url): Simplify further

This commit is contained in:
Stefan Monnier 2019-11-08 13:32:46 -05:00
parent 0a51c70122
commit 24b74c35d5

View file

@ -1403,34 +1403,26 @@ which may actually result in an URL rather than a filename."
(defun ffap-read-file-or-url (prompt guess)
"Read file or URL from minibuffer, with PROMPT and initial GUESS."
(or guess (setq guess default-directory))
(let (dir)
;; Tricky: guess may have or be a local directory, like "w3/w3.elc"
;; or "w3/" or "../el/ffap.el" or "../../../"
(unless (ffap-url-p guess)
(unless (ffap-file-remote-p guess)
(setq guess
(abbreviate-file-name (expand-file-name guess))))
(setq dir (file-name-directory guess)))
(let ((minibuffer-completing-file-name t)
(completion-ignore-case read-file-name-completion-ignore-case)
(fnh-elem (cons ffap-url-regexp #'url-file-handler)))
;; Explain to `rfn-eshadow' that we can use URLs here.
(push fnh-elem file-name-handler-alist)
(unwind-protect
(setq guess
(let ((default-directory (if dir (expand-file-name dir)
default-directory)))
(read-file-name prompt default-directory
(and buffer-file-name
(abbreviate-file-name buffer-file-name))
nil)))
;; 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
;; during the completing-read call).
(setq file-name-handler-alist (delq fnh-elem file-name-handler-alist))))
(or (ffap-url-p guess)
(substitute-in-file-name guess))))
;; Tricky: guess may have or be a local directory, like "w3/w3.elc"
;; or "w3/" or "../el/ffap.el" or "../../../"
(unless (or (ffap-url-p guess)
(ffap-file-remote-p guess))
(setq guess
(abbreviate-file-name (expand-file-name guess))))
(let ((fnh-elem (cons ffap-url-regexp #'url-file-handler)))
;; Explain to `rfn-eshadow' that we can use URLs here.
(push fnh-elem file-name-handler-alist)
(unwind-protect
(setq guess
(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
;; during the completing-read call).
(setq file-name-handler-alist (delq fnh-elem file-name-handler-alist))))
(or (ffap-url-p guess)
(substitute-in-file-name guess)))
;; The rest of this page is just to work with package complete.el.
;; This code assumes that you load ffap.el after complete.el.