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

How to let `ivy-partial-or-done' only complete and do not open file or directory? #86

Closed
tumashu opened this issue May 8, 2015 · 15 comments

Comments

@tumashu
Copy link
Contributor

tumashu commented May 8, 2015

I want to use TAB to complete directory or file name, but don't open, is it possible?

@abo-abo abo-abo closed this as completed in f2a0966 May 8, 2015
@abo-abo
Copy link
Owner

abo-abo commented May 8, 2015

Just bind ivy-partial like this:

(define-key ivy-minibuffer-map (kbd "TAB") 'ivy-partial)

@tumashu
Copy link
Contributor Author

tumashu commented May 8, 2015

Thanks!

@tumashu
Copy link
Contributor Author

tumashu commented May 10, 2015

I try, but feel confusion, following code seed more comfort

(defun eh-ivy-partial-or-done ()
  (interactive)
  (or (ivy-partial)
      (ivy-alt-done)))

(define-key ivy-minibuffer-map (kbd "TAB") 'eh-ivy-partial-or-done)

@tumashu
Copy link
Contributor Author

tumashu commented May 10, 2015

I also find the follow configure is also a comfort tip:

(define-key ivy-minibuffer-map (kbd "<return>") 'ivy-alt-done)

@Ergus
Copy link
Contributor

Ergus commented Sep 8, 2018

Hi, sorry for necropumping this thread, but it is very related

I am trying this:
(define-key ivy-minibuffer-map (kbd "TAB") 'ivy-partial)

and the behaviour is ALMOST what I wanted. BUT the candidates list is not shown if I press tab many times, it requires to press C-j to be shown. Basically I want this to behave like bash or zsh completion because it is more intuitive I think.
My idea is that pressing tab I should get a completion if it is unique else the candidates list, and only open a file (or dired maybe) if I press enter or C-j.

What is missing now it the candidates list with the second tab press, because it does nothing.

I don't want to bother too much, but I don't know if this is the expected behaviour or an issue, maybe it is something I can configure or it requires more complicated work??

Any help please?

@abo-abo
Copy link
Owner

abo-abo commented Sep 8, 2018

What is missing now it the candidates list with the second tab press, because it does nothing.

What do you think should happen with the second tab press? The candidates list is already shown and there's nothing further to complete.

If you really see a use case improvement, please open a new issue and describe a detailed scenario of how you think it should work.

@Ergus
Copy link
Contributor

Ergus commented Sep 8, 2018

What happens to me is when looking for a file. The candidates list is not there after a completion and it needs C-j to be shown.

C-x C-f /ho

image

TAB

image

Now TAB here does nothing.

C-j (This is what I thing the second tab should do)

image

@abo-abo
Copy link
Owner

abo-abo commented Sep 9, 2018

@Ergus OK, I see now. The intended design of ivy-partial is to produce no other effects except extending your input. So you should not be expecting that function to select a candidate.

Instead, the default biding of TAB is ivy-partial-or-done, which actually does what you want in the described use case.

@Ergus
Copy link
Contributor

Ergus commented Sep 9, 2018

Yes, I know. But what I want is to avoid tab to open a file or dired if the completion is actually in a file or directory. ivy-partial-or-done does what I want, but a wrong extra tab makes too much.
I think that all completions should be bound to tabs (alt or partial) and also to show the list directory; but "done" (open file in emacs or call dired) should be something else like enter.
This is the bash default behaviour that is more familiar for many users and compatible with all the other shells like zsh; but also iPython, and any thing that uses read-line in general.
Is this possible?

@Ergus
Copy link
Contributor

Ergus commented Sep 11, 2018

Hi abo-abo:

If the function ivy--directory-done substitutes the 2 calls to (ivy-done) with an "alias" function (initialized by default to ivy-done); then we can reassign the alias symbol in the configuration but the default behaviour will not change. We can just reassign the alias to nothing and the behaviour will be like bash; or to something else for advanced users.

Does it makes sense?

abo-abo added a commit that referenced this issue Sep 11, 2018
* ivy-test.el (ivy-partial-files): Add test.

Re #86
@abo-abo
Copy link
Owner

abo-abo commented Sep 11, 2018

@Ergus Please have a look at the change. If there are more changes required, please open a new issue.

@Ergus
Copy link
Contributor

Ergus commented Sep 12, 2018

Now it is perfect. Thank you very much!

@llemaitre19
Copy link

@Ergus @abo-abo , could you please detail the final solution which matches bash completion behavior ? (I think that last TAB should not perform ENTER actions too)

@Ergus
Copy link
Contributor

Ergus commented Oct 5, 2021

@Ergus @abo-abo , could you please detail the final solution which matches bash completion behavior ? (I think that last TAB should not perform ENTER actions too)

I made this:

(define-key ivy-minibuffer-map (kbd "TAB") #'ivy-partial)
(define-key ivy-minibuffer-map (kbd "RET") #'ivy-alt-done)

@llemaitre19
Copy link

@Ergus thanks for your reply. I think I had already tried this configuration. But trying it again, lets me realize that the way I'd like to use completion in Ivy is not exactly the same as bash but a mix between bash and default Ivy behavior : TAB only for completion (after entering a character or navigating with up or down arrows), ENTER only for opening file or directory.

If someone succeeds in configuring a similar behavior in Ivy, please let me know.

In the meantime, I'll give a try to @Ergus configuration, and who knows, maybe even adopt it !

This issue was closed.
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

4 participants