Browse Source

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

Refs #1533, #1534
master
Kaleb Elwert 7 years ago
parent
commit
6ac2c05f27
  1. 22
      modules/editor/init.zsh

22
modules/editor/init.zsh

@ -241,6 +241,24 @@ function glob-alias { @@ -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 @@ -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
#

Loading…
Cancel
Save