]> code.delx.au - gnu-emacs/blobdiff - lisp/ffap.el
New file.
[gnu-emacs] / lisp / ffap.el
index d045e5aa7f90401c5185363658631f7f68cf7c3c..2c750d8f6125818d8d5118549e75cbdf91c32c35 100644 (file)
@@ -1,7 +1,7 @@
 ;;; ffap.el --- find file (or url) at point
 
 ;; Copyright (C) 1995, 1996, 1997, 2000, 2001, 2002, 2003, 2004,
-;;   2005, 2006, 2007 Free Software Foundation, Inc.
+;;   2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 
 ;; Author: Michelangelo Grigni <mic@mathcs.emory.edu>
 ;; Maintainer: FSF
@@ -797,7 +797,10 @@ This uses ffap-file-exists-string, which may try adding suffixes from
     ("\\.bib\\'" . ffap-bib)           ; search ffap-bib-path
     ("\\`\\." . ffap-home)             ; .emacs, .bashrc, .profile
     ("\\`~/" . ffap-lcd)               ; |~/misc/ffap.el.Z|
-    ("^[Rr][Ff][Cc][- #]?\\([0-9]+\\)" ; no $
+    ;; This uses to have a blank, but ffap-string-at-point doesn't
+    ;; handle blanks.
+    ;; http://lists.gnu.org/archive/html/emacs-devel/2008-01/msg01058.html
+    ("^[Rr][Ff][Cc][-#]?\\([0-9]+\\)"  ; no $
      . ffap-rfc)                       ; "100% RFC2100 compliant"
     (dired-mode . ffap-dired)          ; maybe in a subdirectory
     )
@@ -953,12 +956,20 @@ If t, `ffap-tex-init' will initialize this when needed.")
                      "/pub/gnu/emacs/elisp-archive/"))
     (substring name 2))))
 
+(defcustom ffap-rfc-directories nil
+  "A list of directories to look for RFC files.
+If a given RFC isn't in these then `ffap-rfc-path' is offered."
+  :type '(repeat directory)
+  :version "23.1"
+  :group 'ffap)
+
 (defvar ffap-rfc-path
   (concat (ffap-host-to-filename "ftp.rfc-editor.org") "/in-notes/rfc%s.txt"))
 
 (defun ffap-rfc (name)
-  (format ffap-rfc-path
-         (substring name (match-beginning 1) (match-end 1))))
+  (let ((num (match-string 1 name)))
+    (or (ffap-locate-file (format "rfc%s.txt" num) t ffap-rfc-directories)
+        (format ffap-rfc-path num))))
 
 \f
 ;;; At-Point Functions:
@@ -969,7 +980,7 @@ If t, `ffap-tex-init' will initialize this when needed.")
     ;; Slightly controversial decisions:
     ;; * strip trailing "@" and ":"
     ;; * no commas (good for latex)
-    (file "--:$+<>@-Z_[:lower:]~*?" "<@" "@>;.,!:")
+    (file "--:\\\\$+<>@-Z_[:lower:]~*?" "<@" "@>;.,!:")
     ;; An url, or maybe a email/news message-id:
     (url "--:=&?$+@-Z_[:lower:]~#,%;*" "^[:alnum:]" ":;.,!?")
     ;; Find a string that does *not* contain a colon:
@@ -1262,17 +1273,26 @@ which may actually result in an url rather than a filename."
                    ))
          (setq dir (file-name-directory guess))))
     (let ((minibuffer-completing-file-name t)
-         (completion-ignore-case read-file-name-completion-ignore-case))
-      (setq guess
-           (completing-read
-            prompt
-            'ffap-read-file-or-url-internal
-            dir
-            nil
-            (if dir (cons guess (length dir)) guess)
-            (list 'file-name-history)
-            (and buffer-file-name
-                 (abbreviate-file-name buffer-file-name)))))
+         (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
+                (completing-read
+                 prompt
+                 'ffap-read-file-or-url-internal
+                 dir
+                 nil
+                 (if dir (cons guess (length dir)) guess)
+                 (list 'file-name-history)
+                 (and buffer-file-name
+                      (abbreviate-file-name buffer-file-name))))
+        ;; 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))))
     ;; Do file substitution like (interactive "F"), suggested by MCOOK.
     (or (ffap-url-p guess) (setq guess (substitute-in-file-name guess)))
     ;; Should not do it on url's, where $ is a common (VMS?) character.