-
-
Notifications
You must be signed in to change notification settings - Fork 338
Description
I see strange behaviour when ivy
starts a find-file
completion when in a directory that contains dollar signs (on Linux). Here's a quick example:
Repro:
$ mkdir test && cd test
$ mkdir 'dir1' && mkdir '$dir2'
$ touch 'dir1/file1' 'dir1/file1-1' '$dir2/file2' '$dir2/file2-2'
$ cat > init.el <<EOF
(package-initialize)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/"))
(package-refresh-contents)
(package-install 'ivy)
(ivy-mode 1)
(find-file "~/$dir2/file2")
(setq use-file-dialog nil)
(call-interactively 'find-file)
EOF
$ HOME=$PWD emacs -Q -l init.el
When starting find-file
when in dir1/file1
, ivy populates the starting directory correctly
When starting find-file
when in $dir2/file2
, ivy starts the navigation outside $dir2
(sometimes the list also contains an extra copy of ~/$dir2
at the top as you can see on the screen, but i wasn't unable to repro it reliably):
It is likely related to the following:
- built-in
find-file
executessubstitute-in-file-name
on the final input string to replace environment variables in the supplied path - hence, the initialisation for the completion escapes the directory as
$$dir2
instead of$dir2
so that it can roundtrip without the expansion ivy
is probably not ready for this.
I have seen some code that does (replace-regexp-in-string "\\$\\$" "$" s)
, but here in ivy--reset-state
where initial-input
contains escaped $$dir2
, at least the following potential bugs may happen
- [https://github.com/abo-abo/swiper/blob/8dc02d5b725f78d1f80904807b46f5406f129674/ivy.el#L2364](this comparison) may fail comparing
$$foobar
to$foobar
- [https://github.com/abo-abo/swiper/blob/8dc02d5b725f78d1f80904807b46f5406f129674/ivy.el#L2370](this check) will fail when looking for
$$foobar
directory
i'll advice/hack around it on my side so that it just works, but i have no idea how to fix this correctly, so i'll leave it up to you folks