Merge pull request #11 from dreadatour/master

Add plugin config variables
This commit is contained in:
tarruda 2013-12-04 15:31:36 -08:00
commit a29e838cdf
2 changed files with 19 additions and 10 deletions

View file

@ -29,7 +29,7 @@ this:
```sh ```sh
# Accept suggestions without leaving insert mode # Accept suggestions without leaving insert mode
bindkey '^f' vi-forward-word bindkey '^f' vi-forward-word
# or # or
bindkey '^f' vi-forward-blank-word bindkey '^f' vi-forward-blank-word
``` ```
@ -37,3 +37,10 @@ Emacs-mode users can simply use alt+f which is bound to forward-word
The [zsh-history-substring-search](https://github.com/zsh-users/zsh-history-substring-search) The [zsh-history-substring-search](https://github.com/zsh-users/zsh-history-substring-search)
plugin is also recommended. plugin is also recommended.
## Configuration
You may override default global config variables after plugin load.
- `AUTOSUGGESTION_HIGHLIGHT_COLOR`: suggestion highlight color, default is `'fg=8'`.
- `AUTOSUGGESTION_HIGHLIGHT_CURSOR`: highlight word after cursor or not. Must be integer value `1` or `0`, default is `1`.

View file

@ -1,5 +1,5 @@
# Fish-like autosuggestions for zsh. Some of the code was based on the code # Fish-like autosuggestions for zsh. Some of the code was based on the code
# for 'predict-on' # for 'predict-on'
# #
# ```zsh # ```zsh
# zle-line-init() { # zle-line-init() {
@ -11,6 +11,10 @@ zmodload zsh/net/socket
source "${0:a:h}/completion-client.zsh" source "${0:a:h}/completion-client.zsh"
# configuration variables
AUTOSUGGESTION_HIGHLIGHT_COLOR='fg=8'
AUTOSUGGESTION_HIGHLIGHT_CURSOR=1
function { function {
if [[ -n $ZLE_DISABLE_AUTOSUGGEST ]]; then if [[ -n $ZLE_DISABLE_AUTOSUGGEST ]]; then
ZSH_HIGHLIGHT_HIGHLIGHTERS=() ZSH_HIGHLIGHT_HIGHLIGHTERS=()
@ -26,6 +30,7 @@ function {
ZLE_AUTOSUGGEST_SUSPEND_WIDGETS=( ZLE_AUTOSUGGEST_SUSPEND_WIDGETS=(
vi-cmd-mode vi-backward-char backward-char backward-word beginning-of-line vi-cmd-mode vi-backward-char backward-char backward-word beginning-of-line
history-search-forward history-search-backward up-line-or-history history-search-forward history-search-backward up-line-or-history
history-beginning-search-forward history-beginning-search-backward
down-line-or-history down-line-or-history
) )
@ -68,11 +73,11 @@ autosuggest-resume() {
local widget local widget
# Replace prediction widgets by versions that will also highlight RBUFFER # Replace prediction widgets by versions that will also highlight RBUFFER
zle -A autosuggest-insert-or-space self-insert zle -A autosuggest-insert-or-space self-insert
zle -A autosuggest-insert-or-space magic-space zle -A autosuggest-insert-or-space magic-space
zle -A autosuggest-backward-delete-char backward-delete-char zle -A autosuggest-backward-delete-char backward-delete-char
zle -A autosuggest-accept-line accept-line zle -A autosuggest-accept-line accept-line
# Hook into some default widgets that should suspend autosuggestion # Hook into some default widgets that should suspend autosuggestion
# automatically # automatically
for widget in $ZLE_AUTOSUGGEST_ACCEPT_WIDGETS; do for widget in $ZLE_AUTOSUGGEST_ACCEPT_WIDGETS; do
[[ -z $widgets[$widget] ]] && continue [[ -z $widgets[$widget] ]] && continue
eval "zle -A autosuggest-accept-suggestion $widget" eval "zle -A autosuggest-accept-suggestion $widget"
@ -123,10 +128,7 @@ _zsh_highlight_autosuggest_highlighter_predicate() {
} }
_zsh_highlight_autosuggest_highlighter() { _zsh_highlight_autosuggest_highlighter() {
local color='fg=8' region_highlight+=("$(( $CURSOR + $AUTOSUGGESTION_HIGHLIGHT_CURSOR )) $(( $CURSOR + $#RBUFFER )) $AUTOSUGGESTION_HIGHLIGHT_COLOR")
[[ -n $AUTOSUGGESTION_HIGHLIGHT_COLOR ]] &&\
color=$AUTOSUGGESTION_HIGHLIGHT_COLOR
region_highlight+=("$(( $CURSOR + 1 )) $(( $CURSOR + $#RBUFFER )) $color")
} }
autosuggest-insert-or-space() { autosuggest-insert-or-space() {