It's been a while, but my clumsy adding of a comment to the buffer is unnecessary, given zle -M
, which will display a message outside of the buffer. So here's an updated version:
# -- Run input if single line, otherwise insert newline --
# Key: enter
# Credit: https://programming.dev/comment/2479198
.zle_accept-except-multiline () {
if [[ $BUFFER != *$'\n'* ]] {
zle .accept-line
return
} else {
zle .self-insert-unmeta
zle -M 'Use alt+enter to submit this multiline input'
}
}
zle -N .zle_accept-except-multiline
bindkey '^M' .zle_accept-except-multiline # Enter
# -- Run input if multiline, otherwise insert newline --
# Key: alt+enter
# Credit: https://programming.dev/comment/2479198
.zle_accept-only-multiline () {
if [[ $BUFFER == *$'\n'* ]] {
zle .accept-line
} else {
zle .self-insert-unmeta
}
}
zle -N .zle_accept-only-multiline
bindkey '^[^M' .zle_accept-only-multiline # Enter
A bit from the readme appreciating concatenative programming:
Function composition is concatenation.
Pipelining values through functions to get new values is the most natural idiom.
Functions are applied from left to right instead of inside out.
Support for multiple return values comes for free.
No need for operator precedence.
Fewer delimiters are required: