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

Re: PATCH: command line highlighting



Peter wrote:

> 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

Thanks. Sorry, I see now that that is documented.

> > 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've updated from cvs, rebuilt with debug enabled, removed the
spurious "/" and tried again. This time it works. Thanks.

By the way, the documented feature that accepting a line does not save
region_highlight doesn't appear to work. For me, the variable and the
highlights are persisting.

> 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.

I had to add a call to "zle -R" so that it doesn't wait till the end of
the widget to display the highlight but otherwise, that seems to work.
An additional key typed in less than a second will remove the
highlighting but that's actually fine. I've included the full function
below in case anyone else wants to play with it: handle quoting or
forward searching perhaps.

> > 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.

Yes, that would be another solution.

Oliver

local i nested=1
typeset -A match
match=(
  \) \(
  \" \"
  \' \'
  \] \[
  \} \{
)
zle self-insert
for ((i=$(( $CURSOR - 1));i;i--)) {
  [[ $BUFFER[$i] = $match[$KEYS] ]] && (( ! --nested )) && break
  [[ $BUFFER[$i] == $KEYS ]] && (( nested++ ))
}
region_highlight=("$((i-1)) $i standout")
zle -R
read -kt 1 && zle -U "$REPLY"
region_highlight=()



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