]> code.delx.au - gnu-emacs/blobdiff - lisp/ffap.el
(isearch-complete1): Don't allocate unnecessarily.
[gnu-emacs] / lisp / ffap.el
index e97c217e4dacd7e85738c37bc63820fecd5407c2..5bea298f4df77aed30f490867f3f4a79ca6fedb4 100644 (file)
@@ -1,12 +1,11 @@
-;;; ffap.el --- find file (or url) at point
+;; ffap.el --- find file (or url) at point
 ;;
-;; Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+;; Copyright (C) 1995, 96, 97, 2000  Free Software Foundation, Inc.
 ;;
 ;; Author: Michelangelo Grigni <mic@mathcs.emory.edu>
 ;; Created: 29 Mar 1993
-;; Keywords: files, hypermedia, matching, mouse
+;; Keywords: files, hypermedia, matching, mouse, convenience
 ;; X-URL: ftp://ftp.mathcs.emory.edu/pub/mic/emacs/
-;; X-Source: this file is generated from ffap.epp
 
 ;; This file is part of GNU Emacs.
 
 ;; README's, MANIFEST's, and so on.  Submit bugs or suggestions with
 ;; M-x ffap-bug.
 ;;
-;; For the default installation, byte-compile ffap.el somewhere in
-;; your `load-path' and add these two lines to your .emacs file:
+;; For the default installation, add this line to your .emacs file:
 ;;
-;; (require 'ffap)                      ; load the package
 ;; (ffap-bindings)                      ; do default key bindings
 ;;
 ;; ffap-bindings makes the following global key bindings:
 ;;
 ;; C-x C-f       find-file-at-point (abbreviated as ffap)
+;; C-x d         dired-at-point
 ;; C-x 4 f       ffap-other-window
 ;; C-x 5 f       ffap-other-frame
 ;; S-mouse-3     ffap-at-mouse
@@ -71,7 +69,7 @@
 ;; ffap uses `browse-url' (if found, else `w3-fetch') to fetch URL's.
 ;; For a hairier `ffap-url-fetcher', try ffap-url.el (same ftp site).
 ;; Also, you can add `ffap-menu-rescan' to various hooks to fontify
-;; the file and URL references within a buffer.  
+;; the file and URL references within a buffer.
 
 \f
 ;;; Change Log:
 \f
 ;;; Todo list:
 ;; * use kpsewhich
-;; * let "/path/file#key" jump to key (tag or regexp) in /path/file
+;; * let "/dir/file#key" jump to key (tag or regexp) in /dir/file
 ;; * find file of symbol if TAGS is loaded (like above)
 ;; * break long menus into multiple panes (like imenu?)
 ;; * notice node in "(dired)Virtual Dired" (quotes, parentheses, whitespace)
-;; * notice "machine.dom blah blah blah path/file" (how?)
+;; * notice "machine.dom blah blah blah dir/file" (how?)
 ;; * as w3 becomes standard, rewrite to rely more on its functions
 ;; * regexp options for ffap-string-at-point, like font-lock (MCOOK)
 ;; * v19: could replace `ffap-locate-file' with a quieter `locate-library'
 (defgroup ffap nil
   "Find file or URL at point."
   :link '(url-link :tag "URL" "ftp://ftp.mathcs.emory.edu/pub/mic/emacs/")
-  :group 'matching)
+  :group 'matching
+  :group 'convenience)
 
 ;; The code is organized in pages, separated by formfeed characters.
 ;; See the next two pages for standard customization ideas.
@@ -125,26 +124,26 @@ Otherwise return nil (or the optional DEFAULT value)."
   ;; This used to test for ange-ftp or efs being present, but it should be
   ;; harmless (and simpler) to give it this value unconditionally.
   "\\`/[^/:]+:"
-  "*Paths matching this regexp are treated as remote ftp paths by ffap.
-If nil, ffap neither recognizes nor generates such paths."
+  "*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" "\\`/[^/:]+:")
                 regexp)
   :group 'ffap)
 
 (defcustom ffap-url-unwrap-local t
-  "*If non-nil, convert \"file:\" url to local path 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 path 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 paths 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
@@ -154,7 +153,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 paths are treated as remote.  nil to disable."
+  "*Matching file names are treated as remote.  Use nil to disable."
   :type 'regexp
   :group 'ffap)
 
@@ -165,7 +164,7 @@ Note this name may be omitted if it equals the default
    "\\`\\("
    "news\\(post\\)?:\\|mailto:\\|file:" ; no host ok
    "\\|"
-   "\\(ftp\\|http\\|telnet\\|gopher\\|www\\|wais\\)://" ; needs host
+   "\\(ftp\\|https?\\|telnet\\|gopher\\|www\\|wais\\)://" ; needs host
    "\\)."                              ; require one more character
    )
    "Regexp matching URL's.  nil to disable URL features in ffap.")
