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

Re: [tip] mouse support



On Thu, Nov 11, 2004 at 05:02:47PM -0800, Bart Schaefer wrote:
> On Thu, 11 Nov 2004, Stephane Chazelas wrote:
> 
> > zero='%([BSUbsu]|{*%})'
> > 
> > It replaces '%%some %{%{some%}%}' with '%ome %}' instead of
> > '%%some '
> 
> Hmm.  To fix that, you need extended globbing:
> 
> setopt extendedglob
> zero='(#b)([^%]|(#s))%([BSUbsu]|{*%})'
> print ${(%%)PS1//$~zero/$match[1]}
[...]

That moves the problem (the first one)

ow, there's a problem with '%%%S'

A better fix:

zero='(#b)(%([BSUbsu]|{*%})|(%[^BSUbsu{}]))'
print ${(S%%)PS1//$~zero/$match[3]}

But, it still doesn't fix the problem of nested %{ (maybe not
too big an issue, as I can't think of any case where nesting
%{'s can be useful).

> On Thu, 11 Nov 2004, Stephane Chazelas wrote:
> 
> > Well the (%%) expansion flag has another problem:
> > 
> > var='%Sfoo%s'
> > PS1='$var'
> > 
> > In that case, you need to expand first the variables in PS1 or
> > you'll miss the %S %s visual sequences.
> 
> That's easy enough:
> 
> if [[ -o promptsubst ]]
> then print ${(%%)${(e)PS1}//$~zero/$match[1]}
> else print ${(%%)PS1//$~zero/$match[1]}
> fi

Yes, that was what I did. Except that I used (%) instead of
(%%). But with (%%) PS1 may be expanded again (PS1='$(echo "\$foo")')

So a refined solution could be:

    local cur_prompt
    if [[ -n $PREBUFFER ]]; then
      cur_prompt=$PS2
      # decide wether we're at the PS2 or PS1 prompt
    else
      cur_prompt=$PS1
    fi

    [[ -o promptsubst ]] && cur_prompt=${${(e)cur_prompt}//(#b)([\\\$\`])/\\$match}

    # restore the exit status in case $PS<n> relies on it
    set-status $last_status
    cur_prompt=${(S%%)cur_prompt//(#b)(%([BSUbsu]|{*%})|(%[^BSUbsu{}]))/$match[3]}


what do you think?

-- 
Stéphane



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