Tuesday, July 3, 2012

Re: synIDattr used with matchadd

On 03/07/12 01:21, richard emberson wrote:
> If I use the matchadd function to highlight a region
> given a pattern which is based upon a region,
> can I use the id returned by matchadd with the
> function synIDattr get get the "fg" and "bg" colors
> associated with the highlight group used?
> Or, can synIDattr only be used with ids associated with
> syntax groups?
>
> I tried and 1) it returned different values on subsequent
> runs and 2) I have a 256 color term but it returns only
> values between 0 and 15.
>
> Thanks
>
> Richard
>

synIDattr() needs as its first argument a syntax ID. matchadd() gives
you a match ID. They are not the same and cannot be used
interchangeably. The recommended way to obtain a synID to be plugged
into synIDattr() is by using the synID() function, optionally converted
by synIDtrans(). Or you could use the List output of synstack() and
extract the synIDs from it by means of a little fancy footwork.

You have a 256-color term but have you got a 256-color colorscheme and a
Vim that knows about it? In a GUI-enabled Vim for Linux running in
console mode in a 256-color xterm with the CSApprox plugin, I get fg=201
bg=-1 for the helpHyperTextEntry group.

I used the following to determine values at the cursor:

:echomsg "fg=" . synIDattr(synIDtrans(synID(line("."), col("."), 0)),
"fg", "cterm") "bg=" . synIDattr(synIDtrans(synID(line("."), col("."),
0)), "bg", "cterm")

It is one single long ex-command.


Best regards,
Tony.
--
Q: How many Zen masters does it take to screw in a light bulb?
A: None. The Universe spins the bulb, and the Zen master stays out
of the way.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment