Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Highlight syntax errors as spelling errors

  • Loading branch information...
commit f5b367d8dd7d9d6da1fb359ab19b0e44c49161f7 1 parent 645054f
Peter Odding authored August 10, 2010
13  README.md
Source Rendered
@@ -28,10 +28,9 @@ You don't need to use this command unless you've disabled automatic highlighting
28 28
  * <span style="color: #600000">luaInspectFieldDefined</span>
29 29
  * <span style="color: #C00000">luaInspectFieldUndefined</span>
30 30
  * <span style="background: #D3D3D3">luaInspectSelectedVariable</span>
  31
+ * <span style="border-bottom: 1px dotted red">luaInspectSyntaxError</span>
31 32
 
32  
-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).
33  
-
34  
-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).
  33
+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).
35 34
 
36 35
 ### The `g:loaded_luainspect` option
37 36
 
@@ -57,14 +56,6 @@ The plug-in uses the Lua interface for Vim when available so that it doesn't hav
57 56
 
58 57
     :let g:lua_inspect_internal = 0
59 58
 
60  
-## Not yet implemented
61  
-
62  
- * When LuaInspect fails because of a syntax error the position of the error should be marked like e.g. spelling errors
63  
-
64  
- * 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.
65  
-
66  
- * 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.
67  
-
68 59
 ## Contact
69 60
 
70 61
 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).
7  TODO.md
Source Rendered
... ...
@@ -0,0 +1,7 @@
  1
+# The to-do list
  2
+
  3
+ * 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.
  4
+
  5
+ * 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.
  6
+
  7
+ * Document the g:lua_inspect_path option.
32  luainspect.vim
@@ -2,7 +2,7 @@
2 2
 " Author: Peter Odding <peter@peterodding.com>
3 3
 " Last Change: August 10, 2010
4 4
 " URL: http://peterodding.com/code/vim/lua-inspect/
5  
-" Version: 0.2.2
  5
+" Version: 0.2.3
6 6
 " License: MIT
7 7
 
8 8
 " 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'
48 48
 let s:groups['FieldDefined'] = 'guifg=#600000'
49 49
 let s:groups['FieldUndefined'] = 'guifg=#c00000'
50 50
 let s:groups['SelectedVariable'] = 'Folded'
  51
+let s:groups['SyntaxError'] = 'SpellBad'
51 52
 
52 53
 " (Automatic) command definitions. {{{1
53 54
 
@@ -168,24 +169,23 @@ function! s:clear_previous_matches() " {{{2
168 169
 endfunction
169 170
 
170 171
 function! s:highlight_variables() " {{{2
171  
-  let did_warning = 0
  172
+  if len(b:luainspect_output) == 1
  173
+    let line = b:luainspect_output[0]
  174
+    let errinfo = matchlist(line, '^\(\d\+\)\s*\(\d*\)$')
  175
+    if len(errinfo) >= 3
  176
+      let error_cmd = 'syntax match luaInspectSyntaxError /\%%>%il\%%<%il.*/ containedin=ALLBUT,lua*Comment*'
  177
+      execute printf(error_cmd, errinfo[1] - 1, (errinfo[2] != '' ? errinfo[2] : line('$')) + 1)
  178
+      return
  179
+    endif
  180
+  endif
172 181
   for line in b:luainspect_output
173 182
     if match(line, '^\w\+\(\s\+\d\+\)\{3}$') == -1
174  
-      if !did_warning
175  
-        try
176  
-          echohl WarningMsg
177  
-          echomsg "Invalid output from luainspect4vim.lua:"
178  
-        finally
179  
-          echohl None
180  
-          let did_warning = 1
181  
-        endtry
182  
-      endif
183  
-      echomsg strtrans(line)
184  
-    else
185  
-      let [type, lnum, start, end] = split(line)
186  
-      let syntax_cmd = 'syntax match %s /\%%%il\%%>%ic\<\w\+\>\%%<%ic/'
187  
-      execute printf(syntax_cmd, type, lnum, start - 1, end + 2)
  183
+      call xolox#warning("Invalid output from luainspect4vim.lua: %s", strtrans(line))
  184
+      return
188 185
     endif
  186
+    let [type, lnum, start, end] = split(line)
  187
+    let syntax_cmd = 'syntax match %s /\%%%il\%%>%ic\<\w\+\>\%%<%ic/'
  188
+    execute printf(syntax_cmd, type, lnum, start - 1, end + 2)
189 189
   endfor
190 190
 endfunction
191 191
 
23  luainspect4vim.lua
@@ -9,19 +9,15 @@
9 9
 
10 10
 --]]
11 11
 
12  
-local dumpvar
  12
+local myprint
13 13
 if type(vim) == 'table' and vim.eval then
14 14
   -- The Lua interface for Vim redefines print() so it prints inside Vim.
15  
-  dumpvar = function(kind, lnum, firstcol, lastcol)
16  
-    print(kind, lnum, firstcol, lastcol)
17  
-  end
  15
+  myprint = print
18 16
 else
19 17
   -- My $LUA_INIT script redefines print() to enable pretty printing in the
20 18
   -- interactive prompt, which means strings are printed with surrounding
21 19
   -- quotes. This would break the communication between Vim and this script.
22  
-  dumpvar = function(kind, lnum, firstcol, lastcol)
23  
-    io.write(kind, '\t', lnum, '\t', firstcol, '\t', lastcol, '\n')
24  
-  end
  20
+  function myprint(text) io.write(text, '\n') end
25 21
 end
26 22
 
27 23
 local function getcurvar(tokenlist, line, column)
@@ -44,7 +40,14 @@ return function(src)
44 40
   column = tonumber(column)
45 41
   src = LA.remove_shebang(src)
46 42
   local f, err, linenum, colnum, linenum2 = LA.loadstring(src)
47  
-  if not f then return end -- TODO Highlight syntax errors like spelling errors
  43
+  if not f then
  44
+    if not linenum2 then
  45
+      myprint(linenum)
  46
+    else
  47
+      myprint(linenum2 .. ' ' .. linenum)
  48
+    end
  49
+    return
  50
+  end
48 51
   local ast; ast, err, linenum, colnum, linenum2 = LA.ast_from_string(src, "noname.lua")
49 52
   if not ast then return end
50 53
   local tokenlist = LA.ast_to_tokenlist(ast, src)
@@ -82,7 +85,9 @@ return function(src)
82 85
     if kind then
83 86
       local l1, c1 = unpack(token.ast.lineinfo.first, 1, 2)
84 87
       local l2, c2 = unpack(token.ast.lineinfo.last, 1, 2)
85  
-      if l1 == l2 then dumpvar(kind, l1, c1, c2) end
  88
+      if l1 == l2 then
  89
+        myprint(kind .. ' ' .. l1 .. ' ' .. c1 .. ' ' .. c2)
  90
+      end
86 91
     end
87 92
   end
88 93
 end

0 notes on commit f5b367d

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