abo-abo / swiper

Ivy - a generic completion frontend for Emacs, Swiper - isearch with an overview, and more. Oh, man!
https://oremacs.com/swiper/
2.29k stars 338 forks source link

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

Closed tumashu closed 9 years ago

tumashu commented 9 years ago

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

abo-abo commented 9 years ago

Just bind ivy-partial like this:

(define-key ivy-minibuffer-map (kbd "TAB") 'ivy-partial)
tumashu commented 9 years ago

Thanks!

tumashu commented 9 years ago

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 commented 9 years ago

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

(define-key ivy-minibuffer-map (kbd "<return>") 'ivy-alt-done)
Ergus commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

@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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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

Ergus commented 6 years ago

Now it is perfect. Thank you very much!

llemaitre19 commented 2 years ago

@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 commented 2 years ago

@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 commented 2 years ago

@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 !