Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Showing with 39 additions and 36 deletions.
  1. +2 −11 README.md
  2. +7 −0 TODO.md
  3. +16 −16 luainspect.vim
  4. +14 −9 luainspect4vim.lua
View
13 README.md
@@ -28,10 +28,9 @@ You don't need to use this command unless you've disabled automatic highlighting
* <span style="color: #600000">luaInspectFieldDefined</span>
* <span style="color: #C00000">luaInspectFieldUndefined</span>
* <span style="background: #D3D3D3">luaInspectSelectedVariable</span>
+ * <span style="border-bottom: 1px dotted red">luaInspectSyntaxError</span>
-If you don't like one or more of the default styles the Vim documentation [describes how to change them](http://vimdoc.sourceforge.net/htmldoc/syntax.html#:hi-default).
-
-If you want to disable the semantic highlighting in a specific Vim buffer execute `:LuaInspect!` in that buffer. When you want to reenable the highlighting execute `:LuaInspect` again, but now without the [bang](http://vimdoc.sourceforge.net/htmldoc/map.html#:command-bang).
+When a syntax error is found no highlighting can be performed but the lines where the error is reported will be marked like a spelling error. If you don't like one or more of the default styles the Vim documentation [describes how to change them](http://vimdoc.sourceforge.net/htmldoc/syntax.html#:hi-default). If you want to disable the semantic highlighting in a specific Vim buffer execute `:LuaInspect!` in that buffer. When you want to reenable the highlighting execute `:LuaInspect` again, but now without the [bang](http://vimdoc.sourceforge.net/htmldoc/map.html#:command-bang).
### The `g:loaded_luainspect` option
@@ -57,14 +56,6 @@ The plug-in uses the Lua interface for Vim when available so that it doesn't hav
:let g:lua_inspect_internal = 0
-## Not yet implemented
-
- * When LuaInspect fails because of a syntax error the position of the error should be marked like e.g. spelling errors
-
- * Right now the highlighting styles used by `luainspect.vim` are the same as those used by the SciTE plug-in and they don't work well on dark backgrounds. As soon as I get around to picking some alternate colors I'll include those in the plug-in.
-
- * Bindings for other features of LuaInspect like renaming variables on command and showing tooltips for identifiers. This might be a lot of work but could prove to be really useful in making Lua easy to use in Vim.
-
## Contact
If you have questions, bug reports, suggestions, etc. the author can be contacted at <peter@peterodding.com>. The latest version is available at <http://peterodding.com/code/vim/lua-inspect/> and <http://github.com/xolox/vim-lua-inspect>. If you like this plug-in please vote for it on [www.vim.org](http://www.vim.org/scripts/script.php?script_id=3169).
View
7 TODO.md
@@ -0,0 +1,7 @@
+# The to-do list
+
+ * Right now the highlighting styles used by `luainspect.vim` are the same as those used by the SciTE plug-in and they don't work well on dark backgrounds. As soon as I get around to picking some alternate colors I'll include those in the plug-in.
+
+ * Bindings for other features of LuaInspect like renaming variables on command and showing tooltips for identifiers. This might be a lot of work but could prove to be really useful in making Lua easy to use in Vim.
+
+ * Document the g:lua_inspect_path option.
View
32 luainspect.vim
@@ -2,7 +2,7 @@
" Author: Peter Odding <peter@peterodding.com>
" Last Change: August 10, 2010
" URL: http://peterodding.com/code/vim/lua-inspect/
-" Version: 0.2.2
+" Version: 0.2.3
" License: MIT
" Don't source the plug-in when its already been loaded or &compatible is set.
@@ -48,6 +48,7 @@ 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['SyntaxError'] = 'SpellBad'
" (Automatic) command definitions. {{{1
@@ -168,24 +169,23 @@ function! s:clear_previous_matches() " {{{2
endfunction
function! s:highlight_variables() " {{{2
- let did_warning = 0
+ if len(b:luainspect_output) == 1
+ let line = b:luainspect_output[0]
+ let errinfo = matchlist(line, '^\(\d\+\)\s*\(\d*\)$')
+ if len(errinfo) >= 3
+ let error_cmd = 'syntax match luaInspectSyntaxError /\%%>%il\%%<%il.*/ containedin=ALLBUT,lua*Comment*'
+ execute printf(error_cmd, errinfo[1] - 1, (errinfo[2] != '' ? errinfo[2] : line('$')) + 1)
+ return
+ endif
+ endif
for line in b:luainspect_output
if match(line, '^\w\+\(\s\+\d\+\)\{3}$') == -1
- if !did_warning
- try
- echohl WarningMsg
- echomsg "Invalid output from luainspect4vim.lua:"
- finally
- echohl None
- let did_warning = 1
- endtry
- endif
- echomsg strtrans(line)
- else
- let [type, lnum, start, end] = split(line)
- let syntax_cmd = 'syntax match %s /\%%%il\%%>%ic\<\w\+\>\%%<%ic/'
- execute printf(syntax_cmd, type, lnum, start - 1, end + 2)
+ call xolox#warning("Invalid output from luainspect4vim.lua: %s", strtrans(line))
+ return
endif
+ let [type, lnum, start, end] = split(line)
+ let syntax_cmd = 'syntax match %s /\%%%il\%%>%ic\<\w\+\>\%%<%ic/'
+ execute printf(syntax_cmd, type, lnum, start - 1, end + 2)
endfor
endfunction
View
23 luainspect4vim.lua
@@ -9,19 +9,15 @@
--]]
-local dumpvar
+local myprint
if type(vim) == 'table' and vim.eval then
-- The Lua interface for Vim redefines print() so it prints inside Vim.
- dumpvar = function(kind, lnum, firstcol, lastcol)
- print(kind, lnum, firstcol, lastcol)
- end
+ myprint = print
else
-- My $LUA_INIT script redefines print() to enable pretty printing in the
-- interactive prompt, which means strings are printed with surrounding
-- quotes. This would break the communication between Vim and this script.
- dumpvar = function(kind, lnum, firstcol, lastcol)
- io.write(kind, '\t', lnum, '\t', firstcol, '\t', lastcol, '\n')
- end
+ function myprint(text) io.write(text, '\n') end
end
local function getcurvar(tokenlist, line, column)
@@ -44,7 +40,14 @@ return function(src)
column = tonumber(column)
src = LA.remove_shebang(src)
local f, err, linenum, colnum, linenum2 = LA.loadstring(src)
- if not f then return end -- TODO Highlight syntax errors like spelling errors
+ if not f then
+ if not linenum2 then
+ myprint(linenum)
+ else
+ myprint(linenum2 .. ' ' .. linenum)
+ end
+ return
+ end
local ast; ast, err, linenum, colnum, linenum2 = LA.ast_from_string(src, "noname.lua")
if not ast then return end
local tokenlist = LA.ast_to_tokenlist(ast, src)
@@ -82,7 +85,9 @@ return function(src)
if kind 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 dumpvar(kind, l1, c1, c2) end
+ if l1 == l2 then
+ myprint(kind .. ' ' .. l1 .. ' ' .. c1 .. ' ' .. c2)
+ end
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.