Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Better highlighting of selected variables

Previously the highlighting of the selected variable overruled the
regular highlighting which turned out to get annoying very quickly.
Now the plug-in respects DWIM by combining the two highlighting styles.
  • Loading branch information...
commit 026fdd42bca366b95a271c3b8c9fa78cbc17c0f9 1 parent b0b5800
Peter Odding authored August 12, 2010
11  luainspect.vim
@@ -2,7 +2,7 @@
2 2
 " Author: Peter Odding <peter@peterodding.com>
3 3
 " Last Change: August 12, 2010
4 4
 " URL: http://peterodding.com/code/vim/lua-inspect/
5  
-" Version: 0.3.4
  5
+" Version: 0.3.5
6 6
 " License: MIT
7 7
 
8 8
 " Support for automatic update using the GLVS plug-in.
@@ -50,7 +50,7 @@ let s:groups['Param'] = 'guifg=#000040'
50 50
 let s:groups['Local'] = 'guifg=#000080'
51 51
 let s:groups['FieldDefined'] = 'guifg=#600000'
52 52
 let s:groups['FieldUndefined'] = 'guifg=#c00000'
53  
-let s:groups['SelectedVariable'] = 'Folded'
  53
+let s:groups['SelectedVariable'] = 'CursorLine'
54 54
 let s:groups['SyntaxError'] = 'SpellBad'
55 55
 
56 56
 " (Automatic) command definitions. {{{1
@@ -232,11 +232,16 @@ function! s:clear_previous_matches() " {{{2
232 232
 endfunction
233 233
 
234 234
 function! s:highlight_variables() " {{{2
  235
+  call clearmatches()
235 236
   for line in b:luainspect_output[1:-1]
236 237
     if s:check_output(line, '^\w\+\(\s\+\d\+\)\{3}$')
237 238
       let [hlgroup, linenum, firstcol, lastcol] = split(line)
238 239
       let pattern = s:highlight_position(linenum + 0, firstcol - 1, lastcol + 2)
239  
-      execute 'syntax match' hlgroup '/' . pattern . '/'
  240
+      if hlgroup == 'luaInspectSelectedVariable'
  241
+        call matchadd(hlgroup, pattern)
  242
+      else
  243
+        execute 'syntax match' hlgroup '/' . pattern . '/'
  244
+      endif
240 245
     endif
241 246
   endfor
242 247
 endfunction
9  luainspect4vim.lua
@@ -47,10 +47,13 @@ end
47 47
 function actions.highlight(tokenlist, line, column)
48 48
   local curvar = getcurvar(tokenlist, line, column)
49 49
   for i, token in ipairs(tokenlist) do
50  
-    local kind
51 50
     if curvar and curvar.ast.id == token.ast.id then
52  
-      kind = 'luaInspectSelectedVariable'
53  
-    elseif token.tag == 'Id' then
  51
+      local l1, c1 = unpack(token.ast.lineinfo.first, 1, 2)
  52
+      local l2, c2 = unpack(token.ast.lineinfo.last, 1, 2)
  53
+      if l1 == l2 then myprint('luaInspectSelectedVariable ' .. l1 .. ' ' .. c1 .. ' ' .. c2) end
  54
+    end
  55
+    local kind
  56
+    if token.tag == 'Id' then
54 57
       if not token.ast.localdefinition then
55 58
         if token.ast.definedglobal then
56 59
           kind = 'luaInspectGlobalDefined'

0 notes on commit 026fdd4

Please sign in to comment.
Something went wrong with that request. Please try again.