comparison lisp/dired.el @ 106239:0ac473df1bd1

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'.
author Juri Linkov <juri@jurta.org>
date Wed, 25 Nov 2009 17:11:29 +0000
parents 973f36f0716a
children b1759c4b7ef5
comparison
equal deleted inserted replaced
106238:8cb41d65f821 106239:0ac473df1bd1
597 ;; the dialog code knows we want directories. Some dialogs can 597 ;; the dialog code knows we want directories. Some dialogs can
598 ;; only select directories or files when popped up, not both. 598 ;; only select directories or files when popped up, not both.
599 (if (next-read-file-uses-dialog-p) 599 (if (next-read-file-uses-dialog-p)
600 (read-directory-name (format "Dired %s(directory): " str) 600 (read-directory-name (format "Dired %s(directory): " str)
601 nil default-directory nil) 601 nil default-directory nil)
602 (let ((default (and buffer-file-name 602 (read-file-name (format "Dired %s(directory): " str)
603 (abbreviate-file-name buffer-file-name)))) 603 nil default-directory nil)))))
604 (minibuffer-with-setup-hook
605 (lambda () (setq minibuffer-default default))
606 (read-file-name (format "Dired %s(directory): " str)
607 nil default-directory nil)))))))
608 604
609 ;; We want to switch to a more sophisticated version of 605 ;; We want to switch to a more sophisticated version of
610 ;; dired-read-dir-and-switches like the following, if there is a way 606 ;; dired-read-dir-and-switches like the following, if there is a way
611 ;; to make it more intuitive. See bug#1285. 607 ;; to make it more intuitive. See bug#1285.
612 608
656 ;; (lambda () 652 ;; (lambda ()
657 ;; (setq minibuffer-default default) 653 ;; (setq minibuffer-default default)
658 ;; (setq minibuffer-completion-table completion-table)) 654 ;; (setq minibuffer-completion-table completion-table))
659 ;; (read-file-name (format "Dired %s(directory): " str) 655 ;; (read-file-name (format "Dired %s(directory): " str)
660 ;; nil default-directory nil)))))))) 656 ;; nil default-directory nil))))))))
657
658 (defun dired-file-name-at-point ()
659 "Try to get a file name at point in the current dired buffer.
660 This hook is inteneded to be put in `file-name-at-point-functions'."
661 (let ((filename (dired-get-filename nil t)))
662 (when filename
663 (if (file-directory-p filename)
664 (file-name-as-directory (abbreviate-file-name filename))
665 (abbreviate-file-name filename)))))
661 666
662 ;;;###autoload (define-key ctl-x-map "d" 'dired) 667 ;;;###autoload (define-key ctl-x-map "d" 'dired)
663 ;;;###autoload 668 ;;;###autoload
664 (defun dired (dirname &optional switches) 669 (defun dired (dirname &optional switches)
665 "\"Edit\" directory DIRNAME--delete, rename, print, etc. some files in it. 670 "\"Edit\" directory DIRNAME--delete, rename, print, etc. some files in it.
1770 (setq dired-switches-alist nil) 1775 (setq dired-switches-alist nil)
1771 (dired-sort-other dired-actual-switches t) 1776 (dired-sort-other dired-actual-switches t)
1772 (when (featurep 'dnd) 1777 (when (featurep 'dnd)
1773 (set (make-local-variable 'dnd-protocol-alist) 1778 (set (make-local-variable 'dnd-protocol-alist)
1774 (append dired-dnd-protocol-alist dnd-protocol-alist))) 1779 (append dired-dnd-protocol-alist dnd-protocol-alist)))
1780 (add-hook 'file-name-at-point-functions 'dired-file-name-at-point nil t)
1775 (add-hook 'isearch-mode-hook 'dired-isearch-filenames-setup nil t) 1781 (add-hook 'isearch-mode-hook 'dired-isearch-filenames-setup nil t)
1776 (run-mode-hooks 'dired-mode-hook)) 1782 (run-mode-hooks 'dired-mode-hook))
1777 1783
1778 ;; Idiosyncratic dired commands that don't deal with marks. 1784 ;; Idiosyncratic dired commands that don't deal with marks.
1779 1785