Skip to content

counsel-find-file with archive file types #2998

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

Open
gusbrs opened this issue Oct 8, 2022 · 1 comment
Open

counsel-find-file with archive file types #2998

gusbrs opened this issue Oct 8, 2022 · 1 comment
Assignees

Comments

@gusbrs
Copy link
Contributor

gusbrs commented Oct 8, 2022

On a current Emacs, with default settings, when counsel-find-file meets an archive file type (tar, rar, zip, OpenDocument, etc., any extension contained in tramp-archive-suffixes) it is automatically mounted and treated as a directory. As far as I can tell, this happens because ivy-expand-file-if-directory, which is indirectly used by the counsel-find-file machinery, wraps the file name in file-name-as-directory (thus appending a slash to it) and then testing if file-directory-p. But, with tramp-archive active, which it is by default, this predicate will not only mount the file, but also return t, meaning counsel-find-file will navigate inside the archive file, instead of selecting it.

I initially reported this to Emacs itself, in the following bug report: https://lists.gnu.org/archive/html/bug-gnu-emacs/2022-10/msg00758.html

The stance of Tramp's maintainer, Michael Albinus, on the matter is the following:

There is no need for packages like counsel to check

(file-directory-p (expand-file-name "~/file.odt/"))

It is a misuse to add a slash to an existing regular file and pray that
it works. There has been a similar error in ange-ftp, see bug#56078. It
has fixed. I recommend to contact the counsel author for a fix.

I'd say he's got a point and, either way, that's the upstream position. So, it'd probably be a good idea if file-name-as-directory was dropped from ivy-expand-file-if-directory.

@basil-conto
Copy link
Collaborator

I appreciate that ivy-expand-file-if-directory may need fixing, and thank you for reporting it and getting feedback from Michael.

Before that, I'm not clear on something: the bug description makes it sound like continuing file name completion within an archive as if it were a directory is a bad thing, but is it always so?

I can imagine at least some users finding this a useful feature, so it would be a shame to lose it if that is what you are suggesting.

I just tried a couple of file name completions: I couldn't get counsel-find-file to enter .odt files, but I could get it into a .zip archive by using C-j (ivy-alt-done). By contrast, C-m (ivy-done) selects the .zip in the same way that vanilla Emacs completion does.

Given that I can choose between entering (C-j) or not entering (C-m) the .zip archive during counsel-find-file completion OOTB, I'm not sure exactly what you are suggesting Ivy should do here (except for making ivy-expand-file-if-directory better behaved if possible).

@basil-conto basil-conto self-assigned this Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants