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

Feature request: (z)-like flags needed for syntax-highlighting

(z) doesn't parse interiors of $(...) command substitution. Also, it
doesn't separate $() from preceding word, e.g. $var$(echo test) will
be returned as single token.

Fast-syntax-highlighting does highlight $(), however with a faulty
glob. This makes all this very much reality-driven, and it leads to a
conclusion: a flag that will extract $( ) is needed, so that
syntax-highlighting code can call itself recursively on it.

~ buf='echo $(ls -1) str $(ls -a)'
~ local -a inputs=( "${(Z+x+)buf}" )
~ print -rl -- $inputs
8:ls -1
21:ls -a

Above presents how the new flag should work. It should return offset
where $() body begins, and the body. This allows to call
syntax-highlighting recursively like this (FSH code):

for el in $inputs; do
  -fast-process $PREBUFFER  "${el#*:}"  $(( ${el%%:*} - 1 ))

This is a nice piece of code, which starts syntax-highlighting from
given place – ${el%%:*} - 1, on a short buffer ${el#*:}, causing to an
overlay of highlighting to be generated for the whole $buf. FSH does
this currently but with faulty glob – no way to properly handle \\\)
and other quoting of closing ")".

The reality-driven aspect is important, it would be hard to come up
with this by doing abstract thinking. I think ZSH should be interested
in making a beautiful, correct syntax highlighting. Check out how it
looks like when $() is colorized with different theme than the rest of


Best regards,
Sebastian Gniazdowski

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