mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2024-11-18 09:51:06 +01:00
Integrate with zsh-syntax-highlighting
This commit is contained in:
parent
936056fd9b
commit
7cb87a8a55
1 changed files with 42 additions and 11 deletions
|
@ -12,7 +12,10 @@ zmodload zsh/net/socket
|
||||||
source "${0:a:h}/completion-client.zsh"
|
source "${0:a:h}/completion-client.zsh"
|
||||||
|
|
||||||
function {
|
function {
|
||||||
[[ -n $ZLE_DISABLE_AUTOSUGGEST ]] && return
|
if [[ -n $ZLE_DISABLE_AUTOSUGGEST ]]; then
|
||||||
|
ZSH_HIGHLIGHT_HIGHLIGHTERS=()
|
||||||
|
return
|
||||||
|
fi
|
||||||
autoload -U is-at-least
|
autoload -U is-at-least
|
||||||
|
|
||||||
if is-at-least 5.0.3; then
|
if is-at-least 5.0.3; then
|
||||||
|
@ -84,6 +87,9 @@ autosuggest-resume() {
|
||||||
}
|
}
|
||||||
|
|
||||||
autosuggest-start() {
|
autosuggest-start() {
|
||||||
|
if [[ -z $ZLE_DISABLE_AUTOSUGGEST && -n $functions[_zsh_highlight] ]]; then
|
||||||
|
ZSH_HIGHLIGHT_HIGHLIGHTERS+=(autosuggest)
|
||||||
|
fi
|
||||||
autosuggest-resume
|
autosuggest-resume
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,16 +104,25 @@ autosuggest-toggle() {
|
||||||
}
|
}
|
||||||
|
|
||||||
autosuggest-highlight-suggested-text() {
|
autosuggest-highlight-suggested-text() {
|
||||||
if [[ -n $ZLE_AUTOSUGGESTING ]]; then
|
if (( $+functions[_zsh_highlight_buffer_modified] > 0 )); then
|
||||||
local color='fg=8'
|
_zsh_highlight
|
||||||
[[ -n $AUTOSUGGESTION_HIGHLIGHT_COLOR ]] &&\
|
|
||||||
color=$AUTOSUGGESTION_HIGHLIGHT_COLOR
|
|
||||||
region_highlight=("$(( $CURSOR + 1 )) $(( $CURSOR + $#RBUFFER )) $color")
|
|
||||||
else
|
else
|
||||||
region_highlight=()
|
region_highlight=()
|
||||||
|
_zsh_highlight_autosuggest_highlighter
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_zsh_highlight_autosuggest_highlighter_predicate() {
|
||||||
|
[[ -n $ZLE_AUTOSUGGESTING ]] && (( $#RBUFFER > 0 ))
|
||||||
|
}
|
||||||
|
|
||||||
|
_zsh_highlight_autosuggest_highlighter() {
|
||||||
|
local color='fg=8'
|
||||||
|
[[ -n $AUTOSUGGESTION_HIGHLIGHT_COLOR ]] &&\
|
||||||
|
color=$AUTOSUGGESTION_HIGHLIGHT_COLOR
|
||||||
|
region_highlight+=("$(( $CURSOR + 1 )) $(( $CURSOR + $#RBUFFER )) $color")
|
||||||
|
}
|
||||||
|
|
||||||
autosuggest-insert-or-space() {
|
autosuggest-insert-or-space() {
|
||||||
setopt localoptions noshwordsplit noksharrays
|
setopt localoptions noshwordsplit noksharrays
|
||||||
if [[ $LBUFFER == *$'\012'* ]] || (( PENDING )); then
|
if [[ $LBUFFER == *$'\012'* ]] || (( PENDING )); then
|
||||||
|
@ -119,6 +134,7 @@ autosuggest-insert-or-space() {
|
||||||
if [[ ${RBUFFER[1]} == ${KEYS[-1]} ]]; then
|
if [[ ${RBUFFER[1]} == ${KEYS[-1]} ]]; then
|
||||||
# Same as what's typed, just move on
|
# Same as what's typed, just move on
|
||||||
((++CURSOR))
|
((++CURSOR))
|
||||||
|
autosuggest-invalidate-highlight-cache
|
||||||
else
|
else
|
||||||
LBUFFER="$LBUFFER$KEYS"
|
LBUFFER="$LBUFFER$KEYS"
|
||||||
if [[ $LASTWIDGET == (self-insert|magic-space|backward-delete-char) || $LASTWIDGET == (complete-word|accept-*|zle-line-init) ]]; then
|
if [[ $LASTWIDGET == (self-insert|magic-space|backward-delete-char) || $LASTWIDGET == (complete-word|accept-*|zle-line-init) ]]; then
|
||||||
|
@ -140,6 +156,7 @@ autosuggest-backward-delete-char() {
|
||||||
LBUFFER="$LBUFFER[1,-2]"
|
LBUFFER="$LBUFFER[1,-2]"
|
||||||
else
|
else
|
||||||
((--CURSOR))
|
((--CURSOR))
|
||||||
|
autosuggest-invalidate-highlight-cache
|
||||||
zle .history-beginning-search-forward || RBUFFER=''
|
zle .history-beginning-search-forward || RBUFFER=''
|
||||||
fi
|
fi
|
||||||
autosuggest-highlight-suggested-text
|
autosuggest-highlight-suggested-text
|
||||||
|
@ -152,7 +169,10 @@ autosuggest-backward-delete-char() {
|
||||||
# section when the user accepts the line
|
# section when the user accepts the line
|
||||||
autosuggest-accept-line() {
|
autosuggest-accept-line() {
|
||||||
RBUFFER=''
|
RBUFFER=''
|
||||||
region_highlight=()
|
if (( $+functions[_zsh_highlight_buffer_modified] > 0 )); then
|
||||||
|
# Only clear the colors if the user doesn't have zsh-highlight installed
|
||||||
|
region_highlight=()
|
||||||
|
fi
|
||||||
zle .accept-line
|
zle .accept-line
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,13 +226,24 @@ autosuggest-tab() {
|
||||||
}
|
}
|
||||||
|
|
||||||
autosuggest-accept-suggested-small-word() {
|
autosuggest-accept-suggested-small-word() {
|
||||||
zle .vi-forward-word
|
if [[ -n $ZLE_AUTOSUGGESTING ]]; then
|
||||||
autosuggest-highlight-suggested-text
|
zle .vi-forward-word
|
||||||
|
autosuggest-invalidate-highlight-cache
|
||||||
|
autosuggest-highlight-suggested-text
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
autosuggest-accept-suggested-word() {
|
autosuggest-accept-suggested-word() {
|
||||||
zle .forward-word
|
if [[ -n $ZLE_AUTOSUGGESTING ]]; then
|
||||||
autosuggest-highlight-suggested-text
|
zle .forward-word
|
||||||
|
autosuggest-invalidate-highlight-cache
|
||||||
|
autosuggest-highlight-suggested-text
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
autosuggest-invalidate-highlight-cache() {
|
||||||
|
# invalidate the buffer for zsh-syntax-highlighting
|
||||||
|
_ZSH_HIGHLIGHT_PRIOR_BUFFER=''
|
||||||
}
|
}
|
||||||
|
|
||||||
zle -N autosuggest-toggle
|
zle -N autosuggest-toggle
|
||||||
|
|
Loading…
Reference in a new issue