`consult-dir` inserts extra characters when called from minibuffer
Description:
Typing Alt + Shift + :edit and then pressing C-x C-d to invoke consult-dir causes the selected directory to be inserted before :edit, rather than at the cursor position after :edit.
Expected Behavior: The minibuffer should insert the directory after the command.
(This is unrelated to evil-mode.)
Pressed Ctrl+Shift+:, then typed "test ":
Pressed C-x C-d and selected the first entry:
Here is what was inserted:
I'm a little confused by the images here -- are you saying that the images show what should happen, or is there a bug there?
Consult-dir inserted ~/.emacs.d/lisp/packages/test, which is incorrect. It should have inserted ~/.emacs.d/lisp/packages/. The minibuffer prompt content ('test') must not be appended.
(Another example: typing BUG in the minibuffer and then pressing C-x C-d to insert a directory from consult-dir results in ~/.emacs.d/lisp/packages/BUG being inserted instead of ~/.emacs.d/lisp/packages/.)
Consult-dir inserted
~/.emacs.d/lisp/packages/test, which is incorrect. It should have inserted~/.emacs.d/lisp/packages/. The minibuffer prompt content ('test') must not be appended.
This is intentional, not a bug. When in a file prompt, the base file name is retained and the directory changed by consult-dir.
This is intentional, not a bug.
What is the reason for appending the basename after inserting the path?
When a path is inserted into the prompt, only the path itself is required.
When in a file prompt, the base file name is retained and the directory changed by consult-dir.
The result is that the basename appears both before and after the inserted content.
For example, if the evaluation prompt is:
TEST
The final output after inserting the path becomes:
TEST ~/.emacs.d/lisp/packages/TEST
(This results in the basename TEST appearing both before and after the inserted path.)
FYI: This is my custom function that I am using to fix this issue in my config:
(defun my-consult-dir ()
"Choose a directory and act on it.
The action taken on the directory is the value of `consult-dir-default-command'.
The default is to call `find-file' starting at this directory.
When called from the minibuffer, insert the directory into the minibuffer prompt
instead. Existing minibuffer contents will be shadowed or deleted depending on
the value of `consult-dir-shadow-filenames'.
The list of sources for directory paths is `consult-dir-sources', which can be
customized."
(interactive)
(if (not (minibufferp))
(consult-dir)
;; Minibuffer
;; Fix this issue: https://github.com/karthink/consult-dir/issues/43
(let* ((enable-recursive-minibuffers t)
(new-dir (consult-dir--pick))
(new-full-name (file-name-as-directory new-dir)))
(when new-dir
(if consult-dir-shadow-filenames
(insert "/" new-full-name)
(insert new-full-name))))))
For example, if the evaluation prompt is:
TESTThe final output after inserting the path becomes:
TEST ~/.emacs.d/lisp/packages/TEST
Thanks for the example. There are two separate issues here.
-
If you type in TEST in a minibuffer prompt, then call
consult-dirand pick a directory, you should get~/.emacs.d/lisp/packages/TEST. This is intentional.consult-dirwill not replace text you wrote as I don't know if that text is important to you. In my case I often type in the basename of a file I'm looking for in the wrong directory, then useconsult-dirwhen I realize there are no completions. But there are many other situations where this applies. -
However, you should not get
TEST ~/.emacs.d/lisp/packages/TEST. I am not able to reproduce this behavior. I tried
(read-string "prompt: ")
typed in TEST and then called consult-dir. The result was as in 1 above. So this behavior is definitely a bug. Can you give me more details on how to reproduce this?
For example, if the evaluation prompt is:
TESTThe final output after inserting the path becomes:
TEST ~/.emacs.d/lisp/packages/TESTThanks for the example. There are two separate issues here.
1. If you type in TEST in a minibuffer prompt, then call `consult-dir` and pick a directory, you should get `~/.emacs.d/lisp/packages/TEST`.
Here is another case: You should not get ~/.emacs.d/lisp/packages/TEST when the cursor is positioned after TEST . In this case, the expected result is TEST ~/.emacs.d/lisp/packages/. It is preferable to insert the path directly rather than retrieving the prompt value and appending it to the inserted path.
It is simpler and more effective to have the consult-dir package behave as if the user had copied and pasted the path.
This is intentional.
consult-dirwill not replace text you wrote as I don't know if that text is important to you.
The consult-dir package does not need to determine which part of the text is significant. It should simply insert the path, similar to a copy-and-paste operation.
In my case I often type in the basename of a file I'm looking for in the wrong directory, then use
consult-dirwhen I realize there are no completions. But there are many other situations where this applies.
Could a step-by-step example be provided to illustrate this case? It would help clarify your use case.
2. However, you should not get `TEST ~/.emacs.d/lisp/packages/TEST`. I am not able to reproduce this behavior. I tried(read-string "prompt: ")
typed in TEST and then called
consult-dir. The result was as in 1 above. So this behavior is definitely a bug. Can you give me more details on how to reproduce this?
Type M-x eval-expression, enter TEST with the cursor positioned after TEST, and then insert a path using consult-dir.
If the issue does not occur, install the evil package and enable it with evil-mode.