Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
xolox committed Aug 11, 2010
1 parent b0b5800 commit 026fdd4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
11 changes: 8 additions & 3 deletions luainspect.vim
Expand Up @@ -2,7 +2,7 @@
" Author: Peter Odding <peter@peterodding.com>
" Last Change: August 12, 2010
" URL: http://peterodding.com/code/vim/lua-inspect/
" Version: 0.3.4
" Version: 0.3.5
" License: MIT

" Support for automatic update using the GLVS plug-in.
Expand Down Expand Up @@ -50,7 +50,7 @@ let s:groups['Param'] = 'guifg=#000040'
let s:groups['Local'] = 'guifg=#000080'
let s:groups['FieldDefined'] = 'guifg=#600000'
let s:groups['FieldUndefined'] = 'guifg=#c00000'
let s:groups['SelectedVariable'] = 'Folded'
let s:groups['SelectedVariable'] = 'CursorLine'
let s:groups['SyntaxError'] = 'SpellBad'

" (Automatic) command definitions. {{{1
Expand Down Expand Up @@ -232,11 +232,16 @@ function! s:clear_previous_matches() " {{{2
endfunction

function! s:highlight_variables() " {{{2
call clearmatches()
for line in b:luainspect_output[1:-1]
if s:check_output(line, '^\w\+\(\s\+\d\+\)\{3}$')
let [hlgroup, linenum, firstcol, lastcol] = split(line)
let pattern = s:highlight_position(linenum + 0, firstcol - 1, lastcol + 2)
execute 'syntax match' hlgroup '/' . pattern . '/'
if hlgroup == 'luaInspectSelectedVariable'
call matchadd(hlgroup, pattern)
else
execute 'syntax match' hlgroup '/' . pattern . '/'
endif
endif
endfor
endfunction
Expand Down
9 changes: 6 additions & 3 deletions luainspect4vim.lua
Expand Up @@ -47,10 +47,13 @@ end
function actions.highlight(tokenlist, line, column)
local curvar = getcurvar(tokenlist, line, column)
for i, token in ipairs(tokenlist) do
local kind
if curvar and curvar.ast.id == token.ast.id then
kind = 'luaInspectSelectedVariable'
elseif token.tag == 'Id' then
local l1, c1 = unpack(token.ast.lineinfo.first, 1, 2)
local l2, c2 = unpack(token.ast.lineinfo.last, 1, 2)
if l1 == l2 then myprint('luaInspectSelectedVariable ' .. l1 .. ' ' .. c1 .. ' ' .. c2) end
end
local kind
if token.tag == 'Id' then
if not token.ast.localdefinition then
if token.ast.definedglobal then
kind = 'luaInspectGlobalDefined'
Expand Down

0 comments on commit 026fdd4

Please sign in to comment.