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

heighlighting ranges in buffer

Expand Messages
  • Nathan Hüsken
    Hey, I am currently trying to improve the clang_complete plugin to have a global notion of symbols. One thing I would like to do is highlighting all occurences
    Message 1 of 5 , Feb 13, 2013
    • 0 Attachment
      Hey,

      I am currently trying to improve the clang_complete plugin to have a global notion of symbols.
      One thing I would like to do is highlighting all occurences of the symbol under the cursor.

      I have the position and extend of all occurences. All I need to do is highlighting these ranges.

      How can I do this with vimscript (or python)?

      Thanks!
      Nathan

      --
      --
      You received this message from the "vim_dev" 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

      ---
      You received this message because you are subscribed to the Google Groups "vim_dev" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • James McCoy
      ... If you re ok with the highlighting being window-local, I briefly toyed with something like the following to mimic Eclipse s automatic highlight the word
      Message 2 of 5 , Feb 13, 2013
      • 0 Attachment
        On Wed, Feb 13, 2013 at 10:50:28AM -0800, Nathan Hüsken wrote:
        > Hey,
        >
        > I am currently trying to improve the clang_complete plugin to have a global notion of symbols.
        > One thing I would like to do is highlighting all occurences of the symbol under the cursor.

        If you're ok with the highlighting being window-local, I briefly toyed
        with something like the following to mimic Eclipse's automatic
        "highlight the word under the cursor" functionality.

        hi link AutomaticWord IncSearch
        function! TransientMatch(word)
        if exists('w:matchid')
        call matchdelete(w:matchid)
        endif
        let w:matchid = matchadd('AutomaticWord', '\<'.a:word.'\>', -1)
        endfunction
        augroup TransientMatch
        autocmd!
        autocmd CursorHold * call TransientMatch(expand('<cword>'))
        augroup END

        Since this is triggered by CursorHold, you'd also want to lower
        'updatetime' to a value that's not too slow.

        Cheers,
        --
        James
        GPG Key: 4096R/331BA3DB 2011-12-05 James McCoy <jamessan@...>
      • ZyX
        If I correctly understood OP, current symbol != all words that are the same as the one under cursor (i.e. local variable in one function is different symbol
        Message 3 of 5 , Feb 13, 2013
        • 0 Attachment
          If I correctly understood OP, current symbol != all words that are the same as the one under cursor (i.e. local variable in one function is different symbol from the local variable in another function, even if it has the same name). Thus what is needed, given positions in a list of three-tuples of (lnum, col, len) is constructing the regex like this:

          let regex='\v'.join(map(copy(positions), '"%".v:val[0]."l%".v:val[1]."c.{".v:val[3]."}"'), '|')
          . This assumes length is given it terms of characters, but column is byte offset. Then this regex may be used in your function.

          --
          --
          You received this message from the "vim_dev" 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

          ---
          You received this message because you are subscribed to the Google Groups "vim_dev" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
          For more options, visit https://groups.google.com/groups/opt_out.
        • Nathan Hüsken
          ... That is correct. ... Ok, I have (line,col) but I convert it to byte offset using line2byte(line) + col. Unfortantly something does not work. The regex I
          Message 4 of 5 , Feb 14, 2013
          • 0 Attachment
            Am Donnerstag, 14. Februar 2013 04:46:04 UTC+1 schrieb ZyX:
            > If I correctly understood OP, current symbol != all words that are the same as the one under cursor (i.e. local variable in one function is different symbol from the local variable in another function, even if it has the same name).

            That is correct.

            > Thus what is needed, given positions in a list of three-tuples of (lnum, col, len) is constructing the regex like this:
            >
            > let regex='\v'.join(map(copy(positions), '"%".v:val[0]."l%".v:val[1]."c.{".v:val[3]."}"'), '|')
            > . This assumes length is given it terms of characters, but column is byte offset. Then this regex may be used in your function.

            Ok, I have (line,col) but I convert it to byte offset using line2byte(line) + col.

            Unfortantly something does not work. The regex I get is:

            \v%1l%164c.{5}|%1l%234c.{5}|%1l%332c.{5}

            now I put this into:

            let w:matchid = matchadd('AutomaticWord',regex, -1)

            But the positions are not highlighted.

            Thanks!
            Nathan

            --
            --
            You received this message from the "vim_dev" 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

            ---
            You received this message because you are subscribed to the Google Groups "vim_dev" group.
            To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
            For more options, visit https://groups.google.com/groups/opt_out.
          • Nathan Hüsken
            ... Ok, you got me confused there. I thought col was supposed to be the byte offset in the buffer. Got it corrected and it works like a charm. Thanks! -- --
            Message 5 of 5 , Feb 14, 2013
            • 0 Attachment
              Am Donnerstag, 14. Februar 2013 11:13:36 UTC+1 schrieb Nathan Hüsken:
              > Am Donnerstag, 14. Februar 2013 04:46:04 UTC+1 schrieb ZyX:
              > > If I correctly understood OP, current symbol != all words that are the same as the one under cursor (i.e. local variable in one function is different symbol from the local variable in another function, even if it has the same name).
              >
              > That is correct.
              >
              > > Thus what is needed, given positions in a list of three-tuples of (lnum, col, len) is constructing the regex like this:
              > >
              > > let regex='\v'.join(map(copy(positions), '"%".v:val[0]."l%".v:val[1]."c.{".v:val[3]."}"'), '|')
              > > . This assumes length is given it terms of characters, but column is byte offset. Then this regex may be used in your function.
              >
              > Ok, I have (line,col) but I convert it to byte offset using line2byte(line) + col.
              >
              > Unfortantly something does not work. The regex I get is:
              >
              > \v%1l%164c.{5}|%1l%234c.{5}|%1l%332c.{5}
              >
              > now I put this into:
              >
              > let w:matchid = matchadd('AutomaticWord',regex, -1)
              >
              > But the positions are not highlighted.
              >
              > Thanks!
              > Nathan

              Ok, you got me confused there. I thought col was supposed to be the byte offset in the buffer.
              Got it corrected and it works like a charm. Thanks!

              --
              --
              You received this message from the "vim_dev" 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

              ---
              You received this message because you are subscribed to the Google Groups "vim_dev" group.
              To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
              For more options, visit https://groups.google.com/groups/opt_out.
            Your message has been successfully submitted and would be delivered to recipients shortly.