aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2019-11-08 13:59:23 -0500
committerStefan Monnier2019-11-08 13:59:23 -0500
commitb7f843adfd91bdbb24af7539a782d12767646fce (patch)
tree1cdccf5b08be9f9574f2a04bfee084f3e979d924
parent24b74c35d5d037fbbe4a61be05ec0354ce150903 (diff)
downloademacs-b7f843adfd91bdbb24af7539a782d12767646fce.tar.gz
emacs-b7f843adfd91bdbb24af7539a782d12767646fce.zip
* lisp/ffap.el (ffap-read-file-or-url): Fix some URL cases
-rw-r--r--lisp/ffap.el38
1 files changed, 24 insertions, 14 deletions
diff --git a/lisp/ffap.el b/lisp/ffap.el
index 6cf7656fb44..a3a191c5ae0 100644
--- a/lisp/ffap.el
+++ b/lisp/ffap.el
@@ -1409,20 +1409,30 @@ which may actually result in an URL rather than a filename."
1409 (ffap-file-remote-p guess)) 1409 (ffap-file-remote-p guess))
1410 (setq guess 1410 (setq guess
1411 (abbreviate-file-name (expand-file-name guess)))) 1411 (abbreviate-file-name (expand-file-name guess))))
1412 (let ((fnh-elem (cons ffap-url-regexp #'url-file-handler))) 1412 (if (and (ffap-url-p guess)
1413 ;; Explain to `rfn-eshadow' that we can use URLs here. 1413 ;; Exclude non-filename-like URLs like "mailto:..."
1414 (push fnh-elem file-name-handler-alist) 1414 (not (string-match "\\`[a-z]+://" guess)))
1415 (unwind-protect 1415 (read-string prompt guess nil nil t)
1416 (setq guess 1416 (let ((fnh-elem (cons ffap-url-regexp #'url-file-handler)))
1417 (read-file-name prompt (file-name-directory guess) nil nil 1417 ;; Explain to `rfn-eshadow' that we can use URLs here.
1418 (file-name-nondirectory guess))) 1418 (push fnh-elem file-name-handler-alist)
1419 ;; Remove the special handler manually. We used to just let-bind 1419 (unwind-protect
1420 ;; file-name-handler-alist to preserve its value, but that caused 1420 (let* ((dir (file-name-directory guess))
1421 ;; other modifications to be lost (e.g. when Tramp gets loaded 1421 ;; FIXME: If `guess' is "http://a" url-handler
1422 ;; during the completing-read call). 1422 ;; somehow returns "https://a/" for the directory and
1423 (setq file-name-handler-alist (delq fnh-elem file-name-handler-alist)))) 1423 ;; "a" for the non-directory!
1424 (or (ffap-url-p guess) 1424 (broken-dir (> (length dir) (length guess))))
1425 (substitute-in-file-name guess))) 1425 (setq guess
1426 (read-file-name prompt (if broken-dir guess dir) nil nil
1427 (unless broken-dir
1428 (file-name-nondirectory guess)))))
1429 ;; Remove the special handler manually. We used to just let-bind
1430 ;; file-name-handler-alist to preserve its value, but that caused
1431 ;; other modifications to be lost (e.g. when Tramp gets loaded
1432 ;; during the completing-read call).
1433 (setq file-name-handler-alist (delq fnh-elem file-name-handler-alist))))
1434 (or (ffap-url-p guess)
1435 (substitute-in-file-name guess))))
1426 1436
1427;; The rest of this page is just to work with package complete.el. 1437;; The rest of this page is just to work with package complete.el.
1428;; This code assumes that you load ffap.el after complete.el. 1438;; This code assumes that you load ffap.el after complete.el.