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

space (magic-space) is too aggressive #2

Closed
wookayin opened this issue May 5, 2020 · 25 comments
Closed

space (magic-space) is too aggressive #2

wookayin opened this issue May 5, 2020 · 25 comments
Labels
bug Something isn't working

Comments

@wookayin
Copy link

wookayin commented May 5, 2020

Currently, it automatically accepts the completion when there are completions (automatically) being shown.

Say we want to type for a in 0 1 2; do. There is a.py that is file suggestion.

❯❯❯ for a|     
a.py          

Pressing space here, it will accept the completion:

❯❯❯ for a.py |
a.py         bin/         etc/     ...(more)

which should not be the case.

@weilbith
Copy link

weilbith commented May 5, 2020

Yes. Some behavior like in Vim for the completeopt setting with noinsert and noselect set. So you get the list populated, but you must manually trigger at least once the selection of the first entry (or any other) and complete. Would be awesome.

@marlonrichert
Copy link
Owner

@weilbith I don't use vim, so I have no idea what you're talking about there. Can you try to explain it in more detail?

marlonrichert added a commit that referenced this issue May 5, 2020
@marlonrichert
Copy link
Owner

@wookayin @weilbith I updated the code. Can you test if it resolves the issue for you?

@wookayin
Copy link
Author

wookayin commented May 5, 2020

Thanks for our update. The problem I mentioned in the issue is gone. However, there is still a (similar) problem behavior is still not intuitive. I think space should not match accept suggestions.

Suppose you have a following situation:

$ vim f|
fasd/

image

Pressing <space> accepts the suggestion, making the prompt like

$ vim fasd |
(Suggestions)

Well, one would have wanted 'vim f g h'. Suggestion should be accepted only when <TAB> is pressed IMHO.

Also, should also work similar to the 'longest' behavior as in vim's completeopt -- i.e. only insert the longest common text of the matches.

Given:

❯❯❯ vim zlo|
zlogin   zlogout        

Pressing <TAB> matches zlogin (the first match), not zlog. Note that this is the zsh's default tab completion behavior. --> UPDATE: This was reported also in #10.

@Dwight-D
Copy link

Dwight-D commented May 6, 2020

Seconding the request for removal of this feature. So far I have found magic space to render my terminal more or less unusable as it will often insert inappropriate suggestions. It's also quite difficult to turn off with the recent update.

@weilbith
Copy link

weilbith commented May 6, 2020

Yes, maybe it would be nice to configure some behavior of this plugin. Accepting the "best match" automatically with space is very aggressive. There will be always a special case where the completion could be wrong. Especially when constructing awkward and super special chain commands. 😆

@weilbith
Copy link

weilbith commented May 6, 2020

@weilbith I don't use vim, so I have no idea what you're talking about there. Can you try to explain it in more detail?

noinsert: while looping through the suggestion list don't insert the current entry automatically but the user must manually confirm/select the candidate.

noselect: if the suggestion list pops up, don't automatically select the first entry, but let the user himself decide to use the completion

@marlonrichert
Copy link
Owner

This one is very tricky to solve. Believe me, I have tried. Would one of you want to try your hand at it? I welcome all pull requests! 🙂

@wookayin
Copy link
Author

wookayin commented May 6, 2020

Can we just simply disable space? There is no much value I think this magic-space adds.

@weilbith
Copy link

weilbith commented May 6, 2020

I'll go for customizing the keybindings anyways. So I'll need to unbind default bindings and add my own ones after this plugin got loaded. I would be also fine to just get the widgets and do the binding myself. But I understand that without any binding this plugin is useless. So to make it work out of the box they are necessary. I think this is a critical decision for every plugin. Some allow to configure an option to disable default bindings. The advantage is that I must not care about the source order. Having this automated bindkeys I must make sure that my own bindings using the same keys/trigger get defined afterwards.

marlonrichert added a commit that referenced this issue May 6, 2020
marlonrichert added a commit that referenced this issue May 6, 2020
@marlonrichert
Copy link
Owner

@wookayin @weilbith @Dwight-D I really don't want to give up on magic-space just yet. I just pushed in a new fix that makes all of the above disappear for me. Please git pull, try it out and let me know if it works for you, too. 🙂

@nisavid
Copy link

nisavid commented May 9, 2020

Thank you for looking into this, @marlonrichert. In my usage, I have indeed noticed some improvements to the magic-space behavior after your recent changes. However, I'm still seeing some cases in which it has issues. Below, I will give the two most recent problems that I encountered, and I'll post additional comments if I find others.

tar xf̭spacetar xfv ̭

After typing tar xf̭, there is one available completion, v. Pressing space auto-inserts v. Considering the unlikelihood that the omission of v was an accident, this should not happen. In this particular scenario, the auto-insertion is annoying but probably harmless, but there are surely other cases that follow this pattern where the corresponding auto-insertion significantly changes the effect of the command.