@@ -232,7 +231,7 @@ ffap most of the time."
   ;; http://home.netscape.com/newsref/std/x-remote.html
   "*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."
+For a fancy alternative, get `ffap-url.el'."
   :type '(choice (const w3-fetch)
                 (const browse-url)     ; in recent versions of browse-url
                 (const browse-url-netscape)
@@ -334,24 +333,24 @@ 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
-  "*A symbol, one of: `ping', `accept', `reject'.
-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 speed
-  "*A symbol, one of: ping, accept, reject.
-What `ffap-machine-p' does with hostnames that have a known domain
-\(see mail-extr.el for the known domains\)."
+(defcustom ffap-machine-p-known 'ping  ; `accept' for higher speed
+  "*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)
                 (const accept)
                 (const reject))
   :group 'ffap)
 (defcustom ffap-machine-p-unknown 'reject
-  "*A symbol, one of: ping, accept, reject.
-What `ffap-machine-p' does with hostnames that have an unknown domain
-\(see mail-extr.el for the known domains\)."
+  "*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)
                 (const accept)
                 (const reject))
@@ -398,6 +397,7 @@ Returned values:
       (cond
        ((eq strategy 'accept) 'accept)
        ((eq strategy 'reject) nil)
+       ((not (fboundp 'open-network-stream)) nil)
        ;; assume (eq strategy 'ping)
        (t
        (or quiet
@@ -434,7 +434,7 @@ Returned values:
 \f
 ;;; Possibly Remote Resources:
 
-(defun ffap-replace-path-component (fullname name)
+(defun ffap-replace-file-component (fullname name)
   "In remote FULLNAME, replace path with NAME.  May return nil."
   ;; Use ange-ftp or efs if loaded, but do not load them otherwise.
   (let (found)
@@ -446,12 +446,12 @@ Returned values:
        ange-ftp-replace-name-component
        ))
     (and found
-        (fset 'ffap-replace-path-component found)
+        (fset 'ffap-replace-file-component found)
         (funcall found fullname name))))
-;; (ffap-replace-path-component "/who@foo.com:/whatever" "/new")
+;; (ffap-replace-file-component "/who@foo.com:/whatever" "/new")
 
 (defun ffap-file-suffix (file)
-  "Return trailing \".foo\" suffix of FILE, or nil if none."
+  "Return trailing `.foo' suffix of FILE, or nil if none."
   (let ((pos (string-match "\\.[^./]*\\'" file)))
     (and pos (substring file pos nil))))
 
@@ -463,7 +463,7 @@ Returned values:
   ;; filename, maybe modified by adding a suffix like ".gz".  That
   ;; broke the interface of file-exists-p, so it was later dropped.
   ;; Here we document and simulate the old behavior.
