I'm looking for something similar to (find-buffer-visiting FILENAME &optional PREDICATE)
that would find a dired-mode buffer visiting a specified directory. Something like:
(find-buffer-visiting-dir DIRNAME)
The built-in find-buffer-visiting
only searches buffer visiting files quite unfortunately. It checks if the buffer has a local buffer-file-name variable bound. The optional PREDICATE is therefore used only on files.
A potential improvement for that function would be to write
(find-buffer-visiting FILENAME &optional PREDICATE FILTER)
where FILTER would be a filter function used on all buffers to determine if the buffer should be included in the search.
Is there something like this already available?
dired+
you can checkdiredp--reuse-dir-buffer-helper
. Several interactive commands indired+
use this helper. But, I am not sure whether it really does what you want. (Your question smells a bit like an XY-problem.)