summaryrefslogtreecommitdiff
path: root/lisp/files.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/files.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/files.el')
-rw-r--r--lisp/files.el23
1 files changed, 13 insertions, 10 deletions
diff --git a/lisp/files.el b/lisp/files.el
index 1bde2be0ef0..8478151cf78 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -411,6 +411,14 @@ and should return either a buffer or nil."
:type '(hook :options (cvs-dired-noselect dired-noselect))
:group 'find-file)
+;; FIXME: also add a hook for `(thing-at-point 'filename)'
+(defcustom file-name-at-point-functions '(ffap-guess-file-name-at-point)
+ "List of functions to try in sequence to get a file name at point.
+Each function should return either nil or a file name found at the
+location of point in the current buffer."
+ :type '(hook :options (ffap-guess-file-name-at-point))
+ :group 'find-file)
+
;;;It is not useful to make this a local variable.
;;;(put 'find-file-not-found-hooks 'permanent-local t)
(defvar find-file-not-found-functions nil
@@ -1275,9 +1283,6 @@ its documentation for additional customization information."
;;(make-frame-visible (window-frame old-window))
))
-(defvar find-file-default nil
- "Used within `find-file-read-args'.")
-
(defmacro minibuffer-with-setup-hook (fun &rest body)
"Add FUN to `minibuffer-setup-hook' while executing BODY.
BODY should use the minibuffer at most once.
@@ -1298,12 +1303,7 @@ Recursive uses of the minibuffer will not be affected."
(remove-hook 'minibuffer-setup-hook ,hook)))))
(defun find-file-read-args (prompt mustmatch)
- (list (let ((find-file-default
- (and buffer-file-name
- (abbreviate-file-name buffer-file-name))))
- (minibuffer-with-setup-hook
- (lambda () (setq minibuffer-default find-file-default))
- (read-file-name prompt nil default-directory mustmatch)))
+ (list (read-file-name prompt nil default-directory mustmatch)
t))
(defun find-file (filename &optional wildcards)
@@ -2020,7 +2020,10 @@ regardless of whether it was created literally or not.
In a Lisp program, if you want to be sure of accessing a file's
contents literally, you should create a temporary buffer and then read
the file contents into it using `insert-file-contents-literally'."
- (interactive "FFind file literally: ")
+ (interactive
+ (list (read-file-name
+ "Find file literally: " nil default-directory
+ (confirm-nonexistent-file-or-buffer))))
(switch-to-buffer (find-file-noselect filename nil t)))
(defvar after-find-file-from-revert-buffer nil)