Cleanup #91

Merged
merged 1 commit into from Feb 7, 2016

6 participants

@ericfreese
zsh-users member

Already pulled ericfreese/zsh-autosuggestions#rewrite into tarruda repo as v0.1.x branch so that it is available via antigen bundle tarruda/zsh-autosuggestions --branch=v0.1.x zsh-autosuggestions.zsh.

This PR is for merging v0.1.x into master.

See PR #87 for history.

Fixes/changes:

  • Works with zsh-syntax-highlighting plugin.
  • Works with zsh-history-substring-search plugin (with a little extra config).
  • Works with multi-line commands.
  • Works with tab completion.
  • Fixes a lot of bugs by using POSTDISPLAY instead of LBUFFER/RBUFFER and removing pause/suspend/resume state management code.
  • Removes unused server/client code.

Deprecations:

Note that installation instructions have changed slightly
Please check out the readme in the v0.1.x branch for more info.

  1. No more zle-line-init. Just call autosuggest_start somewhere in your .zshrc after you source the plugin (and after you source zsh-syntax-highlighting, if you are using it):

    autosuggest_start
    
  2. The config variables have changed:

    AUTOSUGGESTION_HIGHLIGHT_COLOR has become ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE, and the other options have been removed.

Old configurations will function for now, but will display deprecation warnings.

To use this:

  • Install the v0.1.x branch with antigen
    • antigen bundle tarruda/zsh-autosuggestions --branch=v0.1.x zsh-autosuggestions.zsh

OR

  • Install manually
    • git clone -b v0.1.x https://github.com/tarruda/zsh-autosuggestions.git ~/.zsh/zsh-autosuggestions

and source as described in the readme.

TODO

  • #96
  • Make old zle autosuggest-start init and AUTOSUGGESTION_HIGHLIGHT_COLOR work with deprecation warnings.
  • end-of-line widget should accept the autosuggestion, regardless of where in the buffer the cursor is.
  • Warn users about using zle-line-init (re: #101)

Nice-to-haves

  • #95
  • Make it work w/ zsh v5.0.x
  • Add config option to enable partially accepting autosuggestion, so forward-char accepts just one character, forward-word accepts just one word, etc. (#93)
@wernight

What about having:

# Enable autosuggestions
zle-line-init() {
    autosuggest_start
}

zle -N zle-line-init

as

# Enable autosuggestions
autosuggest_start

To avoid such breaking change in the future?

@ericfreese
zsh-users member

I thought about this, but ultimately decided against it. I believe the original purpose of the more verbose zle-line-init definition was to allow more flexibility in case you wanted to add more plugins or other functions to your zle-line-init. For example:

# Enable autosuggestions
zle-line-init() {
    another_thing_start
    autosuggest_start
    some_other_plugin_start
    ...
}

zle -N zle-line-init
@hcgraf

I'm sorry, branch v0.1.x it seems broken for me…

  1. I don't get any autosuggestions, without warnings or errors
  2. The cursor disappears randomly, e.g. if I type "c" it disappears, typing "d" in appears again, with "space" it disappears for a few letters, and so on…
  3. The highlighting of other plugins is broken (history-substring-search again), however the syntax-highlighting plugin seems to work

BTW, for the zle-line-init, there is a plugin which provides such widgets as hooks: https://github.com/willghatch/zsh-hooks
This allows multiple plugins to extend those widgets.

@ericfreese
zsh-users member

I don't get any autosuggestions, without warnings or errors

The cursor disappears randomly, e.g. if I type "c" it disappears, typing "d" in appears again, with "space" it disappears for a few letters, and so on…

The highlighting of other plugins is broken (history-substring-search again), however the syntax-highlighting plugin seems to work

Well that's no good.

Can you open a separate issue with more information:

  • what does your .zshrc look like?
  • what other plugins are you using?
  • what version of zsh?
  • what operating system?
  • a screenshot or gif/movie showing the problem would be great

As far as hooking built-in widgets goes, I did end up moving away from aliasing the dot-prefixed ones. It is a little bit less stable (introduces a possibility of triggering infinite recursion), but there was an issue getting autocompletions to work that was easily fixed by doing so.

@faceleg

Wow this looks awesome

@george-b

I have been using the v0.1.x branch for the last week or so without issue 👍

@faceleg

@ericfreese can we merge?

@wernight

I have some issues that I reported. It's better but not yet great.

For one, is the zsh-autosuggestions.plugin.zsh used to work and now doesn't. Another issue is reported in #90.

@faceleg

So #90 isn't fixed?

@wernight

@faceleg No, see my comment, there is too much auto-complete and it's a very frequent use case.

@ericfreese
zsh-users member

I'm going to go ahead and merge this tonight.

@ericfreese ericfreese merged commit 3449ae5 into master Feb 7, 2016
@sorin-ionescu
zsh-users member

In order to integrate zsh-autosuggestions into Prezto, I have to added the following to modules/autosuggestions/init.zsh.

if zstyle -t ':prezto:module:history-substring-search' loaded; then
  ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(
    history-substring-search-up
    history-substring-search-down
  )
fi

In my testing, I have observed that the if statement is unnecessary because adding those widgets to the array, even when zsh-history-substring-search is not sourced, causes no errors. So, why not add the widgets directly to https://github.com/zsh-users/zsh-autosuggestions/blob/master/src/config.zsh#L15 and excuse the user from having to do it?

@ericfreese
zsh-users member

why not add the widgets directly

The idea was to avoid as much as possible supporting other plugins inside of this plugin, since it generally leads to bloat in the code. In this case though, I've gone ahead and added those widgets to the default configuration in v0.2.17, since the change is pretty minimal, and like you said, it doesn't cause any errors.

@sorin-ionescu
zsh-users member

The following should be enough to integrate zsh-autosuggestions into Prezto.

pmodload 'editor'

source "${0:h}/external/zsh-autosuggestions.zsh" || return 1

zstyle -s ':prezto:module:autosuggestions:color' found \
  'ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE' || ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=8'

if ! zstyle -t ':prezto:module:autosuggestions' color; then
  ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE=''
fi

if [[ -n "$key_info" ]]; then
  bindkey -M viins "$key_info[Control]F" vi-forward-word
  bindkey -M viins "$key_info[Control]E" vi-add-eol
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment