Commit 24b74c35 authored by Stefan Monnier's avatar Stefan Monnier

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

parent 0a51c701
Pipeline #3974 failed with stage
in 60 minutes and 23 seconds
......@@ -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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment