I am looking for a command M-x find in Emacs, which behave exactly like M-x grep (allows to modify the command, prints the output nicely including links to the found files, …) and which executes find . -iname '*|*' (with the cursor placed at the vertical bar — for inserting a search pattern — if not too complicated to implement). Has anyone implemented this before? [I am aware of M-x find-grep]
I am looking for a command M-x find in Emacs, which behave exactly like
Share
Let’s start with M-x
find-diredthat does almost what you want: it reads directory from minibuffer, defaulting to current directory, and then reads otherfindarguments. The result is opened indiredmode, and I think it’s as nicely as it can get (if you think thatdiredis too verbose, check outdired-detailsand maybedired-details+packages at MELPA).Now let’s make it start with
-iname **with a cursor between the stars when it’s asking for options. Looking atfind-diredsource, we can see that it uses the value offind-argsas an initial input argument toread-string. This argument is obsolete and deprecated but awfully useful. One of its features (as we read inread-from-minibufferdescription) is providing a default point position when a cons of a string and an integer is given.We added single quotes around stars in
'**'because the arguments are subject to shell expansion.Instead of reading our own arguments from the minibuffer, we just
rebind
find-argsand delegate all the rest tofind-dired. Normallyfind-diredremembers last arguments you enter infind-argsso theybecome the new default. Rebinding it with
letensures that thismodification from our call to
find-diredwill be thrown away, soregular
find-diredwill use the arguments given to the latestregular
find-dired. It probably doesn’t matter if you don’t use regularfind-dired. If you want find arguments given to our wrapper to be used by regularfind-dired, use the following definition instead: