File Search: Retrieve a loaded file buffer specified by a filter containing text

This seems like a pretty typical use case, but I'll be damned if I can figure it out. There must be something fundamental that I'm missing.

find-dired is basically the front of the find command, which gives the result with a shaded buffer

find-grep-dired seems to be more related to grep than to search. and produces a shaded buffer, but it looks for all the files in the directory tree.

I would like to be able to start from the given path and look for * .css for # some-id and give it dired-buffer for further processing.

It seems that all the parts are there, but I did not understand this. Therefore, I think this is something fundamental that I may have missed.

+3
source share
4 answers

It looks like the function you are looking for is grep . It will invoke the grep utility with the expression you give it and collect the output in an interactive buffer. You can select any of the matching lines in the buffer to go to that line in the file from which the match matches.

For example, if you run M-x grep, you should receive the following prompt in the mini-buffer:

Run grep (like this): grep -n

Then you add the regex pattern and glob that you want to pass grep:

Run grep (like this): grep -n #some-id *.css

#some-id , *.css . , rgrep grep. , , ?

+2

, emacs-lisp, :

(defun find-iname-grep-dired (dir pattern regexp)
  (interactive
   "DFind-name (directory): \nsFind-name (filename wildcard): \nsFind-grep (grep regexp): ")
  (find-dired dir (concat "-iname " (shell-quote-argument pattern) " "
                          "-type f -exec " grep-program " " find-grep-options " -e "
                          (shell-quote-argument regexp) " "
                          (shell-quote-argument "{}") " "
                          (shell-quote-argument ";"))))

find-grep-dired find-name-dired find-name-dired .

+3

. . , . , find-dired , Windows args "-exec grep", . linux-, , grep.

....

  #on Linux
  M-x find-dired
  Run Find in Directory: <current_path> 
  Run find(with args): -type f -exec grep -q -e \{\} \; 

  #on windows
  M-x find-dired
  Run Find in Directory: <current_path> 
  Run find(with args): 

  #Solution
  M-x find-dired
  Run Find in Directory: <current_path> 
  Run find(with args): -type f -iname "*.css" -exec grep -q -e #some-id \{\} \; 
+1

( ):

the only thing that is missing is output to the bottled buffer , so I can do things like select / move / copy all these files at once

It is a pity that I have not seen this issue so far. This feature is available with Dired + . The command diredp-grepped-files-other-windowopens Dired in grephit files . (It also works for any other mode derived from compilation-mode.)

+1
source

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


All Articles