It seems that zle send-break commits to history the content of PREBUFFER  when used from PS2, does this makes sense?
I replicated it with:

echo abc\<enter>
> def<ctrl-G>

now the first item in the history is:
: 1630178520:0;E qwe\

this is wrong, due to the \ at the end of the row that will make the subsequent row treated as part of a multi-line construct but it is not, only the first line has been inserted in the history. in my case the following line in .zsh_history is:
: 1630178638:0;tail -n 1 ~/.zsh_history

if I insert more lines before pressing ctrl-g just the last one is missing:

echo ab\<enter>
> bc\<enter>
> de<ctrl-G>

tail -n 3 zsh-history
: 1630178860:0;echo ab\\
bc\
: 1630178870:0;tail -n 3 ~/.zsh_history

this may be due to my very old zsh (5.1.1)

Pier Paolo Grassi


Il giorno ven 27 ago 2021 alle ore 23:59 Bart Schaefer <schaefer@brasslantern.com> ha scritto:
On Fri, Aug 27, 2021 at 2:15 PM Pier Paolo Grassi <pierpaolog@gmail.com> wrote:
>
> the send-break widget returns a status code 1, and since I have a precmd that displays the last status code, I was wondering if it is in some way possibile to suppress that return status.

The short answer is no, there is not.  There was a long thread about
this on zsh-workers earlier this year, search "curious incident of the
feep".

As written your widget discards multi-line structures if invoked at
the PS2 prompt.  If that's intentional you can replace with:

commit_to_history() {
  print -rs -- ${(q)${(z)BUFFER}}
  BUFFER=''
  if [[ -n $PREBUFFER ]]
  then zle accept-line
  else zle send-break
  fi
}

If you would prefer to capture multi-line structure at PS2,

commit_to_history() {
  local fullbuffer="$PREBUFFER$BUFFER"
  print -rs -- ${(q)${(z)fullbuffer}}
  BUFFER=''
  if [[ -n $PREBUFFER ]]
  then zle accept-line
  else zle send-break
  fi
}