summaryrefslogtreecommitdiff
path: root/lisp/ffap.el
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2019-11-08 13:32:46 -0500
committerStefan Monnier <monnier@iro.umontreal.ca>2019-11-08 13:32:46 -0500
commit24b74c35d5d037fbbe4a61be05ec0354ce150903 (patch)
tree8c124306bd5e75b819c25f69641ada96b2457808 /lisp/ffap.el
parent0a51c7012268d764ac4282b5969e4901ebeabfdb (diff)
downloademacs-24b74c35d5d037fbbe4a61be05ec0354ce150903.tar.gz
* lisp/ffap.el (ffap-read-file-or-url): Simplify further
Diffstat (limited to 'lisp/ffap.el')
-rw-r--r--lisp/ffap.el48
1 files changed, 20 insertions, 28 deletions
diff --git a/lisp/ffap.el b/lisp/ffap.el
index 542aec77f81..6cf7656fb44 100644
--- a/lisp/ffap.el
+++ b/lisp/ffap.el
@@ -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.