I don't use Counsel. But from a quick look at its code:
It looks like counsel-find-file
binds default-directory
to use the INITIAL-DIRECTORY
argument, but if the current buffer is in Dired mode then that binding is overridden to use the value of dired-current-directory
instead.
And that function returns the value of the directory for the listing you are currently in in Dired. (E.g., if you are in a subdir listing then that subdir is used, else the top-level dir is used.)
(defun counsel--find-file-1 (prompt initial-input action caller)
(let ((default-directory
(if (eq major-mode 'dired-mode) ; <================
(dired-current-directory) ; <================
default-directory)))
...))
[FWIW, I suspect the author of Counsel might want to change that (eq major-mode 'dired-mode)
to use derived-mode
instead. But that's unrelated to your question/problem.]
So the directory used in counsel--find-file-1
is the value of dired-current-directory
from your current position in Dired.
This binding of default-directory
in counsel-find-file
is overridden by the binding in counsel--find-file-1
:
(let ((tramp-archive-enabled nil)
(default-directory (or initial-directory default-directory)))
...)
You'll notice, by the way, that the doc of counsel-find-file
doesn't even mention argument INITIAL-DIRECTORY
:
Forward to find-file
.
When INITIAL-INPUT
is non-nil
, use it in the minibuffer during completion.
If it did, it would probably have to tell you something about its use, including the fact that it's apparently useless when in Dired.
Dunno whether this is a misfeature, a bug, or a feature. If you don't get a good answer here from someone else, and you think it perhaps shouldn't behave this way, consider reporting it to the Counsel maintainer.
nil
. It evaluates to itself.