Emacs find-grep-dired, then automatically isearch-forward with the given regular expression

I usually do find-grep-diredto find an expression in the project directory. This gives me a good diredview of all the files containing this expression. But my next step is to invariably open one of these files and do it isearch-forwardwith the same search expression. How can I save myself from entering search words twice each time (or more than two times if there are several files that I want to edit)?

+3
source share
3 answers

This should work for you:

  • Run find-grep-diredas usual
  • Click * t(dired-toggle-marks) to mark all files.
  • A, dired-do-search. M-p, find-grep,
  • . , M-,, , .
  • Profit? (, )

, :

(defun find-grep-dired-do-search (dir regexp)
  "First perform `find-grep-dired', and wait for it to finish.
Then, using the same REGEXP as provided to `find-grep-dired',
perform `dired-do-search' on all files in the *Find* buffer."
  (interactive "DFind-grep (directory): \nsFind-grep (grep regexp): ")
  (find-grep-dired dir regexp)
  (while (get-buffer-process (get-buffer "*Find*"))
    (sit-for 1))
  (with-current-buffer "*Find*"
    (dired-toggle-marks)
    (dired-do-search regexp)))
+5

, find-grep-dired kill (C-SPACE C-a M-w). kill (C-s M-y). M-y .

() isearch-forward, C-h k C-s.

+3

? M-x igrep-find igrep.el.

By default, it searches for all occurrences of the template, but you can change the behavior to just find the first such event with:

(setq igrep-options "-i -m 1")   ;; I like -i for case-insensitivity

This will create a compilation style buffer (with a name *igrep*) with one line for each file, and when you click on a line (or do C-x `), you will automatically put on a line that has a match. In addition, you can see the corresponding line in the buffer *igrep*.

Obviously, if you want to see more than one match in a file, change the number after -mor completely omit this part.

+2
source

Source: https://habr.com/ru/post/1791479/


All Articles