Add pound-toggle zle widget to work around the buggy built-in pound-insert

Refs #1533, #1534
This commit is contained in:
Kaleb Elwert 2018-01-26 14:52:11 -08:00
parent 906ac99e20
commit 904eef5fa5

View file

@ -241,6 +241,24 @@ function glob-alias {
}
zle -N glob-alias
# Toggle the comment character at the start of the line. This is meant to work
# around a buggy implementation of pound-insert in zsh.
function pound-toggle {
if [[ "$BUFFER" = '#'* ]]; then
# Because of an oddity in how zsh handles the cursor when the buffer size
# changes, we need to make this check before we modify the buffer and let
# zsh handle moving the cursor back if it's past the end of the line.
if [[ $CURSOR != $#BUFFER ]]; then
(( CURSOR -= 1 ))
fi
BUFFER="${BUFFER:1}"
else
BUFFER="#$BUFFER"
(( CURSOR += 1 ))
fi
}
zle -N pound-toggle
# Reset to default key bindings.
bindkey -d
@ -276,6 +294,10 @@ if (( $+widgets[history-incremental-pattern-search-backward] )); then
history-incremental-pattern-search-forward
fi
# Toggle comment at the start of the line.
bindkey -M emacs "$key_info[Escape];" pound-toggle
#
# Vi Key Bindings
#