summaryrefslogtreecommitdiff
path: root/lisp/ffap.el
diff options
context:
space:
mode:
authorJuri Linkov <juri@jurta.org>2009-11-25 17:11:29 +0000
committerJuri Linkov <juri@jurta.org>2009-11-25 17:11:29 +0000
commit7d371eac644665cdc4afcac57e7a09560e010a31 (patch)
tree668947c7530c04603a2a5372cc13156c4f96ad0e /lisp/ffap.el
parent04ae543a28153fda0c084a5d56f59e2f7b12510d (diff)
downloademacs-7d371eac644665cdc4afcac57e7a09560e010a31.tar.gz
Provide additional default values (file name at point or at the
current Dired line) via M-n for file reading minibuffers. (Bug#5010) * minibuffer.el (read-file-name-defaults): New function. (read-file-name): Reset `minibuffer-default' to nil when it duplicates initial input `insdef'. Bind `minibuffer-default-add-function' to lambda that calls `read-file-name-defaults' in `minibuffer-selected-window'. (minibuffer-insert-file-name-at-point): New command. * files.el (file-name-at-point-functions): New defcustom. (find-file-default): Remove defvar. (find-file-read-args): Don't use `find-file-default'. Move `minibuffer-with-setup-hook' that sets `minibuffer-default' to `read-file-name'. (find-file-literally): Use `read-file-name' with `confirm-nonexistent-file-or-buffer'. * ffap.el (ffap-guess-file-name-at-point): New autoloaded function. * dired.el (dired-read-dir-and-switches): Move `minibuffer-with-setup-hook' that sets `minibuffer-default' to `read-file-name'. (dired-file-name-at-point): New function. (dired-mode): Add hook `dired-file-name-at-point' to `file-name-at-point-functions'.
Diffstat (limited to 'lisp/ffap.el')
-rw-r--r--lisp/ffap.el23
1 files changed, 23 insertions, 0 deletions
diff --git a/lisp/ffap.el b/lisp/ffap.el
index a0e0d411206..7d3f279f724 100644
--- a/lisp/ffap.el
+++ b/lisp/ffap.el
@@ -1893,6 +1893,29 @@ Only intended for interactive use."
(call-interactively 'dired-at-point)))
+;;; 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 inteneded 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))))))
+
+
;;; Offer default global bindings (`ffap-bindings'):
(defvar ffap-bindings