summaryrefslogtreecommitdiff
path: root/lisp/ffap.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/ffap.el')
-rw-r--r--lisp/ffap.el54
1 files changed, 34 insertions, 20 deletions
diff --git a/lisp/ffap.el b/lisp/ffap.el
index 6faf8d50b26..84dcc04a712 100644
--- a/lisp/ffap.el
+++ b/lisp/ffap.el
@@ -260,6 +260,7 @@ ffap most of the time."
:type 'boolean
:group 'ffap)
+;;;###autoload
(defcustom ffap-file-finder 'find-file
"The command called by `find-file-at-point' to find a file."
:type 'function
@@ -1417,7 +1418,7 @@ which may actually result in an URL rather than a filename."
(string (ffap-string-at-point)) ; uses mode alist
(name
(or (condition-case nil
- (and (not (string-match "//" string)) ; foo.com://bar
+ (and (not (string-search "//" string)) ; foo.com://bar
(substitute-in-file-name string))
(error nil))
string))
@@ -1524,24 +1525,37 @@ which may actually result in an URL rather than a filename."
;; The solution here is to forcefully activate url-handler-mode, which
;; takes care of it for us.
+(defun ffap--url-file-handler (operation &rest args)
+ (let ((inhibit-file-name-handlers
+ (cons 'ffap--url-file-handler inhibit-file-name-handlers))
+ (inhibit-file-name-operation operation))
+ (cl-case operation
+ ;; We mainly just want to disable these bits:
+ (substitute-in-file-name (car args))
+ (expand-file-name (car args))
+ (otherwise
+ (apply operation args)))))
+
(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))
- ;; Tricky: guess may have or be a local directory, like "w3/w3.elc"
- ;; or "w3/" or "../el/ffap.el" or "../../../"
- (if (ffap-url-p guess)
- ;; FIXME: We earlier tried to make use of `url-file-handler' so
- ;; `read-file-name' could also be used for URLs, but it
- ;; introduced all kinds of subtle breakage such as:
- ;; - (file-name-directory "http://a") returning "http://a/"
- ;; - Trying to contact remote hosts with no justification
- ;; These should be fixed in url-handler-mode before we can try
- ;; using it here again.
- (read-string prompt guess nil nil t)
- (unless (ffap-file-remote-p guess)
- (setq guess (abbreviate-file-name (expand-file-name guess))))
- (read-file-name prompt (file-name-directory guess) nil nil
- (file-name-nondirectory guess))))
+ (let ((elem (cons ffap-url-regexp #'ffap--url-file-handler)))
+ (unwind-protect
+ (progn
+ (push elem file-name-handler-alist)
+ (if (ffap-url-p guess)
+ (read-file-name prompt guess guess)
+ (unless guess
+ (setq guess default-directory))
+ (unless (ffap-file-remote-p guess)
+ (setq guess (abbreviate-file-name (expand-file-name 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 elem file-name-handler-alist)))))
;; The rest of this page is just to work with package complete.el.
;; This code assumes that you load ffap.el after complete.el.
@@ -1653,9 +1667,9 @@ See also the variables `ffap-dired-wildcards', `ffap-newfile-prompt',
((or (not ffap-newfile-prompt)
(file-exists-p filename)
(y-or-n-p "File does not exist, create buffer? "))
- (funcall ffap-file-finder
- ;; expand-file-name fixes "~/~/.emacs" bug sent by CHUCKR.
- (expand-file-name filename)))
+ (find-file
+ ;; expand-file-name fixes "~/~/.emacs" bug sent by CHUCKR.
+ (expand-file-name filename)))
;; User does not want to find a non-existent file:
((signal 'file-missing (list "Opening file buffer"
"No such file or directory"