diff options
| author | Christopher Thorne | 2019-04-11 23:51:13 +0300 |
|---|---|---|
| committer | Juri Linkov | 2019-04-11 23:51:13 +0300 |
| commit | de238b39e335c6814283faa171b35145f124edf2 (patch) | |
| tree | 37d45836bc976f0b79ed69f54b31dd792414394d | |
| parent | 382a508ed21e4f12ace9f8871818e25235e8f05e (diff) | |
| download | emacs-de238b39e335c6814283faa171b35145f124edf2.tar.gz emacs-de238b39e335c6814283faa171b35145f124edf2.zip | |
Fix rgrep in dired using directory for search file pattern
* lisp/progmodes/grep.el (grep-read-files): Allow major modes to
define file name to use for default search pattern.
Add non-directory file at point as default search pattern candidate.
* lisp/dired.el (dired-grep-read-files): Use non-directory file at
point for grep file name pattern. (Bug#34621)
Copyright-paperwork-exempt: yes
| -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))) |