How do I define "Mx find" the same way as "Mx grep"?

I'm looking for a command M-x find

in Emacs that behaves exactly like M-x grep

(allows you to modify the command, print nicely, including links to found files, ...) and that does find . -iname '*|*'

(with the cursor on the vertical bar - to insert a search pattern - if not too difficult to implement). Has anyone implemented this before? [I know M-x find-grep

]

0


source to share


3 answers


Let's start with M-x find-dired

, which does almost what you want: it reads a directory from the minibuffer, defaults to the current directory, and then reads other arguments find

. The result opens in mode dired

and I think it is as good as it can get (if you think it's dired

too verbose, check dired-details

and maybe the dired-details+

packages on MELPA ).

Now let's start with -iname **

using the cursor between the stars when prompted for options. Looking at the source find-dired

, we can see that it uses the value find-args

as the original input argument for read-string

. This argument is outdated and out of date, but terribly useful. One of its possibilities (as we read in the description read-from-minibuffer

) is to provide a default position when the minuses of a string and an integer are given.

(defun marius/find-dired ()
  (interactive)
  (let ((find-args '("-iname '**'" . 10)))
    (call-interactively 'find-dired)))

      



We added single quotes around the stars in '**'

because the arguments are subject to shell expansion.

Instead of reading our own arguments from the minibuffer, we just rebind find-args

and delegate everyone else find-dired

. As usual, find-dired

remembers the last arguments entered in find-args

so that they become the new default. Using the permutation let

ensures that this change from our call to find-dired

is thrown, so that the regular find-dired

will use the arguments given by the last regular find-dired

. It probably doesn't matter if you don't use the regular one find-dired

. If you want to find the arguments provided by our shell to be used by a regular one find-dired

, use the following definition instead:

(defun marius/find-dired ()
  (interactive)
  (setq find-args '("-iname '**'" . 10))
  (call-interactively 'find-dired))

      

+3


source


I think it find-dired

fulfills your requirements (except that it doesn't initialize the command with "-iname" and lets you type it in).

For example:



  • M-x find-dired

    RET(execute find-dired

    )
  • C-j(accept the default directory: .

    )
  • -iname "*.foo"

    RET (enter command line parameters)

The results are presented in a buffer dired

.

+1


source


You can start with:

(defun eab/find-grep ()
  (interactive)
  (let ((grep-host-defaults-alist nil)
        (grep-find-command
         `(,"find . -iname '**' -type f -print0 | xargs -0 -e grep -nH -m 1 -e \"^\"" . 17)))
    (call-interactively 'find-grep)))

      

Also I use:

(defun eab/grep ()
  (interactive)
  (let ((grep-host-defaults-alist nil)
        (grep-command
         `(,(concat "grep -i -nH -e  *."
                    (ignore-errors
                      (file-name-extension buffer-file-name))) . 16)))
    (call-interactively 'grep)))

      

EDIT: Now grep-find command to search the first line of each file by default.

0


source







All Articles