Looking at the code, find-name-dired
delegates to find-dired
.
Looking at the find-dired
code, it opens a buffer with name "*Find*"
. From its source:
(get-buffer-create "*Find*")
So if we rename the first buffer we made, the second call to find-name-dired
will not touch it. You can rename the buffer with M-x rename-buffer (lets you choose a name) or M-x rename-uniquely (adds a numerical suffix <2>
, <3>
, …).
Rather than renaming by hand, here's a wrapper function around find-name-dired
that changes the buffer name after it's ran. Note that it will reuse any preexisting buffer called *Find*
, so prior searches ran with find-name-dired
or other find commands will go away.
(defun find-name-dired-with-unique-buffer-name (dir pattern)
"Search DIR recursively for files matching the globbing pattern PATTERN,
and run Dired on those files.
PATTERN is a shell wildcard (not an Emacs regexp) and need not be quoted.
The default command run (after changing into DIR) is
find . -name \\='PATTERN\\=' -ls
See `find-name-arg' to customize the arguments."
(interactive
"DFind-name (directory): \nsFind-name (filename wildcard): ")
(find-name-dired dir pattern)
(let ((buffer-name (format "*Find: %s in %s*" pattern dir)))
"If we previously searched for the same thing, kill that buffer for reuse"
(when (get-buffer buffer-name)
(kill-buffer buffer-name))
;;we are left in a buffer called "*Find*"
(rename-buffer buffer-name)))