Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: $ZLE_LINE_ABORTED



On 7 September 2010 16:51, Greg Klanderman <gak@xxxxxxxxxxxxxx> wrote:
>
> Wow that was fast!  Seems to be working here, will continue to play
> with it..

I played with it a bit now, and came up with this

#the intent here is to insert syntax errors back on the command line, since
#those aren't saved in history, for example entering "do;"
function _zle_line_init() {
  if [[ -n $ZLE_LINE_SAVED && $ZLE_LINE_SAVED[1] != " " &&
$ZLE_LINE_SAVED != $history[$((HISTCMD-1))] ]]; then
    LBUFFER=$ZLE_LINE_SAVED
    zle -R
  fi
  unset ZLE_LINE_SAVED
}

#like pws said, if we accept a line, we don't need the aborted one anymore
function _zle_line_finish() {
  ZLE_LINE_SAVED=$BUFFER
  unset ZLE_LINE_ABORTED
}


#this puts back the aborted line when you try to go up history, can be
bound to other
#things too but haven't got around to that yet (ie up-line-or-search).
should probably
#also check the current line is empty first too.
function _recover_line_or_else() {
  if [[ -n $ZLE_LINE_SAVED ]]; then
    LBUFFER+=$ZLE_LINE_SAVED
    unset ZLE_LINE_SAVED
  elif [[ -n $ZLE_LINE_ABORTED ]]; then
    LBUFFER+=$ZLE_LINE_ABORTED
    unset ZLE_LINE_ABORTED
  else
    zle .$WIDGET
  fi
}
zle -N up-history _recover_line_or_else

-- 
Mikael Magnusson



Messages sorted by: Reverse Date, Date, Thread, Author