]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/ffap.el (ffap-read-file-or-url): Simplify further
authorStefan Monnier <monnier@iro.umontreal.ca>
Fri, 8 Nov 2019 18:32:46 +0000 (13:32 -0500)
committerStefan Monnier <monnier@iro.umontreal.ca>
Fri, 8 Nov 2019 18:32:46 +0000 (13:32 -0500)
lisp/ffap.el

index 542aec77f81c620d17a7e791a818894645cc8c60..6cf7656fb44594b4ce357692d12c9865ae9877cc 100644 (file)
@@ -1403,34 +1403,26 @@ which may actually result in an URL rather than a filename."
 (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))
-  (let (dir)
-    ;; Tricky: guess may have or be a local directory, like "w3/w3.elc"
-    ;; or "w3/" or "../el/ffap.el" or "../../../"
-    (unless (ffap-url-p guess)
-      (unless (ffap-file-remote-p guess)
-       (setq guess
-             (abbreviate-file-name (expand-file-name guess))))
-      (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)))
-      ;; 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)))
-                  (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
-        ;; during the completing-read call).
-        (setq file-name-handler-alist (delq fnh-elem file-name-handler-alist))))
-    (or (ffap-url-p guess)
-       (substitute-in-file-name guess))))
+  ;; Tricky: guess may have or be a local directory, like "w3/w3.elc"
+  ;; or "w3/" or "../el/ffap.el" or "../../../"
+  (unless (or (ffap-url-p guess)
+              (ffap-file-remote-p guess))
+    (setq guess
+         (abbreviate-file-name (expand-file-name guess))))
+  (let ((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
+              (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 fnh-elem file-name-handler-alist))))
+  (or (ffap-url-p guess)
+      (substitute-in-file-name guess)))
 
 ;; The rest of this page is just to work with package complete.el.
 ;; This code assumes that you load ffap.el after complete.el.