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

Re: PATCH: command line highlighting



On Thu, 03 Apr 2008 12:30:14 +0200
Oliver Kiddle <okiddle@xxxxxxxxxxx> wrote:
> > +special array parameter tt(region_highglight); see
> 
> There's a typo there.

I'll fix that when I commit.

> Can the region and unprintable characters have a different highlight
> style? zle_highlight is an array, right? Or is that for start/end escape
> sequences.

zle_highlight is a global setting which can go in your .zshrc, so you can
set zle_highlight=(region:underline special:bold), or whatever.  That's why
it begins with zle_: the local special parameters in widgets are only
special there so don't have it.

> > - arbitrary chunks of the line:  controlled by the (zle special) array
> >   region_highlight.  This is limited to static uses at the moment;
> >   highlighting doesn't track movement.
> 
> This is probably the part that will be expanded on if things like syntax
> highlighting will be done in shell code (completion system like).

Yes, one day it should be possible to expand this to track changes, but I
think there are areas of the code that aren't very consistent at the
moment, such as undo.  Also, I'm not sure how consistent the completion
code is in calling the right code to change the command line: mostly I
think it's OK, but there's so much of it it's hard to be sure.  So for now
it's purely static.

> As a test, I wrote a very rudimentary bracket matching widget:
>   local i
>   zle self-insert
>   for ((i=$CURSOR;i;i--)) {
>     [[ $BUFFER[$i] = '(' ]] && break
>   }
>   region_highlight=("$((i-1)) $i/ bold")
> With a zle -M command at the end of this, zsh coredumps. Let me know if
> you can't reproduce it. I observed it on Solaris 10.

I couldn't easily get this to happen (that "/" probably isn't supposed to
be there).  However, I have seen at least one crash involving widgets and
region_highlight here which comes from get_region_highlight() being
broken.  I think I'll commit what I have:  it is to be assumed that the
interface will continue to change.

> I'm not sure where and how to implement the unhighlight. Ideally, I
> would like to have the matching paren highlighted for 1 second which
> is what nedit does.

We need to be able to see if a key is read within the time and if it is
unget it and return (like sit-for in Emacs).  Something like
  read -kt 1 && zle -U $REPLY
should work, but I haven't played around with it yet.

> And how can it be sure to remove its highlight
> and not a region from some other widget.

region_highlight could be an associative array, I suppose.

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



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