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

Re: ZLE: missing edit-buffer widget



On Aug 23, 10:35pm, rooom wrote:
}
} I'm looking for widget "edit-line" or "edit-buffer" which move entire
} command line into editor buffer regardless if it is single line or 
} multi-line construct.

Look at the edit-command-line function in the distribution (probably
findable with   print -R $^fpath/edit-command-line(N)  )

You want to do what that does, except skip invoking the editor on a
file.  So something like:

    print -Rz - "$PREBUFFER$BUFFER"
    zle send-break

This is exactly what push-line-or-edit does except that if there is
only one line of input it skips the send-break.  (push-line-or-edit
was implemented before user-defined widgets were available.)

You could also write a little wrapper that's just a no-op if there
is only one line:

    edit-if-multi-line () {
      if [[ -n "$PREBUFFER" ]]; then
	zle .push-line-or-edit
      fi
      return 0
    }

} For some reason the simple definition doesn't work:
} 
} push-input-get-line () {
}     zle .push-input
}     zle .get-line
} }

You've discovered the reason push-line-or-edit exists.  In a multi-
line construct, the stuff entered at previous prompts (the value of
$PREBUFFER) has already passed through both the editor and the shell
parser and is only awaiting the completion of the parse to be run as
shell input.  In order to get it back and undo the parser state,
push-input has to abort the whole parser loop, so get-line never has
a chance to be executed.



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