diff options
author | Thierry Volpiatto <thierry.volpiatto@gmail.com> | 2019-11-08 10:20:40 -0500 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2019-11-08 10:20:40 -0500 |
commit | 0a51c7012268d764ac4282b5969e4901ebeabfdb (patch) | |
tree | 04c4b567f846f0ee93f483ea3a28755a3e8fad4e /lisp/ffap.el | |
parent | 05167c1173c4a6c6850ba62da6757760e2df3507 (diff) | |
download | emacs-0a51c7012268d764ac4282b5969e4901ebeabfdb.tar.gz |
* lisp/ffap.el (ffap-read-file-or-url): Use `read-file-name`
Since we use `url-handler-mode` to deal with URLs, `read-file-name`
works just as well, with the added benefit that it interacts correctly
with packages that rebind `read-file-name-function`, such as Helm.
(ffap-read-url-internal, ffap-read-file-or-url-internal): Remove, unused.
Diffstat (limited to 'lisp/ffap.el')
-rw-r--r-- | lisp/ffap.el | 38 |
1 files changed, 7 insertions, 31 deletions
diff --git a/lisp/ffap.el b/lisp/ffap.el index c4e6d8dbf49..542aec77f81 100644 --- a/lisp/ffap.el +++ b/lisp/ffap.el @@ -1397,9 +1397,8 @@ which may actually result in an URL rather than a filename." ;; ;; We want to complete filenames as in read-file-name, but also url's ;; which read-file-name-internal would truncate at the "//" string. -;; The solution here is to replace read-file-name-internal with -;; `ffap-read-file-or-url-internal', which checks the minibuffer -;; contents before attempting to complete filenames. +;; The solution here is to forcefully activate url-handler-mode, which +;; takes care of it for us. (defun ffap-read-file-or-url (prompt guess) "Read file or URL from minibuffer, with PROMPT and initial GUESS." @@ -1414,22 +1413,17 @@ which may actually result in an URL rather than a filename." (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))) + (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))) - (completing-read - prompt - 'ffap-read-file-or-url-internal - nil - nil - (if dir (cons guess (length dir)) guess) - 'file-name-history - (and buffer-file-name - (abbreviate-file-name buffer-file-name))))) + (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 @@ -1438,24 +1432,6 @@ which may actually result in an URL rather than a filename." (or (ffap-url-p guess) (substitute-in-file-name guess)))) -(defun ffap-read-url-internal (string pred action) - "Complete URLs from history, treating given string as valid." - (let ((hist (ffap-symbol-value 'url-global-history-hash-table))) - (cond - ((not action) - (or (try-completion string hist pred) string)) - ((eq action t) - (or (all-completions string hist pred) (list string))) - ;; action == lambda, documented where? Tests whether string is a - ;; valid "match". Let us always say yes. - (t t)))) - -(defun ffap-read-file-or-url-internal (string pred action) - (let ((url (ffap-url-p string))) - (if url - (ffap-read-url-internal url pred action) - (read-file-name-internal (or string default-directory) pred action)))) - ;; The rest of this page is just to work with package complete.el. ;; This code assumes that you load ffap.el after complete.el. ;; |