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

Re: Match paren



Hi,

2013/8/16 shawn wilson <ag4ve.us@xxxxxxxxx>:
> Has anyone made a script or omz plugin that visually highlights
> matching parens, brackets, and curleys? I know this is being done
> somehow as % works to move between them. However, I'd like to see the
> match when I hover over it.

The following code highlights the matching symbols when you type them.
Unless I'm mistaken, it was originally written by Oliver Kiddle.

function highlight-paren()
{
    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=()
}
zle -N highlight-paren

Best regards,

-- 
Jérémie



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