diff options
| -rw-r--r-- | lisp/dired.el | 9 | ||||
| -rw-r--r-- | lisp/progmodes/grep.el | 12 |
2 files changed, 19 insertions, 2 deletions
diff --git a/lisp/dired.el b/lisp/dired.el index 4c2c3f44e72..63082fe3927 100644 --- a/lisp/dired.el +++ b/lisp/dired.el | |||
| @@ -774,6 +774,15 @@ as an argument to `dired-goto-file'." | |||
| 774 | (file-name-as-directory (abbreviate-file-name filename)) | 774 | (file-name-as-directory (abbreviate-file-name filename)) |
| 775 | (abbreviate-file-name filename))))) | 775 | (abbreviate-file-name filename))))) |
| 776 | 776 | ||
| 777 | (defun dired-grep-read-files () | ||
| 778 | "Use file at point as the file for grep's default file-name pattern suggestion. | ||
| 779 | If a directory or nothing is found at point, return nil." | ||
| 780 | (let ((file-name (dired-file-name-at-point))) | ||
| 781 | (if (and file-name | ||
| 782 | (not (file-directory-p file-name))) | ||
| 783 | file-name))) | ||
| 784 | (put 'dired-mode 'grep-read-files 'dired-grep-read-files) | ||
| 785 | |||
| 777 | ;;;###autoload (define-key ctl-x-map "d" 'dired) | 786 | ;;;###autoload (define-key ctl-x-map "d" 'dired) |
| 778 | ;;;###autoload | 787 | ;;;###autoload |
| 779 | (defun dired (dirname &optional switches) | 788 | (defun dired (dirname &optional switches) |
diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el index c0f47159c95..8c7a58fd8bd 100644 --- a/lisp/progmodes/grep.el +++ b/lisp/progmodes/grep.el | |||
| @@ -959,8 +959,16 @@ substitution string. Note dynamic scoping of variables.") | |||
| 959 | The pattern can include shell wildcards. As whitespace triggers | 959 | The pattern can include shell wildcards. As whitespace triggers |
| 960 | completion when entering a pattern, including it requires | 960 | completion when entering a pattern, including it requires |
| 961 | quoting, e.g. `\\[quoted-insert]<space>'." | 961 | quoting, e.g. `\\[quoted-insert]<space>'." |
| 962 | (let* ((bn (or (buffer-file-name) | 962 | (let* ((grep-read-files-function (get major-mode 'grep-read-files)) |
| 963 | (replace-regexp-in-string "<[0-9]+>\\'" "" (buffer-name)))) | 963 | (file-name-at-point |
| 964 | (run-hook-with-args-until-success 'file-name-at-point-functions)) | ||
| 965 | (bn (if grep-read-files-function | ||
| 966 | (funcall grep-read-files-function) | ||
| 967 | (or (if (and (stringp file-name-at-point) | ||
| 968 | (not (file-directory-p file-name-at-point))) | ||
| 969 | file-name-at-point) | ||
| 970 | (buffer-file-name) | ||
| 971 | (replace-regexp-in-string "<[0-9]+>\\'" "" (buffer-name))))) | ||
| 964 | (fn (and bn | 972 | (fn (and bn |
| 965 | (stringp bn) | 973 | (stringp bn) |
| 966 | (file-name-nondirectory bn))) | 974 | (file-name-nondirectory bn))) |