diff options
| author | Thierry Volpiatto | 2019-11-08 10:20:40 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2019-11-08 10:20:40 -0500 |
| commit | 0a51c7012268d764ac4282b5969e4901ebeabfdb (patch) | |
| tree | 04c4b567f846f0ee93f483ea3a28755a3e8fad4e | |
| parent | 05167c1173c4a6c6850ba62da6757760e2df3507 (diff) | |
| download | emacs-0a51c7012268d764ac4282b5969e4901ebeabfdb.tar.gz emacs-0a51c7012268d764ac4282b5969e4901ebeabfdb.zip | |
* 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.
| -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." | |||
| 1397 | ;; | 1397 | ;; |
| 1398 | ;; We want to complete filenames as in read-file-name, but also url's | 1398 | ;; We want to complete filenames as in read-file-name, but also url's |
| 1399 | ;; which read-file-name-internal would truncate at the "//" string. | 1399 | ;; which read-file-name-internal would truncate at the "//" string. |
| 1400 | ;; The solution here is to replace read-file-name-internal with | 1400 | ;; The solution here is to forcefully activate url-handler-mode, which |
| 1401 | ;; `ffap-read-file-or-url-internal', which checks the minibuffer | 1401 | ;; takes care of it for us. |
| 1402 | ;; contents before attempting to complete filenames. | ||
| 1403 | 1402 | ||
| 1404 | (defun ffap-read-file-or-url (prompt guess) | 1403 | (defun ffap-read-file-or-url (prompt guess) |
| 1405 | "Read file or URL from minibuffer, with PROMPT and initial GUESS." | 1404 | "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." | |||
| 1414 | (setq dir (file-name-directory guess))) | 1413 | (setq dir (file-name-directory guess))) |
| 1415 | (let ((minibuffer-completing-file-name t) | 1414 | (let ((minibuffer-completing-file-name t) |
| 1416 | (completion-ignore-case read-file-name-completion-ignore-case) | 1415 | (completion-ignore-case read-file-name-completion-ignore-case) |
| 1417 | (fnh-elem (cons ffap-url-regexp 'url-file-handler))) | 1416 | (fnh-elem (cons ffap-url-regexp #'url-file-handler))) |
| 1418 | ;; Explain to `rfn-eshadow' that we can use URLs here. | 1417 | ;; Explain to `rfn-eshadow' that we can use URLs here. |
| 1419 | (push fnh-elem file-name-handler-alist) | 1418 | (push fnh-elem file-name-handler-alist) |
| 1420 | (unwind-protect | 1419 | (unwind-protect |
| 1421 | (setq guess | 1420 | (setq guess |
| 1422 | (let ((default-directory (if dir (expand-file-name dir) | 1421 | (let ((default-directory (if dir (expand-file-name dir) |
| 1423 | default-directory))) | 1422 | default-directory))) |
| 1424 | (completing-read | 1423 | (read-file-name prompt default-directory |
| 1425 | prompt | 1424 | (and buffer-file-name |
| 1426 | 'ffap-read-file-or-url-internal | 1425 | (abbreviate-file-name buffer-file-name)) |
| 1427 | nil | 1426 | nil))) |
| 1428 | nil | ||
| 1429 | (if dir (cons guess (length dir)) guess) | ||
| 1430 | 'file-name-history | ||
| 1431 | (and buffer-file-name | ||
| 1432 | (abbreviate-file-name buffer-file-name))))) | ||
| 1433 | ;; Remove the special handler manually. We used to just let-bind | 1427 | ;; Remove the special handler manually. We used to just let-bind |
| 1434 | ;; file-name-handler-alist to preserve its value, but that caused | 1428 | ;; file-name-handler-alist to preserve its value, but that caused |
| 1435 | ;; other modifications to be lost (e.g. when Tramp gets loaded | 1429 | ;; 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." | |||
| 1438 | (or (ffap-url-p guess) | 1432 | (or (ffap-url-p guess) |
| 1439 | (substitute-in-file-name guess)))) | 1433 | (substitute-in-file-name guess)))) |
| 1440 | 1434 | ||
| 1441 | (defun ffap-read-url-internal (string pred action) | ||
| 1442 | "Complete URLs from history, treating given string as valid." | ||
| 1443 | (let ((hist (ffap-symbol-value 'url-global-history-hash-table))) | ||
| 1444 | (cond | ||
| 1445 | ((not action) | ||
| 1446 | (or (try-completion string hist pred) string)) | ||
| 1447 | ((eq action t) | ||
| 1448 | (or (all-completions string hist pred) (list string))) | ||
| 1449 | ;; action == lambda, documented where? Tests whether string is a | ||
| 1450 | ;; valid "match". Let us always say yes. | ||
| 1451 | (t t)))) | ||
| 1452 | |||
| 1453 | (defun ffap-read-file-or-url-internal (string pred action) | ||
| 1454 | (let ((url (ffap-url-p string))) | ||
| 1455 | (if url | ||
| 1456 | (ffap-read-url-internal url pred action) | ||
| 1457 | (read-file-name-internal (or string default-directory) pred action)))) | ||
| 1458 | |||
| 1459 | ;; The rest of this page is just to work with package complete.el. | 1435 | ;; The rest of this page is just to work with package complete.el. |
| 1460 | ;; This code assumes that you load ffap.el after complete.el. | 1436 | ;; This code assumes that you load ffap.el after complete.el. |
| 1461 | ;; | 1437 | ;; |