Thank you for the inspiration!
I just augmented it with a trick I use to chain accept-line handlers (my own, and zsh_autosuggest):
If you read the fine print, you will see that .accept-line is the rock-bottom handler, not just anything that was bound before.
if [[ -z ${CALCPREVACCEPTLINE} ]]; then
# only do this once, even if the file is sourced multiple times
function quote_expression() {
if [[ ${BUFFER} =~ ^=.* ]]; then
# used below in history hack
typeset -g calc_expr="${BUFFER}"
# add quotes
BUFFER="= ${(q-)${${BUFFER#=}# }}"
fi
if [[ -z ${CALCPREVACCEPTLINE} ]]; then
# bail out
zle .accept-line
else
# up the chain
"${CALCPREVACCEPTLINE}" "${@}"
fi
}
# save the original accept-line widget, so we can call it from our wrapper
CALCPREVACCEPTLINE=${widgets[accept-line]#*:}
zle -N accept-line quote_expression
fi
Kind regards, erik.