-  "Return FILE \(maybe modified\) if it exists, else nil.
+  "Return FILE (maybe modified) if the file exists, else nil.
 When using jka-compr (a.k.a. `auto-compression-mode'), the returned
 name may have a suffix added from `ffap-compression-suffixes'.
 The optional NOMODIFY argument suppresses the extra search."
@@ -483,14 +483,14 @@ The optional NOMODIFY argument suppresses the extra search."
       ret))))
 
 (defun ffap-file-remote-p (filename)
-  "If FILENAME looks remote, return it \(maybe slightly improved\)."
+  "If FILENAME looks remote, return it (maybe slightly improved)."
   ;; (ffap-file-remote-p "/user@foo.bar.com:/pub")
-  ;; (ffap-file-remote-p "/cssun.mathcs.emory.edu://path")
+  ;; (ffap-file-remote-p "/cssun.mathcs.emory.edu://dir")
   ;; (ffap-file-remote-p "/ffap.el:80")
   (or (and ffap-ftp-regexp
           (string-match ffap-ftp-regexp filename)
-          ;; Convert "/host.com://path" to "/host:/path", to handle a dieing
-          ;; practice of advertising ftp paths as "host.dom://path".
+          ;; Convert "/host.com://dir" to "/host:/dir", to handle a dieing
+          ;; practice of advertising ftp files as "host.dom://filename".
           (if (string-match "//" filename)
               ;; (replace-match "/" nil nil filename)
               (concat (substring filename 0 (1+ (match-beginning 0)))
@@ -505,7 +505,7 @@ The optional NOMODIFY argument suppresses the extra search."
   (let ((mach (ffap-string-at-point 'machine)))
     (and (ffap-machine-p mach) mach)))
 
-(defsubst ffap-host-to-path (host)
+(defsubst ffap-host-to-filename (host)
   "Convert HOST to something like \"/USER@HOST:\" or \"/HOST:\".
 Looks at `ffap-ftp-default-user', returns \"\" for \"localhost\"."
   (if (equal host "localhost")
@@ -518,7 +518,7 @@ Looks at `ffap-ftp-default-user', returns \"\" for \"localhost\"."
       (concat "/" user (and user "@") host ":"))))
 
 (defun ffap-fixup-machine (mach)
-  ;; Convert a hostname into an url, an ftp path, or nil.
+  ;; Convert a hostname into an url, an ftp file name, or nil.
   (cond
    ((not (and ffap-url-regexp (stringp mach))) nil)
    ;; gopher.well.com
@@ -528,7 +528,7 @@ Looks at `ffap-ftp-default-user', returns \"\" for \"localhost\"."
    ((and (string-match "\\`w\\(ww\\|eb\\)[-.]" mach))
     (concat "http://" mach "/"))
    ;; More cases?  Maybe "telnet:" for archie?
-   (ffap-ftp-regexp (ffap-host-to-path mach))
+   (ffap-ftp-regexp (ffap-host-to-filename mach))
    ))
 
 (defvar ffap-newsgroup-regexp "^[a-z]+\\.[-+a-z_0-9.]+$"
@@ -550,7 +550,8 @@ Looks at `ffap-ftp-default-user', returns \"\" for \"localhost\"."
           (progn
             ;; errs: htb symbol may be unbound, or not a hash-table.
             ;; gnus-gethash is just a macro for intern-soft.
-            (and (intern-soft string (symbol-value htb))
+            (and (symbol-value htb)
+                 (intern-soft string (symbol-value htb))
                  (setq ret string htbs nil))
             ;; If we made it this far, gnus is running, so ignore "heads":
             (setq heads nil))
@@ -579,7 +580,7 @@ Looks at `ffap-ftp-default-user', returns \"\" for \"localhost\"."
   "Return URL as a remote file, or nil.  Ignores `ffap-url-regexp'."
   (and (string-match "\\`\\(ftp\\|file\\)://\\([^:/]+\\):?\\(/.*\\)" url)
        (concat
-       (ffap-host-to-path (substring url (match-beginning 2) (match-end 2)))
+       (ffap-host-to-filename (substring url (match-beginning 2) (match-end 2)))
        (substring url (match-beginning 3) (match-end 3)))))
 ;; Test: (ffap-url-unwrap-remote "ftp://foo.com/bar.boz")
 
@@ -595,10 +596,10 @@ Looks at `ffap-ftp-default-user', returns \"\" for \"localhost\"."
    (url)))
 
 \f
-;;; Path Handling:
+;;; File Name Handling:
 ;;
 ;; The upcoming ffap-alist actions need various utilities to prepare
-;; and search paths of directories.  Too many features here.
+;; and search directories.  Too many features here.
 
 ;; (defun ffap-last (l) (while (cdr l) (setq l (cdr l))) l)
 ;; (defun ffap-splice (func inlist)
@@ -900,7 +901,7 @@ If t, `ffap-tex-init' will initialize this when needed.")
     (member (ffap-string-around) '("||" "|\n")))
    (concat
     ;; lispdir.el may not be loaded yet:
-    (ffap-host-to-path
+    (ffap-host-to-filename
      (ffap-soft-value "elisp-archive-host"
                      "archive.cis.ohio-state.edu"))
     (file-name-as-directory
@@ -909,7 +910,7 @@ If t, `ffap-tex-init' will initialize this when needed.")
     (substring name 2))))
 
 (defvar ffap-rfc-path
-  (concat (ffap-host-to-path "ds.internic.net") "/rfc/rfc%s.txt"))
+  (concat (ffap-host-to-filename "ds.internic.net") "/rfc/rfc%s.txt"))
 
 (defun ffap-rfc (name)
   (format ffap-rfc-path
@@ -935,8 +936,8 @@ If t, `ffap-tex-init' will initialize this when needed.")
     (math-mode ",-:$+<>@-Z_a-z~`" "<" "@>;.,!?`:")
     )
   "Alist of \(MODE CHARS BEG END\), where MODE is a symbol,
-possibly a `major-mode' or some symbol internal to ffap
-\(such as 'file, 'url, 'machine, and 'nocolon\).
+possibly a major-mode name, or one of the symbol
+`file', `url', `machine', and `nocolon'.
 `ffap-string-at-point' uses the data fields as follows:
 1. find a maximal string of CHARS around point,
 2. strip BEG chars before point from the beginning,
@@ -948,9 +949,9 @@ possibly a `major-mode' or some symbol internal to ffap
 
 (defun ffap-string-at-point (&optional mode)
   "Return a string of characters from around point.
-MODE (defaults to `major-mode') is a symbol used to lookup string
+MODE (defaults to value of `major-mode') is a symbol used to look up string
 syntax parameters in `ffap-string-at-point-mode-alist'.
-If MODE is not found, we fall back on the symbol 'file.
+If MODE is not found, we use `file' instead of MODE.
 Sets `ffap-string-at-point' and `ffap-string-at-point-region'."
   (let* ((args
          (cdr
@@ -1076,7 +1077,7 @@ The two subexpressions are the KEY and VALUE.")
    ;; Icky regexp avoids: default: 123: foo::bar cs:pub
    ;; It does match on: mic@cs: cs:/pub mathcs.emory.edu: (point at end)
    "\\`\\([^:@]+@[^:@]+:\\|[^@.:]+\\.[^@:]+:\\|[^:]+:[~/]\\)\\([^:]\\|\\'\\)")
-  "Strings matching this are coerced to ftp paths by ffap.
+  "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
@@ -1086,7 +1087,7 @@ If the filename is not obvious, it also tries `ffap-alist',
 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://path" to an ftp path
+  ;; a pseudo-url "site.com://dir" to an ftp file name
   (let* ((case-fold-search t)          ; url prefixes are case-insensitive
         (data (match-data))
         (string (ffap-string-at-point)) ; uses mode alist
@@ -1101,14 +1102,20 @@ which may actually result in an url rather than a filename."
     (unwind-protect
        (cond
         ;; Immediate rejects (/ and // are too common in C++):
-        ((member name '("" "/" "//")) nil)
+         ((member name '("" "/" "//" ".")) nil)
+         ;; Immediately test local filenames.  If default-directory is
+         ;; remote, you probably already have a connection.
+         ((and (not abs) (ffap-file-exists-string name)))
+         ;; Try stripping off line numbers; good for compilation/grep output.
+         ((and (not abs) (string-match ":[0-9]" name)
+               (ffap-file-exists-string (substring name 0 (match-beginning 0)))))
         ;; Immediately test local filenames.  If default-directory is
         ;; remote, you probably already have a connection.
         ((and (not abs) (ffap-file-exists-string name)))
         ;; Accept remote names without actual checking (too slow):
         ((if abs
              (ffap-file-remote-p name)
-           ;; Try adding a leading "/" (common omission in ftp paths):
+           ;; Try adding a leading "/" (common omission in ftp file names):
            (and
             ffap-ftp-sans-slash-regexp
             (string-match ffap-ftp-sans-slash-regexp name)
@@ -1137,7 +1144,7 @@ which may actually result in an url rather than a filename."
            try))
         ;; Alist failed?  Try to guess an active remote connection
         ;; from buffer variables, and try once more, both as an
-        ;; absolute and relative path on that remote host.
+        ;; absolute and relative file name on that remote host.
         ((let* (ffap-rfs-regexp        ; suppress
                 (remote-dir
                  (cond
@@ -1155,13 +1162,12 @@ which may actually result in an url rather than a filename."
                 (or
                  (and (string-match "\\`\\(/?~?ftp\\)/" name)
                       (ffap-file-exists-string
-                       (ffap-replace-path-component
+                       (ffap-replace-file-component
                         remote-dir (substring name (match-end 1)))))
                  (ffap-file-exists-string
-                  (ffap-replace-path-component remote-dir name))))))
+                  (ffap-replace-file-component remote-dir name))))))
         )
-      (store-match-data data))))
-
+      (set-match-data data))))
 \f
 ;;; Prompting (`ffap-read-file-or-url'):
 ;;
@@ -1184,15 +1190,15 @@ which may actually result in an url rather than a filename."
                    (abbreviate-file-name (expand-file-name guess))
                    ))
          (setq dir (file-name-directory guess))))
-    (setq guess
-         (completing-read
-          prompt
-          'ffap-read-file-or-url-internal
-          dir
-          nil
-          (if dir (cons guess (length dir)) guess)
-          (list 'file-name-history)
-          ))
+    (let ((minibuffer-completing-file-name t))
+      (setq guess
+           (completing-read
+            prompt
+            'ffap-read-file-or-url-internal
+            dir
+            nil
+            (if dir (cons guess (length dir)) guess)
+            (list 'file-name-history))))
     ;; 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.
@@ -1212,6 +1218,10 @@ which may actually result in an url rather than a filename."
      (t t))))
 
 (defun ffap-read-file-or-url-internal (string dir action)
+  (unless dir
+    (setq dir default-directory))
+  (unless string
+    (setq string default-directory))
   (if (ffap-url-p string)
       (ffap-read-url-internal string dir action)
     (read-file-name-internal string dir action)))
@@ -1230,9 +1240,7 @@ which may actually result in an url rather than a filename."
   ;; Note: t and non-nil mean somewhat different reasons.
   (if (eq minibuffer-completion-table 'ffap-read-file-or-url-internal)
       (not (ffap-url-p (buffer-string))) ; t
-    (memq minibuffer-completion-table
-         '(read-file-name-internal read-directory-name-internal)) ; list
-    ))
+    (and minibuffer-completing-file-name '(t)))) ;list
 
 (and
  (featurep 'complete)
@@ -1253,7 +1261,7 @@ which may actually result in an url rather than a filename."
 ;;
 ;; Based on overlay highlighting in Emacs 19.28 isearch.el.
 
-(defvar ffap-highlight (and window-system t)
+(defvar ffap-highlight t
   "If non-nil, ffap highlights the current buffer substring.")
 
 (defvar ffap-highlight-overlay nil
@@ -1280,8 +1288,7 @@ Uses the face `ffap' if it is defined, or else `highlight'."
     (setq ffap-highlight-overlay
          (apply 'make-overlay ffap-string-at-point-region))
     (overlay-put ffap-highlight-overlay 'face
-                     (if (internal-find-face 'ffap)
-                         'ffap 'highlight)))))
+                     (if (facep 'ffap) 'ffap 'highlight)))))
 
 \f
 ;;; Main Entrance (`find-file-at-point' == `ffap'):
@@ -1347,10 +1354,7 @@ See <ftp://ftp.mathcs.emory.edu/pub/mic/emacs/> for latest version."
                                filename))))))
 
 ;; Shortcut: allow {M-x ffap} rather than {M-x find-file-at-point}.