foo() { ((̭ }spacefoo() { (( } ̭

When defining an inline function, I often type the closing brace before the body, then move the cursor back to fill in the body. When any simple command (i.e. command, sublist, or pipeline component) within the body starts with (( (to begin an arithmetic expression), pressing space causes the cursor to skip past the function's closing brace before inserting the space character. There is no scenario in which this behavior is intended.

@nisavid
Copy link

nisavid commented May 9, 2020

Here's another problematic case.

print a̭ spaceprint a-long-file-name ̭

If the working directory contains (if I understand correctly) any file that starts with the letter a (such as a-long-file-name, per the title above), then after typing print a, pressing space will auto-complete the first such file name before inserting the space character. This behavior would be reasonable if it followed Zsh's rules for spelling correction—for example, if one had typed a-long-file-nm and had set the max-errors style to 2 (or greater). However, this scenario does not fall under spelling correction. It is unclear to me why a is auto-completed to a-long-file-name, and I suspect that no user—not I, anyway—would desire this behavior.

@marlonrichert
Copy link
Owner

@nisavid Thanks for the very detailed reports! 👏🏽

I will investigate what is the best way to fix this and of course notify this thread when I’ve pushed in a fix.

@Mallchad
Copy link

I haven't used this plugin much yet, I like it very much already.
But I have found simply commenting out
bindkey ' ' magic-space
to be good enough for me. I don't like fully automatic completion it throws me off.
I think it would be nice to have a single variable to disable this.

@marlonrichert
Copy link
Owner

marlonrichert commented May 11, 2020

@wookayin

Also, should also work similar to the 'longest' behavior as in vim's completeopt -- i.e. only insert the longest common text of the matches.

Given:

❯❯❯ vim zlo|
zlogin zlogout
Pressing matches zlogin (the first match), not zlog. Note that this is the zsh's default tab completion behavior.

With the input above, just type i and press Tab to get zlogin or type o and Tab to get zlogout. Especially for large listings, that's much faster than endlessly tabbing around. zsh-autocomplete is set up to match much more than just the beginning of the word or consecutive characters. You can type almost any of characters in the word you're looking for, as long as they are in the right order. So, if you have several matches to pick from, just try typing the next letter that they don't have in common. 🙂

Also, don't forget you can use the arrow keys in the completion menu. That, too, is often faster than tabbing around. (If you have fzf installed, zsh-autocomplete is auto-configured to let you open the menu with the Down arrow key.)

marlonrichert added a commit that referenced this issue May 11, 2020
marlonrichert added a commit that referenced this issue May 11, 2020
@marlonrichert
Copy link
Owner

marlonrichert commented May 11, 2020

@nisavid @wookayin @weilbith @Dwight-D All right, I've pushed in a fix. Rather than my previous approach of trying to check what not to correct, I've decided to use a whitelist of things that are safe to correct instead. With that, all of the cases you've listed above now pass, plus some more. Please give it a try. 🙂

Oh, and you can turn it off completely by adding the following to your .zshrc after sourcing zsh-autocomplete:

zstyle ':completion:correct-word:*' tag-order '-'

@marlonrichert
Copy link
Owner

Closing this now. Please let me know if it needs to be reopened.

@marlonrichert
Copy link
Owner

Well, gosh darn, I just discovered that zstyle ':completion:correct-word:*' tag-order '-' does not completely disable autocorrection, plus I found that there are still some cases for which autocorrection works incorrectly. 🙁 I'll have to investigate further on how to solve this.

@marlonrichert marlonrichert reopened this May 13, 2020
marlonrichert added a commit that referenced this issue May 14, 2020
@marlonrichert
Copy link
Owner

marlonrichert commented May 14, 2020

@nisavid @wookayin @weilbith @Dwight-D @Mallchad I just pushed in a major rewrite that hopefully fixes things once and for all. 😅

When you press Space, correction now works as follows:

  1. Don't correct anything if…
    • …the word we're on can be expanded,
    • …completion offers an exact match.
    • …we're on an option.
  2. If there is only one possible correction, insert it immediately.
  3. If there are multiple corrections, pop up a menu with corrections plus what you actually typed, always as the last option.
    • This means that if the correction menu pops up, you can always press Arrow Up + Enter to revert the correction.
    • Works with all the normal completion menu key bindings (except Shift-Tab).

Plus:

  • On the command line, press Undo (^_ in Zsh by default) to revert the correction without removing the space you just inserted! 😃
  • In the corrections menu, press Undo once to close the menu, then Undo again to revert the correction.

Finally, to disable correction completely, add this to your .zshrc (after sourcing zsh-autocomplete):

zstyle ':completion:correct-word:*' max-errors 0

Or you can set max-errors to 1 to try stricter correction. (The default is 2.)

Hopefully, we can close this is issue now. 😁

@Mallchad
Copy link

Mallchad commented May 14, 2020

Feels pretty fantastic so far. Nearly every feels just as it should be.
Thank you.
There's just one more problem that I think was mentioned in issue #17
It still lags sometimes. This is most notable when you try to type a path on it's own.
(For executing files directly and searching for files with changing the working directory)
image
This is what is shows when I try to do so.
It feels a bit better then before now, before it would nearly lock when I typed a path.

@marlonrichert
Copy link
Owner

OK, I can reproduce that. It seems to occur only when using AUTO_CD.

But it's not related to this particular issue, so let's continue the discussion at #17, @Mallchad. 🙂

@marlonrichert
Copy link
Owner

marlonrichert commented May 15, 2020

I noticed a couple more edge cases where magic-space wasn't functioning correctly, so I pushed in another fix.

@marlonrichert
Copy link
Owner

Since I haven't heard any complaints anymore, I'm guessing this is fine now. Closing.

@marlonrichert
Copy link
Owner

@nisavid @wookayin @weilbith @Dwight-D @Mallchad
I just wanted to let you know that 7256aeb adds a new way to configure magic-space. Please see the Readme.

@marlonrichert marlonrichert added the bug Something isn't working label Mar 8, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants