Skip to content

Commit

Permalink
feat(expansion): when expanding with spacebar, append a space
Browse files Browse the repository at this point in the history
  • Loading branch information
olets committed Jan 12, 2020
1 parent 6cc7e0c commit e5b4696
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions abbr
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,17 @@ function abbr_expand() {
local rest="${LBUFFER%%$abbreviation}"
LBUFFER="$rest$expansion"
fi

zle self-insert
fi
} always {
unfunction -m "abbr_get_expansion"
}
}

function abbr_expand_space() {
abbr_expand
LBUFFER="$LBUFFER "
}

if [ -f "$ABBR_UNIVERSALS_SOURCE" ]; then
while read -r k v; do ABBRS[$k]="$v"; done < "$ABBR_UNIVERSALS_SOURCE"
fi
Expand All @@ -69,12 +72,17 @@ mktemp "$TMPDIR"/abbr_universals 1> /dev/null

typeset -p ABBRS > "$TMPDIR"/abbr_universals

zle -N abbr_expand
# spacebar expands abbreviations
zle -N abbr_expand_space
bindkey " " abbr_expand_space

bindkey " " abbr_expand
# control-spacebar is a normal space
bindkey "^ " magic-space

# when running an incremental search,
# spacebar behaves normally and control-space expands abbreviations
bindkey -M isearch "^ " abbr_expand_space
bindkey -M isearch " " magic-space
bindkey -M isearch "^ " abbr_expand



Expand Down

0 comments on commit e5b4696

Please sign in to comment.