-;; The defun is for autoload.el; the defalias takes over at load time.
 ;;;###autoload
-(defun ffap (&optional filename)
-  "A short alias for the find-file-at-point command.")
 (defalias 'ffap 'find-file-at-point)
 
 \f
@@ -1367,8 +1371,8 @@ For example, try \":/\" for URL (and some ftp) references.")
 
 (defvar ffap-menu-text-plist
   (cond
-   ((not window-system) nil)
-   (t '(face bold mouse-face highlight))) ; keymap <mousy-map>
+   ((display-mouse-p) '(face bold mouse-face highlight)) ; keymap <mousy-map>
+   (t nil))
   "Text properties applied to strings found by `ffap-menu-rescan'.
 These properties may be used to fontify the menu references.")
 
@@ -1413,7 +1417,7 @@ a rebuild.  Searches with `ffap-menu-regexp'."
 Arguments are TITLE, ALIST, and CONT \(a continuation function\).
 This uses either a menu or the minibuffer depending on invocation.
 The TITLE string is used as either the prompt or menu title.
-Each \(string . data\) ALIST entry defines a choice.
+Each ALIST entry looks like (STRING . DATA) and defines one choice.
 Function CONT is applied to the entry chosen by the user."
   ;; Note: this function is used with a different continuation
   ;; by the ffap-url add-on package.
@@ -1625,6 +1629,53 @@ Only intended for interactive use."
   (interactive) (ffap-gnus-wrapper '(ffap-menu)))
 
 \f
+(defcustom dired-at-point-require-prefix nil
+  "*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
+  :group 'ffap
+  :version "20.3")
+
+;;;###autoload
+(defun dired-at-point (&optional filename)
+  "Start Dired, defaulting to file at point.  See `ffap'."
+  (interactive)
+  (if (and (interactive-p)
+          (if dired-at-point-require-prefix
+              (not current-prefix-arg)
+            current-prefix-arg))
+      (let (current-prefix-arg)                ; already interpreted
+       (call-interactively 'dired))
+    (or filename (setq filename (dired-at-point-prompter)))
+    (cond
+     ((ffap-url-p filename)
+      (funcall ffap-url-fetcher filename))
+     ((and ffap-dired-wildcards
+          (string-match ffap-dired-wildcards filename))
+      (dired filename))
+     ((file-exists-p filename)
+      (if (file-directory-p filename)
+         (dired (expand-file-name filename))
+       (dired (concat (expand-file-name filename) "*"))))
+     ((and (file-writable-p (file-name-directory filename))
+           (y-or-n-p "Directory does not exist, create it? "))
+      (make-directory filename)
+      (dired filename))
+     ((error "No such file or directory `%s'" filename)))))
+
+(defun dired-at-point-prompter (&optional guess)
+  ;; Does guess and prompt step for find-file-at-point.
+  ;; Extra complication for the temporary highlighting.
+  (unwind-protect
+      (ffap-read-file-or-url
+       (if ffap-url-regexp "Dired file or URL: " "Dired file: ")
+       (prog1
+          (setq guess (or guess (ffap-guesser)))
+        (and guess (ffap-highlight))
+        ))
+    (ffap-highlight t)))
+\f
 ;;; Offer default global bindings (`ffap-bindings'):
 
 (defvar ffap-bindings
@@ -1634,6 +1685,7 @@ Only intended for interactive use."
      (global-set-key "\C-x\C-f" 'find-file-at-point)
      (global-set-key "\C-x4f"   'ffap-other-window)
      (global-set-key "\C-x5f"   'ffap-other-frame)
+     (global-set-key "\C-xd"    'dired-at-point)
      (add-hook 'gnus-summary-mode-hook 'ffap-gnus-hook)
      (add-hook 'gnus-article-mode-hook 'ffap-gnus-hook)
      (add-hook 'vm-mode-hook 'ffap-ro-mode-hook)
@@ -1641,13 +1693,14 @@ Only intended for interactive use."
      ;; (setq dired-x-hands-off-my-keys t) ; the default
      )
      "List of binding forms evaluated by function `ffap-bindings'.
-A reasonable ffap installation needs just these two lines:
-  (require 'ffap)
+A reasonable ffap installation needs just this one line:
   (ffap-bindings)
 Of course if you do not like these bindings, just roll your own!")
 
+;;;###autoload
 (defun ffap-bindings nil
   "Evaluate the forms in variable `ffap-bindings'."
+  (interactive)
   (eval (cons 'progn ffap-bindings)))
 
 \f