Loading ...
Sorry, an error occurred while loading the content.

synIDattr used with matchadd

Expand Messages
  • richard emberson
    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
    Message 1 of 2 , Jul 2, 2012
    • 0 Attachment
      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

      --
      Quis custodiet ipsos custodes

      --
      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
    • Tony Mechelynck
      ... 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
      Message 2 of 2 , Jul 3, 2012
      • 0 Attachment
        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
      Your message has been successfully submitted and would be delivered to recipients shortly.