reddit / emacs

Shorten find-file path by removing minibuffer "default directory" prefix when entering ~ ?

shmulkinator · 2022-06-26 22:37
When I visit a file I often enter `~` (or `~user` or `/`) to set the navigation root accordingly. The standard behavior in this case seems to be to continue to show the "default directory" (in this case, `/bin`) in the minibuffer, despite the fact that I've indicated that I'm looking for a file elsewhere: https://preview.redd.it/r1n95gckj1891.png?width=358&format=png&auto=webp&s=bacf8e03bcc910d03e0ce85dd5e5216848e05119 Once I've entered `~/` I'd like the minibuffer to look like this: https://preview.redd.it/t4ulbn7dk1891.png?width=228&format=png&auto=webp&s=b79e8452cfc9ba23dafbfba760dc06f9a7d7c410 I know that I can delete the "default directory" part of the path by hand, but that's cumbersome. I've looked in the Emacs manual, and I don't see an option that produces this behavior. Am I missing something?
00-11 · 2022-06-26 22:42
`M-x customize-option insert-default-directory`
shmulkinator · 2022-06-26 23:03
Thanks. This does what I was looking for, but now I'm going to get greedy: I would also like `~` to delete any file path which precedes it. For example, assume that I have started to look under `~/tmp` and then would like to look under `~/bar`. Current behavior (sorry, I can't insert a screen shot in a reply): `Find file: {~/tmp/} ~/bar` Desired behavior: `Find file: ~/bar`
Dragoncraft89 · 2022-06-26 23:07
[Ido](https://www.gnu.org/software/emacs/manual/html_mono/ido.html) does this So you can use `ido-find-file` as a replacement for `find-file`
kunht · 2022-06-26 23:17
Maybe `M-x customize-option file-name-shadow-properties RET` (and `file-name-shadow-tty-properties` for `-nw`)? The first option "Invisible" looks like what you want.
shmulkinator · 2022-06-26 23:18
Thanks. I'm using [vertico](https://github.com/minad/vertico). Maybe there's some sort of plug-in or modification that can be used with `vertico` to achieve the same effect.
shmulkinator · 2022-06-26 23:26
Yes! That does the trick: specifically, customizing `File Name Shadow Properties` by checking `Invisible` does exactly what I want. The equivalent custom setting for `-nw` is `File Name Shadow Tty Properties`. Thanks!
00-11 · 2022-06-27 01:11
Just use `M-n`, then type `~/bar` after the default name that you just inserted.
samsjj · 2022-06-29 06:46
https://github.com/minad/vertico/blob/c511f874fa0f39e4691ab145b233bbe5b23e4fa2/extensions/vertico-directory.el#L92 :hook (rfn-eshadow-update-overlay . vertico-directory-tidy) ; Correct file path when changed https://kristofferbalintona.me/posts/202202211546/#extensions I have not tried it but came across this
shmulkinator · 2022-06-29 15:51
This works perfectly! I didn't know about that function; goes to show you that reading the source can be very helpful. Thanks!