Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

counsel-find-file destroys filenames when called with ivy-call or ivy-next-line-and-call #1903

Closed
vornado63 opened this issue Jan 26, 2019 · 5 comments

Comments

@vornado63
Copy link

@vornado63 vornado63 commented Jan 26, 2019

steps to reproduce:

dired some directory:

  /usr/local/share/emacs/26.1:
  total used in directory 36K available 128892068
  drwxr-sr-x  5 root staff 4.0K Sep 30 20:02 .
  drwxr-sr-x  4 root staff 4.0K Jun  5  2018 ..
  drwxr-xr-x 14 root staff 4.0K Sep 30 20:03 etc
  drwxr-xr-x 26 root staff  20K Sep 30 20:03 lisp
  drwxr-sr-x  2 root staff 4.0K Jun  5  2018 site-lisp

call counsel-find-file (i used something like ^lisp el.gz$)

call ivy-next-line-and-call multiple times

This yields buffer with nonexisting files:

 MRL Name                    Size Mode             Filename/Process
 --- ----                    ---- ----             ----------------
[ Default ]
  %  savehist.el.gz<...     15094 Emacs-Lisp       /usr/local/share/emacs/26.1/lisp/savehist.el.gz
  %  26.1                     330 Dired by name    /usr/local/share/emacs/26.1/
     savehist.el.gz<...         0 Emacs-Lisp       /usr/local/share/emacs/26.1/lisp/lisp/lisp/lisp/savehist.el.gz
     dos-w32.el.gz              0 Emacs-Lisp       /usr/local/share/emacs/26.1/lisp/lisp/lisp/dos-w32.el.gz
     avoid.el.gz                0 Emacs-Lisp       /usr/local/share/emacs/26.1/lisp/lisp/avoid.el.gz
  %  indent.el.gz           29899 Emacs-Lisp       /usr/local/share/emacs/26.1/lisp/indent.el.gz

In this case, the dirname "lisp" appears multiple times.

(emacs-version)
"GNU Emacs 26.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.11) of 2018-08-21"

counsel-20190123.1048
ivy-20190123.1100

This problem only occurs when opening files in a subdirectory of the cwd.

@basil-conto
Copy link
Collaborator

@basil-conto basil-conto commented Feb 12, 2019

Sorry, I can't reproduce what I think you mean, but your recipe is not clear.

counsel-find-file destroys filenames

What does "destroy" mean in this context, and what do you mean by "filename"? Are you talking about the buffer-local value of the variable buffer-file-name in file-visiting buffers? Or the name of the file on the filesystem?

call counsel-find-file (i used something like ^lisp el.gz$)

I don't understand how counsel-find-file can simultaneously match the lisp parent directory and el.gz files within it. Please elaborate on precisely which commands you invoke, which keys you type, etc.

This yields buffer with nonexisting files:

Again, this is not clear to me. What does "yield buffer" mean? Did you create the Ibuffer buffer, or was it created automatically? What does "buffer with nonexisting file" mean? Do you mean a buffer not visiting a file, i.e. with a buffer-file-name value of nil? Or does the non-nil value of buffer-file-name not correspond to any existing files?

Here's what I tried:

  1. make plain
  2. C-xd//usr/share/emacs/26.1RET
  3. C-xC-flisp/gz
  4. M-RET
    Result: abbrev.el.gz is visited, as expected.
  5. C-M-n
    Result: align.el.gz is visited, as expected.

Here's my full Emacs version:

In GNU Emacs 26.1 (build 1, x86_64-pc-linux-gnu, X toolkit, Xaw3d scroll bars)
 of 2019-02-03, modified by Debian built on zam904
Windowing system distributor 'The X.Org Foundation', version 11.0.12003000
System Description:	Debian GNU/Linux buster/sid

I get the same results with the following Emacs version as well:

In GNU Emacs 27.0.50 (build 13, x86_64-pc-linux-gnu, X toolkit, Xaw3d scroll bars)
 of 2019-02-11 built on thunk
Repository revision: d41f9123ecae45654f006d736996343275d774bd
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12003000
System Description: Debian GNU/Linux buster/sid

What am I missing?

@vornado63
Copy link
Author

@vornado63 vornado63 commented Feb 13, 2019

my head --> table --> ouch. You are missing nothing, i am afraid, i was a bit tired when i wrote this issue.
In principle, my obeservation is correct, except one tiny, little thingy... the function to blame.
Of course counsel-find-file is innocent, the suspect is counsel-file-jump.
Im am so sorry for wasting your time; please accept my apologies.
I'll logout now, turn off my computer, an write on paper 100 times: "Reread your bugreports one more time".

@basil-conto
Copy link
Collaborator

@basil-conto basil-conto commented Feb 14, 2019

Ah, no worries. I can reproduce the issue now. Does the following patch solve it?

diff --git a/counsel.el b/counsel.el
index fa214c4..658b87c 100644
--- a/counsel.el
+++ b/counsel.el
@@ -2451,8 +2451,8 @@ counsel-file-jump
    (list nil
          (when current-prefix-arg
            (read-directory-name "From directory: "))))
-  (counsel-require-program "find")
-  (let* ((default-directory (or initial-directory default-directory)))
+  (counsel-require-program find-program)
+  (let ((default-directory (or initial-directory default-directory)))
     (ivy-read "Find file: "
               (split-string
                (shell-command-to-string
@@ -2460,9 +2460,7 @@ counsel-file-jump
                "\n" t)
               :matcher #'counsel--find-file-matcher
               :initial-input initial-input
-              :action (lambda (x)
-                        (with-ivy-window
-                          (find-file (expand-file-name x ivy--directory))))
+              :action #'find-file
               :preselect (counsel--preselect-file)
               :require-match 'confirm-after-completion
               :history 'file-name-history

@justbur Why did you deem the call to with-ivy-window necessary?

@vornado63
Copy link
Author

@vornado63 vornado63 commented Feb 16, 2019

patching file counsel.el
Hunk #1 succeeded at 2452 (offset 1 line).
Hunk #2 succeeded at 2461 (offset 1 line).

recompile..

works as expected. :-) Thank you!
btw: when will this be available via melpa?

@vornado63 vornado63 closed this Feb 16, 2019
basil-conto added a commit to basil-conto/swiper that referenced this issue Feb 17, 2019
Expand candidate file names relative to original default-directory,
not that of ivy-state-window (ivy--directory seems to always be nil
in the action function).

Fixes abo-abo#1903
@basil-conto
Copy link
Collaborator

@basil-conto basil-conto commented Feb 17, 2019

@vornado63 I'm glad it resolves your issue.

when will this be available via melpa?

If and when #1938 gets merged, plus a few hours to propagate.

astoff added a commit to astoff/swiper that referenced this issue Jan 1, 2021
Expand candidate file names relative to original default-directory,
not that of ivy-state-window (ivy--directory seems to always be nil
in the action function).

Fixes abo-abo#1903
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants