Bump version to 24.0.94
[bpt/emacs.git] / lisp / ffap.el
index 939b287..99017d2 100644 (file)
@@ -1,7 +1,6 @@
 ;;; ffap.el --- find file (or url) at point
 
-;; Copyright (C) 1995, 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2005,
-;;   2006, 2007, 2008, 2009  Free Software Foundation, Inc.
+;; Copyright (C) 1995-1997, 2000-2012  Free Software Foundation, Inc.
 
 ;; Author: Michelangelo Grigni <mic@mathcs.emory.edu>
 ;; Maintainer: FSF
 \f
 ;;; User Variables:
 
-(defun ffap-soft-value (name &optional default)
-  "Return value of symbol with NAME, if it is interned.
-Otherwise return nil (or the optional DEFAULT value)."
-  ;; Bug: (ffap-soft-value "nil" 5) --> 5
-  (let ((sym (intern-soft name)))
-    (if (and sym (boundp sym)) (symbol-value sym) default)))
+(defun ffap-symbol-value (sym &optional default)
+  "Return value of symbol SYM, if bound, or DEFAULT otherwise."
+  (if (boundp sym) (symbol-value sym) default))
 
 (defcustom ffap-shell-prompt-regexp
   ;; This used to test for some shell prompts that don't have a space
   ;; after them. The common root shell prompt (#) is not listed since it
   ;; also doubles up as a valid URL character.
   "[$%><]*"
-  "Paths matching this regexp are stripped off the shell prompt
+  "Paths matching this regexp are stripped off the shell prompt.
 If nil, ffap doesn't do shell prompt stripping."
   :type '(choice (const :tag "Disable" nil)
                  (const :tag "Standard" "[$%><]*")
@@ -187,7 +183,7 @@ Note this name may be omitted if it equals the default
    "\\(ftp\\|https?\\|telnet\\|gopher\\|www\\|wais\\)://" ; needs host
    "\\)."                              ; require one more character
    )
-   "Regexp matching URL's.  nil to disable URL features in ffap.")
+   "Regexp matching URLs.  Use nil to disable URL features in ffap.")
 
 (defcustom ffap-foo-at-bar-prefix "mailto"
   "Presumed URL prefix type of strings like \"<foo.9z@bar>\".
@@ -285,7 +281,7 @@ For a fancy alternative, get `ffap-url.el'."
 ;; See the ftp site for a more general version.  The following
 ;; functions are necessary "leftovers" from the more general version.
 
-(defun ffap-mouse-event nil            ; current mouse event, or nil
+(defun ffap-mouse-event ()             ; current mouse event, or nil
   (and (listp last-nonmenu-event) last-nonmenu-event))
 (defun ffap-event-buffer (event)
   (window-buffer (car (event-start event))))
@@ -397,8 +393,8 @@ See `mail-extr.el' for the known domains."
 (defun ffap-what-domain (domain)
   ;; Like what-domain in mail-extr.el, returns string or nil.
   (require 'mail-extr)
-  (let ((ob (or (ffap-soft-value "mail-extr-all-top-level-domains")
-               (ffap-soft-value "all-top-level-domains")))) ; XEmacs
+  (let ((ob (or (ffap-symbol-value 'mail-extr-all-top-level-domains)
+               (ffap-symbol-value 'all-top-level-domains)))) ; XEmacs
     (and ob (get (intern-soft (downcase domain) ob) 'domain-name))))
 
 (defun ffap-machine-p (host &optional service quiet strategy)
@@ -527,7 +523,7 @@ The optional NOMODIFY argument suppresses the extra search."
   ;; (ffap-file-remote-p "/ffap.el:80")
   (or (and ffap-ftp-regexp
           (string-match ffap-ftp-regexp filename)
-          ;; Convert "/host.com://dir" to "/host:/dir", to handle a dieing
+          ;; Convert "/host.com://dir" to "/host:/dir", to handle a dying
           ;; practice of advertising ftp files as "host.dom://filename".
           (if (string-match "//" filename)
               ;; (replace-match "/" nil nil filename)
@@ -538,7 +534,7 @@ The optional NOMODIFY argument suppresses the extra search."
           (string-match ffap-rfs-regexp filename)
           filename)))
 
-(defun ffap-machine-at-point nil
+(defun ffap-machine-at-point ()
   "Return machine name at point if it exists, or nil."
   (let ((mach (ffap-string-at-point 'machine)))
     (and (ffap-machine-p mach) mach)))
@@ -550,8 +546,8 @@ Looks at `ffap-ftp-default-user', returns \"\" for \"localhost\"."
       ""
     (let ((user ffap-ftp-default-user))
       ;; Avoid including the user if it is same as default:
-      (if (or (equal user (ffap-soft-value "ange-ftp-default-user"))
-             (equal user (ffap-soft-value "efs-default-user")))
+      (if (or (equal user (ffap-symbol-value 'ange-ftp-default-user))
+             (equal user (ffap-symbol-value 'efs-default-user)))
          (setq user nil))
       (concat "/" user (and user "@") host ":"))))
 
@@ -603,7 +599,7 @@ Looks at `ffap-ftp-default-user', returns \"\" for \"localhost\"."
      ret)))
 
 (defsubst ffap-url-p (string)
-  "If STRING looks like an url, return it (maybe improved), else nil."
+  "If STRING looks like an URL, return it (maybe improved), else nil."
   (let ((case-fold-search t))
     (and ffap-url-regexp (string-match ffap-url-regexp string)
         ;; I lied, no improvement:
@@ -684,7 +680,7 @@ Uses `path-separator' to separate the path into substrings."
     (nreverse ret)))
 
 (defun ffap-all-subdirs (dir &optional depth)
-  "Return list all subdirectories under DIR, starting with itself.
+  "Return list of all subdirectories under DIR, starting with itself.
 Directories beginning with \".\" are ignored, and directory symlinks
 are listed but never searched (to avoid loops).
 Optional DEPTH limits search depth."
@@ -724,27 +720,24 @@ kpathsea, a library used by some versions of TeX."
               (list dir))))
          path)))
 
-(defun ffap-locate-file (file &optional nosuffix path dir-ok)
+(defun ffap-locate-file (file nosuffix path)
   ;; The current version of locate-library could almost replace this,
   ;; except it does not let us override the suffix list.  The
   ;; compression-suffixes search moved to ffap-file-exists-string.
-  "A generic path-searching function, mimics `load' by default.
-Returns path to file that \(load FILE\) would load, or nil.
+  "A generic path-searching function.
+Returns the name of file in PATH, or nil.
 Optional NOSUFFIX, if nil or t, is like the fourth argument
-for load: whether to try the suffixes (\".elc\" \".el\" \"\").
+for `load': whether to try the suffixes (\".elc\" \".el\" \"\").
 If a nonempty list, it is a list of suffixes to try instead.
-Optional PATH is a list of directories instead of `load-path'.
-Optional DIR-OK means that returning a directory is allowed,
-DIR-OK is already implicit if FILE looks like a directory.
+PATH is a list of directories.
 
-This uses ffap-file-exists-string, which may try adding suffixes from
+This uses `ffap-file-exists-string', which may try adding suffixes from
 `ffap-compression-suffixes'."
-  (or path (setq path load-path))
-  (or dir-ok (setq dir-ok (equal "" (file-name-nondirectory file))))
   (if (file-name-absolute-p file)
       (setq path (list (file-name-directory file))
            file (file-name-nondirectory file)))
-  (let ((suffixes-to-try
+  (let ((dir-ok (equal "" (file-name-nondirectory file)))
+        (suffixes-to-try
         (cond
          ((consp nosuffix) nosuffix)
          (nosuffix '(""))
@@ -792,20 +785,20 @@ 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|
-    ;; This uses to have a blank, but ffap-string-at-point doesn't
+    ;; This used 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 $
+    ("\\`[Rr][Ff][Cc][-#]?\\([0-9]+\\)"        ; no $
      . ffap-rfc)                       ; "100% RFC2100 compliant"
     (dired-mode . ffap-dired)          ; maybe in a subdirectory
     )
   "Alist of \(KEY . FUNCTION\) pairs parsed by `ffap-file-at-point'.
-If string NAME at point (maybe \"\") is not a file or url, these pairs
+If string NAME at point (maybe \"\") is not a file or URL, these pairs
 specify actions to try creating such a string.  A pair matches if either
   KEY is a symbol, and it equals `major-mode', or
-  KEY is a string, it should matches NAME as a regexp.
+  KEY is a string, it should match NAME as a regexp.
 On a match, \(FUNCTION NAME\) is called and should return a file, an
-url, or nil. If nil, search the alist for further matches.")
+URL, or nil.  If nil, search the alist for further matches.")
 
 (put 'ffap-alist 'risky-local-variable t)
 
@@ -839,8 +832,8 @@ url, or nil. If nil, search the alist for further matches.")
 (defun ffap-info (name)
   (ffap-locate-file
    name '("" ".info")
-   (or (ffap-soft-value "Info-directory-list")
-       (ffap-soft-value "Info-default-directory-list")
+   (or (ffap-symbol-value 'Info-directory-list)
+       (ffap-symbol-value 'Info-default-directory-list)
        )))
 
 (defun ffap-info-2 (name) (ffap-info (substring name 5)))
@@ -849,17 +842,32 @@ url, or nil. If nil, search the alist for further matches.")
   ;; This ignores the node! "(emacs)Top" same as "(emacs)Intro"
   (and (equal (ffap-string-around) "()") (ffap-info name)))
 
-(defun ffap-el (name) (ffap-locate-file name t))
+(defun ffap-el (name) (ffap-locate-file name t load-path))
 
 (defun ffap-el-mode (name)
   ;; If name == "foo.el" we will skip it, since ffap-el already
   ;; searched for it once.  (This assumes the default ffap-alist.)
   (and (not (string-match "\\.el\\'" name))
-       (ffap-locate-file name '(".el"))))
+       (ffap-locate-file name '(".el") load-path)))
 
+;; FIXME this duplicates the logic of Man-header-file-path.
+;; There should be a single central variable or function for this.
+;; See also (bug#10702):
+;; cc-search-directories, semantic-c-dependency-system-include-path,
+;; semantic-gcc-setup
 (defvar ffap-c-path
-  ;; Need smarter defaults here!  Suggestions welcome.
-  '("/usr/include" "/usr/local/include"))
+  (let ((arch (with-temp-buffer
+                (when (eq 0 (ignore-errors
+                              (call-process "gcc" nil '(t nil) nil
+                                            "-print-multiarch")))
+                  (goto-char (point-min))
+                  (buffer-substring (point) (line-end-position)))))
+        (base '("/usr/include" "/usr/local/include")))
+    (if (zerop (length arch))
+        base
+      (append base (list (expand-file-name arch "/usr/include")))))
+  "List of directories to search for include files.")
+
 (defun ffap-c-mode (name)
   (ffap-locate-file name t ffap-c-path))
 
@@ -870,10 +878,10 @@ url, or nil. If nil, search the alist for further matches.")
 
 (defvar ffap-tex-path
   t                            ; delayed initialization
-  "Path where `ffap-tex-mode' looks for tex files.
+  "Path where `ffap-tex-mode' looks for TeX files.
 If t, `ffap-tex-init' will initialize this when needed.")
 
-(defun ffap-tex-init nil
+(defun ffap-tex-init ()
   ;; Compute ffap-tex-path if it is now t.
   (and (eq t ffap-tex-path)
        ;; this may be slow, so say something
@@ -886,8 +894,8 @@ If t, `ffap-tex-init' will initialize this when needed.")
                (append
                 (ffap-list-env "TEXINPUTS")
                 ;; (ffap-list-env "BIBINPUTS")
-                (ffap-soft-value
-                 "TeX-macro-global"    ; AUCTeX
+                (ffap-symbol-value
+                 'TeX-macro-global     ; AUCTeX
                  '("/usr/local/lib/tex/macros"
                    "/usr/local/lib/tex/inputs")))))))))
 
@@ -934,6 +942,7 @@ If t, `ffap-tex-init' will initialize this when needed.")
 
 ;; Maybe a "Lisp Code Directory" reference:
 (defun ffap-lcd (name)
+  ;; FIXME: Is this still in use?
   (and
    (or
     ;; lisp-dir-apropos output buffer:
@@ -944,13 +953,23 @@ If t, `ffap-tex-init' will initialize this when needed.")
    (concat
     ;; lispdir.el may not be loaded yet:
     (ffap-host-to-filename
-     (ffap-soft-value "elisp-archive-host"
-                     "archive.cis.ohio-state.edu"))
+     (ffap-symbol-value 'elisp-archive-host
+                        "archive.cis.ohio-state.edu"))
     (file-name-as-directory
-     (ffap-soft-value "elisp-archive-directory"
-                     "/pub/gnu/emacs/elisp-archive/"))
+     (ffap-symbol-value 'elisp-archive-directory
+                        "/pub/gnu/emacs/elisp-archive/"))
     (substring name 2))))
 
+(defcustom ffap-rfc-path
+  (concat (ffap-host-to-filename "ftp.rfc-editor.org") "/in-notes/rfc%s.txt")
+  "A `format' string making a filename for RFC documents.
+This can be an ange-ftp or tramp remote filename to download, or
+a local filename if you have full set of RFCs locally.  See also
+`ffap-rfc-directories'."
+  :type 'string
+  :version "23.1"
+  :group 'ffap)
+
 (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."
@@ -958,9 +977,6 @@ If a given RFC isn't in these then `ffap-rfc-path' is offered."
   :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)
   (let ((num (match-string 1 name)))
     (or (ffap-locate-file (format "rfc%s.txt" num) t ffap-rfc-directories)
@@ -1026,7 +1042,7 @@ Sets `ffap-string-at-point' and `ffap-string-at-point-region'."
     (set-text-properties 0 (length str) nil str)
     (setq ffap-string-at-point str)))
 
-(defun ffap-string-around nil
+(defun ffap-string-around ()
   ;; Sometimes useful to decide how to treat a string.
   "Return string of two chars around last `ffap-string-at-point'.
 Assumes the buffer has not changed."
@@ -1054,8 +1070,8 @@ Assumes the buffer has not changed."
 ;; External.
 (declare-function w3-view-this-url "ext:w3" (&optional no-show))
 
-(defun ffap-url-at-point nil
-  "Return url from around point if it exists, or nil."
+(defun ffap-url-at-point ()
+  "Return URL from around point if it exists, or nil."
   ;; Could use w3's url-get-url-at-point instead.  Both handle "URL:",
   ;; ignore non-relative links, trim punctuation.  The other will
   ;; actually look back if point is in whitespace, but I would rather
@@ -1095,11 +1111,11 @@ Assumes the buffer has not changed."
 
 (defvar ffap-gopher-regexp
   "^.*\\<\\(Type\\|Name\\|Path\\|Host\\|Port\\) *= *\\(.*\\) *$"
-  "Regexp Matching a line in a gopher bookmark (maybe indented).
+  "Regexp matching a line in a gopher bookmark (maybe indented).
 The two subexpressions are the KEY and VALUE.")
 
-(defun ffap-gopher-at-point nil
-  "If point is inside a gopher bookmark block, return its url."
+(defun ffap-gopher-at-point ()
+  "If point is inside a gopher bookmark block, return its URL."
   ;; `gopher-parse-bookmark' from gopher.el is not so robust
   (save-excursion
     (beginning-of-line)
@@ -1108,7 +1124,7 @@ The two subexpressions are the KEY and VALUE.")
          (while (and (looking-at ffap-gopher-regexp) (not (bobp)))
            (forward-line -1))
          (or (looking-at ffap-gopher-regexp) (forward-line 1))
-         (let ((type "1") name path host (port "70"))
+         (let ((type "1") path host (port "70"))
            (while (looking-at ffap-gopher-regexp)
              (let ((var (intern
                          (downcase
@@ -1138,11 +1154,11 @@ The two subexpressions are the KEY and VALUE.")
   "Strings matching this are coerced to ftp file names by ffap.
 That is, ffap just prepends \"/\".  Set to nil to disable.")
 
-(defun ffap-file-at-point nil
+(defun ffap-file-at-point ()
   "Return filename from around point if it exists, or nil.
 Existence test is skipped for names that look remote.
 If the filename is not obvious, it also tries `ffap-alist',
-which may actually result in an url rather than a filename."
+which may actually result in an URL rather than a filename."
   ;; Note: this function does not need to look for url's, just
   ;; filenames.  On the other hand, it is responsible for converting
   ;; a pseudo-url "site.com://dir" to an ftp file name
@@ -1258,7 +1274,7 @@ which may actually result in an url rather than a filename."
 ;; contents before attempting to complete filenames.
 
 (defun ffap-read-file-or-url (prompt guess)
-  "Read file or url from minibuffer, with PROMPT and initial 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"
@@ -1300,8 +1316,8 @@ which may actually result in an url rather than a filename."
     guess))
 
 (defun ffap-read-url-internal (string pred action)
-  "Complete url's from history, treating given string as valid."
-  (let ((hist (ffap-soft-value "url-global-history-hash-table")))
+  "Complete URLs from history, treating given string as valid."
+  (let ((hist (ffap-symbol-value 'url-global-history-hash-table)))
     (cond
      ((not action)
       (or (try-completion string hist pred) string))
@@ -1324,7 +1340,7 @@ which may actually result in an url rather than a filename."
 ;; We must inform complete about whether our completion function
 ;; will do filename style completion.
 
-(defun ffap-complete-as-file-p nil
+(defun ffap-complete-as-file-p ()
   ;; Will `minibuffer-completion-table' complete the minibuffer
   ;; contents as a filename?  Assumes the minibuffer is current.
   ;; Note: t and non-nil mean somewhat different reasons.
@@ -1380,7 +1396,7 @@ Uses the face `ffap' if it is defined, or else `highlight'."
 \f
 ;;; Main Entrance (`find-file-at-point' == `ffap'):
 
-(defun ffap-guesser nil
+(defun ffap-guesser ()
   "Return file or URL or nil, guessed from text around point."
   (or (and ffap-url-regexp
           (ffap-fixup-url (or (ffap-url-at-point)
@@ -1473,7 +1489,7 @@ These properties may be used to fontify the menu references.")
 
 ;;;###autoload
 (defun ffap-menu (&optional rescan)
-  "Put up a menu of files and urls mentioned in this buffer.
+  "Put up a menu of files and URLs mentioned in this buffer.
 Then set mark, jump to choice, and try to fetch it.  The menu is
 cached in `ffap-menu-alist', and rebuilt by `ffap-menu-rescan'.
 The optional RESCAN argument \(a prefix, interactively\) forces
@@ -1545,7 +1561,7 @@ Function CONT is applied to the entry chosen by the user."
       (message "No choice made!")      ; possible with menus
       nil)))
 
-(defun ffap-menu-rescan nil
+(defun ffap-menu-rescan ()
   "Search buffer for `ffap-menu-regexp' to build `ffap-menu-alist'.
 Applies `ffap-menu-text-plist' text properties at all matches."
   (interactive)
@@ -1599,7 +1615,7 @@ Ignored when `ffap-at-mouse' is called programmatically.")
 
 ;;;###autoload
 (defun ffap-at-mouse (e)
-  "Find file or url guessed from text around mouse click.
+  "Find file or URL guessed from text around mouse click.
 Interactively, calls `ffap-at-mouse-fallback' if no guess is found.
 Return value:
   * if a guess string is found, return it (after finding it)
@@ -1627,7 +1643,7 @@ Return value:
      ((called-interactively-p 'interactive)
       (if ffap-at-mouse-fallback
          (call-interactively ffap-at-mouse-fallback)
-       (message "No file or url found at mouse click.")
+       (message "No file or URL found at mouse click.")
        nil))                           ; no fallback, return nil
      ;; failure: return nil
      )))
@@ -1639,7 +1655,7 @@ Return value:
 ;; at least two new user variables, and there is no w3-fetch-noselect.
 ;; So instead, we just fake it with a slow save-window-excursion.
 
-(defun ffap-other-window nil
+(defun ffap-other-window ()
   "Like `ffap', but put buffer in another window.
 Only intended for interactive use."
   (interactive)
@@ -1652,7 +1668,7 @@ Only intended for interactive use."
        (current-buffer)))
     value))
 
-(defun ffap-other-frame nil
+(defun ffap-other-frame ()
   "Like `ffap', but put buffer in another frame.
 Only intended for interactive use."
   (interactive)
@@ -1708,6 +1724,22 @@ Only intended for interactive use."
   (let ((ffap-file-finder 'find-alternate-file))
     (call-interactively 'ffap)))
 
+(defun ffap-alternate-file-other-window ()
+  "Like `ffap' and `find-alternate-file-other-window'.
+Only intended for interactive use."
+  (interactive)
+  (let ((ffap-file-finder 'find-alternate-file-other-window))
+    (call-interactively 'ffap)))
+
+(defun ffap-literally ()
+  "Like `ffap' and `find-file-literally'.
+Only intended for interactive use."
+  (interactive)
+  (let ((ffap-file-finder 'find-file-literally))
+    (call-interactively 'ffap)))
+
+(defalias 'find-file-literally-at-point 'ffap-literally)
+
 \f
 ;;; Bug Reporter:
 
@@ -1720,13 +1752,13 @@ Only intended for interactive use."
 ;; If you do not like these bindings, write versions with whatever
 ;; bindings you would prefer.
 
-(defun ffap-ro-mode-hook nil
+(defun ffap-ro-mode-hook ()
   "Bind `ffap-next' and `ffap-menu' to M-l and M-m, resp."
   (local-set-key "\M-l" 'ffap-next)
   (local-set-key "\M-m" 'ffap-menu)
   )
 
-(defun ffap-gnus-hook nil
+(defun ffap-gnus-hook ()
   "Bind `ffap-gnus-next' and `ffap-gnus-menu' to M-l and M-m, resp."
   (set (make-local-variable 'ffap-foo-at-bar-prefix) "news") ; message-id's
   ;; Note "l", "L", "m", "M" are taken:
@@ -1759,11 +1791,11 @@ Only intended for interactive use."
        (eval form)
       (pop-to-buffer sb))))
 
-(defun ffap-gnus-next nil
+(defun ffap-gnus-next ()
   "Run `ffap-next' in the gnus article buffer."
   (interactive) (ffap-gnus-wrapper '(ffap-next nil t)))
 
-(defun ffap-gnus-menu nil
+(defun ffap-gnus-menu ()
   "Run `ffap-menu' in the gnus article buffer."
   (interactive) (ffap-gnus-wrapper '(ffap-menu)))
 
@@ -1778,7 +1810,8 @@ ffap most of the time."
 
 ;;;###autoload
 (defun dired-at-point (&optional filename)
-  "Start Dired, defaulting to file at point.  See `ffap'."
+  "Start Dired, defaulting to file at point.  See `ffap'.
+If `dired-at-point-require-prefix' is set, the prefix meaning is reversed."
   (interactive)
   (if (and (called-interactively-p 'interactive)
           (if dired-at-point-require-prefix
@@ -1877,6 +1910,29 @@ Only intended for interactive use."
     (call-interactively 'dired-at-point)))
 
 \f
+;;; Hooks to put in `file-name-at-point-functions':
+
+;;;###autoload
+(progn (defun ffap-guess-file-name-at-point ()
+  "Try to get a file name at point.
+This hook is intended to be put in `file-name-at-point-functions'."
+  (when (fboundp 'ffap-guesser)
+    ;; Logic from `ffap-read-file-or-url' and `dired-at-point-prompter'.
+    (let ((guess (ffap-guesser)))
+      (setq guess
+           (if (or (not guess)
+                   (and (fboundp 'ffap-url-p)
+                        (ffap-url-p guess))
+                   (and (fboundp 'ffap-file-remote-p)
+                        (ffap-file-remote-p guess)))
+               guess
+             (abbreviate-file-name (expand-file-name guess))))
+      (when guess
+       (if (file-directory-p guess)
+           (file-name-as-directory guess)
+         guess))))))
+
+\f
 ;;; Offer default global bindings (`ffap-bindings'):
 
 (defvar ffap-bindings
@@ -1910,7 +1966,7 @@ A reasonable ffap installation needs just this one line:
 Of course if you do not like these bindings, just roll your own!")
 
 ;;;###autoload
-(defun ffap-bindings nil
+(defun ffap-bindings ()
   "Evaluate the forms in variable `ffap-bindings'."
   (interactive)
   (eval (cons 'progn ffap-bindings)))
@@ -1918,5 +1974,4 @@ Of course if you do not like these bindings, just roll your own!")
 \f
 (provide 'ffap)
 
-;; arch-tag: 9dd3e88a-5dec-4607-bd57-60ae9ede8ebc
 ;;; ffap.el ends here