diff options
| author | Stefan Monnier | 2019-11-08 13:32:46 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2019-11-08 13:32:46 -0500 |
| commit | 24b74c35d5d037fbbe4a61be05ec0354ce150903 (patch) | |
| tree | 8c124306bd5e75b819c25f69641ada96b2457808 | |
| parent | 0a51c7012268d764ac4282b5969e4901ebeabfdb (diff) | |
| download | emacs-24b74c35d5d037fbbe4a61be05ec0354ce150903.tar.gz emacs-24b74c35d5d037fbbe4a61be05ec0354ce150903.zip | |
* lisp/ffap.el (ffap-read-file-or-url): Simplify further
| -rw-r--r-- | lisp/ffap.el | 48 |
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." | |||
| 1403 | (defun ffap-read-file-or-url (prompt guess) | 1403 | (defun ffap-read-file-or-url (prompt guess) |
| 1404 | "Read file or URL from minibuffer, with PROMPT and initial GUESS." | 1404 | "Read file or URL from minibuffer, with PROMPT and initial GUESS." |
| 1405 | (or guess (setq guess default-directory)) | 1405 | (or guess (setq guess default-directory)) |
| 1406 | (let (dir) | 1406 | ;; Tricky: guess may have or be a local directory, like "w3/w3.elc" |
| 1407 | ;; Tricky: guess may have or be a local directory, like "w3/w3.elc" | 1407 | ;; or "w3/" or "../el/ffap.el" or "../../../" |
| 1408 | ;; or "w3/" or "../el/ffap.el" or "../../../" | 1408 | (unless (or (ffap-url-p guess) |
| 1409 | (unless (ffap-url-p guess) | 1409 | (ffap-file-remote-p guess)) |
| 1410 | (unless (ffap-file-remote-p guess) | 1410 | (setq guess |
| 1411 | (setq guess | 1411 | (abbreviate-file-name (expand-file-name guess)))) |
| 1412 | (abbreviate-file-name (expand-file-name guess)))) | 1412 | (let ((fnh-elem (cons ffap-url-regexp #'url-file-handler))) |
| 1413 | (setq dir (file-name-directory guess))) | 1413 | ;; Explain to `rfn-eshadow' that we can use URLs here. |
| 1414 | (let ((minibuffer-completing-file-name t) | 1414 | (push fnh-elem file-name-handler-alist) |
| 1415 | (completion-ignore-case read-file-name-completion-ignore-case) | 1415 | (unwind-protect |
| 1416 | (fnh-elem (cons ffap-url-regexp #'url-file-handler))) | 1416 | (setq guess |
| 1417 | ;; Explain to `rfn-eshadow' that we can use URLs here. | 1417 | (read-file-name prompt (file-name-directory guess) nil nil |
| 1418 | (push fnh-elem file-name-handler-alist) | 1418 | (file-name-nondirectory guess))) |
| 1419 | (unwind-protect | 1419 | ;; Remove the special handler manually. We used to just let-bind |
| 1420 | (setq guess | 1420 | ;; file-name-handler-alist to preserve its value, but that caused |
| 1421 | (let ((default-directory (if dir (expand-file-name dir) | 1421 | ;; other modifications to be lost (e.g. when Tramp gets loaded |
| 1422 | default-directory))) | 1422 | ;; during the completing-read call). |
| 1423 | (read-file-name prompt default-directory | 1423 | (setq file-name-handler-alist (delq fnh-elem file-name-handler-alist)))) |
| 1424 | (and buffer-file-name | 1424 | (or (ffap-url-p guess) |
| 1425 | (abbreviate-file-name buffer-file-name)) | 1425 | (substitute-in-file-name guess))) |
| 1426 | nil))) | ||
| 1427 | ;; Remove the special handler manually. We used to just let-bind | ||
| 1428 | ;; file-name-handler-alist to preserve its value, but that caused | ||
| 1429 | ;; other modifications to be lost (e.g. when Tramp gets loaded | ||
| 1430 | ;; during the completing-read call). | ||
| 1431 | (setq file-name-handler-alist (delq fnh-elem file-name-handler-alist)))) | ||
| 1432 | (or (ffap-url-p guess) | ||
| 1433 | (substitute-in-file-name guess)))) | ||
| 1434 | 1426 | ||
| 1435 | ;; The rest of this page is just to work with package complete.el. | 1427 | ;; The rest of this page is just to work with package complete.el. |
| 1436 | ;; This code assumes that you load ffap.el after complete.el. | 1428 | ;; This code assumes that you load ffap.el after complete.el. |