Add 2012 to FSF copyright years for Emacs files
[bpt/emacs.git] / lisp / ffap.el
index c34478a..c379753 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 Free Software Foundation, Inc.
+;; Copyright (C) 1995-1997, 2000-2012  Free Software Foundation, Inc.
 
 ;; Author: Michelangelo Grigni <mic@mathcs.emory.edu>
 ;; Maintainer: FSF
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -22,9 +21,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 \f
 ;;; Commentary:
 \f
 ;;; Code:
 
-(provide 'ffap)
-
-;; Please do not delete this variable, it is checked in bug reports.
-(defconst ffap-version "1.9-fsf <97/06/25 13:21:41 mic>"
-  "The version of ffap: \"Major.Minor-Build <Timestamp>\"")
-
+(define-obsolete-variable-alias 'ffap-version 'emacs-version "23.2")
 
 (defgroup ffap nil
   "Find file or URL at point."
-  :link '(url-link :tag "URL" "ftp://ftp.mathcs.emory.edu/pub/mic/emacs/")
+  ;; Dead 2009/07/05.
+;;  :link '(url-link :tag "URL" "ftp://ftp.mathcs.emory.edu/pub/mic/emacs/")
   :group 'matching
   :group 'convenience)
 
 \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" "[$%><]*")
@@ -150,7 +140,7 @@ If nil, ffap doesn't do shell prompt stripping."
   ;; This used to test for ange-ftp or efs being present, but it should be
   ;; harmless (and simpler) to give it this value unconditionally.
   "\\`/[^/:]+:"
-  "*File names matching this regexp are treated as remote ffap.
+  "File names matching this regexp are treated as remote ffap.
 If nil, ffap neither recognizes nor generates such names."
   :type '(choice (const :tag "Disable" nil)
                 (const :tag "Standard" "\\`/[^/:]+:")
@@ -158,18 +148,18 @@ If nil, ffap neither recognizes nor generates such names."
   :group 'ffap)
 
 (defcustom ffap-url-unwrap-local t
-  "*If non-nil, convert `file:' URL to local file name before prompting."
+  "If non-nil, convert `file:' URL to local file name before prompting."
   :type 'boolean
   :group 'ffap)
 
 (defcustom ffap-url-unwrap-remote t
-  "*If non-nil, convert `ftp:' URL to remote file name before prompting.
+  "If non-nil, convert `ftp:' URL to remote file name before prompting.
 This is ignored if `ffap-ftp-regexp' is nil."
   :type 'boolean
   :group 'ffap)
 
 (defcustom ffap-ftp-default-user "anonymous"
-  "*User name in ftp file names generated by `ffap-host-to-path'.
+  "User name in ftp file names generated by `ffap-host-to-path'.
 Note this name may be omitted if it equals the default
 \(either `efs-default-user' or `ange-ftp-default-user'\)."
   :type 'string
@@ -179,7 +169,7 @@ Note this name may be omitted if it equals the default
   ;; Remote file access built into file system?  HP rfa or Andrew afs:
   "\\`/\\(afs\\|net\\)/."
   ;; afs only: (and (file-exists-p "/afs") "\\`/afs/.")
-  "*Matching file names are treated as remote.  Use nil to disable."
+  "Matching file names are treated as remote.  Use nil to disable."
   :type 'regexp
   :group 'ffap)
 
@@ -193,10 +183,10 @@ 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>\".
+  "Presumed URL prefix type of strings like \"<foo.9z@bar>\".
 Sensible values are nil, \"news\", or \"mailto\"."
   :type '(choice (const "mailto")
                 (const "news")
@@ -215,7 +205,7 @@ Sensible values are nil, \"news\", or \"mailto\"."
 ;; enabler in your .emacs file.
 
 (defcustom ffap-dired-wildcards "[*?][^/]*\\'"
-  "*A regexp matching filename wildcard characters, or nil.
+  "A regexp matching filename wildcard characters, or nil.
 
 If `find-file-at-point' gets a filename matching this pattern,
 and `ffap-pass-wildcards-to-dired' is nil, it passes it on to
@@ -235,33 +225,33 @@ it passes it on to `dired'."
   :group 'ffap)
 
 (defcustom ffap-pass-wildcards-to-dired nil
-  "*If non-nil, pass filenames matching `ffap-dired-wildcards' to dired."
+  "If non-nil, pass filenames matching `ffap-dired-wildcards' to dired."
   :type 'boolean
   :group 'ffap)
 
 (defcustom ffap-newfile-prompt nil
   ;; Suggestion from RHOGEE, 11 Jul 1994.  Disabled, I think this is
   ;; better handled by `find-file-not-found-hooks'.
-  "*Whether `find-file-at-point' prompts about a nonexistent file."
+  "Whether `find-file-at-point' prompts about a nonexistent file."
   :type 'boolean
   :group 'ffap)
 
 (defcustom ffap-require-prefix nil
   ;; Suggestion from RHOGEE, 20 Oct 1994.
-  "*If set, reverses the prefix argument to `find-file-at-point'.
+  "If set, reverses the prefix argument to `find-file-at-point'.
 This is nil so neophytes notice ffap.  Experts may prefer to disable
 ffap most of the time."
   :type 'boolean
   :group 'ffap)
 
 (defcustom ffap-file-finder 'find-file
-  "*The command called by `find-file-at-point' to find a file."
+  "The command called by `find-file-at-point' to find a file."
   :type 'function
   :group 'ffap)
 (put 'ffap-file-finder 'risky-local-variable t)
 
 (defcustom ffap-directory-finder 'dired
-  "*The command called by `dired-at-point' to find a directory."
+  "The command called by `dired-at-point' to find a directory."
   :type 'function
   :group 'ffap)
 (put 'ffap-directory-finder 'risky-local-variable t)
@@ -273,7 +263,7 @@ ffap most of the time."
   ;; Remote control references:
   ;; http://www.ncsa.uiuc.edu/SDG/Software/XMosaic/remote-control.html
   ;; http://home.netscape.com/newsref/std/x-remote.html
-  "*A function of one argument, called by ffap to fetch an URL.
+  "A function of one argument, called by ffap to fetch an URL.
 Reasonable choices are `w3-fetch' or a `browse-url-*' function.
 For a fancy alternative, get `ffap-url.el'."
   :type '(choice (const w3-fetch)
@@ -291,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))))
@@ -311,7 +301,7 @@ For a fancy alternative, get `ffap-url.el'."
   ;; It pays to put a big fancy regexp here, since ffap-guesser is
   ;; much more time-consuming than regexp searching:
   "[/:.~[:alpha:]]/\\|@[[:alpha:]][-[:alnum:]]*\\."
-  "*Regular expression governing movements of `ffap-next'."
+  "Regular expression governing movements of `ffap-next'."
   :type 'regexp
   :group 'ffap)
 
@@ -366,7 +356,7 @@ Actual search is done by `ffap-next-guess'."
   "Like `ffap-next', but search with `ffap-url-regexp'."
   (interactive)
   (let ((ffap-next-regexp ffap-url-regexp))
-    (if (interactive-p)
+    (if (called-interactively-p 'interactive)
        (call-interactively 'ffap-next)
       (ffap-next back wrap))))
 
@@ -377,14 +367,14 @@ Actual search is done by `ffap-next-guess'."
 ;; particular, if `Pinging...' is broken or takes too long on your
 ;; machine, try setting these all to accept or reject.
 (defcustom ffap-machine-p-local 'reject        ; this happens often
-  "*What `ffap-machine-p' does with hostnames that have no domain.
+  "What `ffap-machine-p' does with hostnames that have no domain.
 Value should be a symbol, one of `ping', `accept', and `reject'."
   :type '(choice (const ping)
                 (const accept)
                 (const reject))
   :group 'ffap)
 (defcustom ffap-machine-p-known 'ping  ; `accept' for higher speed
-  "*What `ffap-machine-p' does with hostnames that have a known domain.
+  "What `ffap-machine-p' does with hostnames that have a known domain.
 Value should be a symbol, one of `ping', `accept', and `reject'.
 See `mail-extr.el' for the known domains."
   :type '(choice (const ping)
@@ -392,7 +382,7 @@ See `mail-extr.el' for the known domains."
                 (const reject))
   :group 'ffap)
 (defcustom ffap-machine-p-unknown 'reject
-  "*What `ffap-machine-p' does with hostnames that have an unknown domain.
+  "What `ffap-machine-p' does with hostnames that have an unknown domain.
 Value should be a symbol, one of `ping', `accept', and `reject'.
 See `mail-extr.el' for the known domains."
   :type '(choice (const ping)
@@ -403,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)
@@ -426,7 +416,7 @@ Returned values:
   ;; (ffap-machine-p "mathcs" 5678 nil 'ping)
   ;; (ffap-machine-p "foo.bonk" nil nil 'ping)
   ;; (ffap-machine-p "foo.bonk.com" nil nil 'ping)
-  (if (or (string-match "[^-[:alnum:].]" host) ; Illegal chars (?)
+  (if (or (string-match "[^-[:alnum:].]" host) ; Invalid chars (?)
          (not (string-match "[^0-9]" host))) ; 1: a number? 2: quick reject
       nil
     (let* ((domain
@@ -533,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)
@@ -544,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)))
@@ -556,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 ":"))))
 
@@ -609,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:
@@ -635,8 +625,9 @@ Looks at `ffap-ftp-default-user', returns \"\" for \"localhost\"."
    ((and ffap-url-unwrap-local (ffap-url-unwrap-local url)))
    ((and ffap-url-unwrap-remote ffap-ftp-regexp
         (ffap-url-unwrap-remote url)))
-   ((fboundp 'url-normalize-url)       ; may autoload url (part of w3)
-    (url-normalize-url url))
+   ;; All this seems to do is remove any trailing "#anchor" part (Bug#898).
+;;;   ((fboundp 'url-normalize-url)    ; may autoload url (part of w3)
+;;;    (url-normalize-url url))
    (url)))
 
 \f
@@ -689,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."
@@ -729,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 '(""))
@@ -797,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)
 
@@ -844,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)))
@@ -854,13 +842,13 @@ 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)))
 
 (defvar ffap-c-path
   ;; Need smarter defaults here!  Suggestions welcome.
@@ -875,10 +863,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
@@ -891,8 +879,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")))))))))
 
@@ -922,7 +910,7 @@ If t, `ffap-tex-init' will initialize this when needed.")
   (ffap-locate-file name t ffap-bib-path))
 
 (defun ffap-dired (name)
-  (let ((pt (point)) dir try)
+  (let ((pt (point)) try)
     (save-excursion
       (and (progn
             (beginning-of-line)
@@ -939,6 +927,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:
@@ -949,19 +938,34 @@ 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))))
 
-(defvar ffap-rfc-path
-  (concat (ffap-host-to-filename "ftp.rfc-editor.org") "/in-notes/rfc%s.txt"))
+(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."
+  :type '(repeat directory)
+  :version "23.1"
+  :group 'ffap)
 
 (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:
@@ -972,11 +976,11 @@ 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_[:alpha:]~*?" "<@" "@>;.,!:")
     ;; An url, or maybe a email/news message-id:
-    (url "--:=&?$+@-Z_[:lower:]~#,%;*" "^[:alnum:]" ":;.,!?")
+    (url "--:=&?$+@-Z_[:alpha:]~#,%;*" "^[:alnum:]" ":;.,!?")
     ;; Find a string that does *not* contain a colon:
-    (nocolon "--9$+<>@-Z_[:lower:]~" "<@" "@>;.,!?")
+    (nocolon "--9$+<>@-Z_[:alpha:]~" "<@" "@>;.,!?")
     ;; A machine:
     (machine "-[:alnum:]." "" ".")
     ;; Mathematica paths: allow backquotes
@@ -1023,7 +1027,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."
@@ -1051,8 +1055,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
@@ -1092,11 +1096,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)
@@ -1105,7 +1109,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
@@ -1135,11 +1139,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
@@ -1174,6 +1178,9 @@ which may actually result in an url rather than a filename."
         ((and abs (ffap-file-remote-p name)))
         ;; Ok, not remote, try the existence test even if it is absolute:
         ((and abs (ffap-file-exists-string name)))
+        ;; Try stripping off line numbers.
+        ((and abs (string-match ":[0-9]" name)
+              (ffap-file-exists-string (substring name 0 (match-beginning 0)))))
         ;; If it contains a colon, get rid of it (and return if exists)
         ((and (string-match path-separator name)
               (setq name (ffap-string-at-point 'nocolon))
@@ -1252,7 +1259,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"
@@ -1271,15 +1278,17 @@ which may actually result in an url rather than a filename."
       (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))))
+                (let ((default-directory (if dir (expand-file-name dir)
+                                           default-directory)))
+                  (completing-read
+                   prompt
+                   'ffap-read-file-or-url-internal
+                   nil
+                   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
@@ -1291,26 +1300,24 @@ which may actually result in an url rather than a filename."
     ;; Note: upcoming url.el package ought to handle this automatically.
     guess))
 
-(defun ffap-read-url-internal (string dir action)
-  "Complete url's from history, treating given string as valid."
-  (let ((hist (ffap-soft-value "url-global-history-hash-table")))
+(defun ffap-read-url-internal (string pred action)
+  "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) string))
+      (or (try-completion string hist pred) string))
      ((eq action t)
-      (or (all-completions string hist) (list string)))
+      (or (all-completions string hist pred) (list string)))
      ;; action == lambda, documented where?  Tests whether string is a
      ;; valid "match".  Let us always say yes.
      (t t))))
 
-(defun ffap-read-file-or-url-internal (string dir action)
-  (unless dir
-    (setq dir default-directory))
-  (unless string
+(defun ffap-read-file-or-url-internal (string pred action)
+  (unless string                        ;Why would this ever happen?
     (setq string default-directory))
   (if (ffap-url-p string)
-      (ffap-read-url-internal string dir action)
-    (read-file-name-internal string dir action)))
+      (ffap-read-url-internal string pred action)
+    (read-file-name-internal string pred action)))
 
 ;; The rest of this page is just to work with package complete.el.
 ;; This code assumes that you load ffap.el after complete.el.
@@ -1318,7 +1325,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.
@@ -1374,7 +1381,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)
@@ -1392,7 +1399,11 @@ Uses the face `ffap' if it is defined, or else `highlight'."
        (ffap-read-file-or-url
         (if ffap-url-regexp "Find file or URL: " "Find file: ")
         (prog1
-            (setq guess (or guess (ffap-guesser))) ; using ffap-alist here
+             (let ((mark-active nil))
+               ;; Don't use the region here, since it can be something
+               ;; completely unwieldy.  If the user wants that, she could
+               ;; use M-w before and then C-y.  --Stef
+               (setq guess (or guess (ffap-guesser)))) ; using ffap-alist here
           (and guess (ffap-highlight))
           )))
     (ffap-highlight t)))
@@ -1406,7 +1417,7 @@ If `ffap-require-prefix' is set, the prefix meaning is reversed.
 See also the variables `ffap-dired-wildcards', `ffap-newfile-prompt',
 and the functions `ffap-file-at-point' and `ffap-url-at-point'."
   (interactive)
-  (if (and (interactive-p)
+  (if (and (called-interactively-p 'interactive)
           (if ffap-require-prefix (not current-prefix-arg)
             current-prefix-arg))
       ;; Do exactly the ffap-file-finder command, even the prompting:
@@ -1463,7 +1474,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
@@ -1515,7 +1526,7 @@ Function CONT is applied to the entry chosen by the user."
            (x-popup-menu
             t
             (list "" (cons title
-                           (mapcar (function (lambda (i) (cons (car i) i)))
+                           (mapcar (lambda (i) (cons (car i) i))
                                    alist))))))
      ;; minibuffer with completion buffer:
      (t
@@ -1529,14 +1540,13 @@ Function CONT is applied to the entry chosen by the user."
               nil)))
       (sit-for 0)                      ; redraw original screen
       ;; Convert string to its entry, or else the default:
-      (setq choice (or (assoc choice alist) (car alist))))
-     )
+      (setq choice (or (assoc choice alist) (car alist)))))
     (if choice
        (funcall cont choice)
       (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)
@@ -1561,7 +1571,7 @@ Applies `ffap-menu-text-plist' text properties at all matches."
                                 ffap-menu-text-plist)
            (message "Scanning...%2d%% <%s>"
                     (/ (* 100 (- (point) (point-min))) range) item)))
-      (or mod (set-buffer-modified-p nil))))
+      (or mod (restore-buffer-modified-p nil))))
   (message "Scanning...done")
   ;; Remove duplicates.
   (setq ffap-menu-alist                        ; sort by item
@@ -1590,7 +1600,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)
@@ -1615,10 +1625,10 @@ Return value:
            (find-file-at-point guess)
            guess)                      ; success: return non-nil
        (ffap-highlight t)))
-     ((interactive-p)
+     ((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
      )))
@@ -1630,7 +1640,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)
@@ -1643,7 +1653,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)
@@ -1699,6 +1709,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:
 
@@ -1711,13 +1737,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:
@@ -1750,17 +1776,17 @@ 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)))
 
 \f
 (defcustom dired-at-point-require-prefix nil
-  "*If set, reverses the prefix argument to `dired-at-point'.
+  "If set, reverses the prefix argument to `dired-at-point'.
 This is nil so neophytes notice ffap.  Experts may prefer to disable
 ffap most of the time."
   :type 'boolean
@@ -1769,9 +1795,10 @@ 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 (interactive-p)
+  (if (and (called-interactively-p 'interactive)
           (if dired-at-point-require-prefix
               (not current-prefix-arg)
             current-prefix-arg))
@@ -1868,6 +1895,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
@@ -1901,12 +1951,12 @@ 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)))
 
 \f
+(provide 'ffap)
 
-;;; arch-tag: 9dd3e88a-5dec-4607-bd57-60ae9ede8ebc
 ;;; ffap.el ends here