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

Re: zsh-no-ps2: A plugin that inserts a newline on Enter instead of displaying PS2



On Mon, Nov 13, 2023 at 8:29 AM Stephane Chazelas <stephane@xxxxxxxxxxxx> wrote:
>
> On 2023-11-12 13:48, Roman Perepelitsa wrote:
> > tl;dr: zsh-no-ps2 changes the behavior of Enter key to insert a
> > newline instead of going into PS2
> [...]
>
> I remember offering something similar at
> https://unix.stackexchange.com/questions/750378/disabling-the-secondary-prompt-in-zsh/750481#750481
> not so long ago (you might want to offer your plugin as an alternative
> answer there).

Thanks for the link. I've posted my own answer there.

There are two differences in my code compared to yours. Firstly, my
code looks at $PREBUFFER$BUFFER rather than just $BUFFER. This makes a
difference if you end up in PS2 for some reason, perhaps
intentionally.  I think it's worth editing your answer to fix this.
Secondly, my code works as expected when the buffer is "for x" or
"<<END", while yours ends up in PS2. The fix is rather hacky: append
$'\ndo\ndone' and see if that parses. It's possible that there are
other corner cases which this hack does not cover. I'll be very
interested to know about them if you find any.

My function that detects whether a piece of code is well-formed can be
found here: https://github.com/romkatv/zsh4humans/blob/v5/fn/-z4h-is-valid-list

> > The drawback to skipping PS2 is that you don't get the helpful hints
> > about where you are in the syntax tree (by having %_ in the value of
> > PS2 or RPS2), but as Roman notes in his README.md, you can get back to
> > that by forcing an accept-line.
>
> Another widget that returns the state of the parser after reading what's
> left of the cursor?

Or perhaps something more generic: an actual parser, which gives you
an AST. This would do all the heavy lifting required for implementing
a syntax highlighter and a multitude of other features.

Roman.




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