Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Simplified wrapper as suggested by David Manura

I figured MetaLua had to include the line/column info somewhere, but
when I couldn't find it in 10 minutes I decided to improvise a
workaround. Fortunately that turned out to be unnecessary which means I
get to delete code and make the plug-in faster :-)
  • Loading branch information...
commit ed34601710a09222ef3351082c40cc249eae9821 1 parent 63dc4bb
Peter Odding authored July 28, 2010
2  luainspect.vim
@@ -2,7 +2,7 @@
2 2
 " Author: Peter Odding <peter@peterodding.com>
3 3
 " Last Change: July 28, 2010
4 4
 " URL: http://peterodding.com/code/vim/lua-inspect/
5  
-" Version: 0.1.3
  5
+" Version: 0.1.4
6 6
 
7 7
 " Configuration defaults. {{{1
8 8
 
29  luainspect4vim.lua
@@ -8,33 +8,18 @@
8 8
 
9 9
 --]]
10 10
 
11  
-local function offset2lineinfo(text, offset)
12  
-  -- TODO Cache intermediate results because they won't change within a single
13  
-  --      call to the function returned from this module below.
14  
-  local curlnum = 1
15  
-  local lastlineoffset = 0
16  
-  for i in text:gmatch '()\n' do
17  
-    if i >= offset then break end
18  
-    curlnum = curlnum + 1
19  
-    lastlineoffset = i
20  
-  end
21  
-  return curlnum, offset - lastlineoffset
22  
-end
23  
-
24 11
 local dumpvar
25 12
 if type(vim) == 'table' and vim.eval then
26 13
   -- The Lua interface for Vim redefines print() so it prints inside Vim.
27  
-  dumpvar = function(text, kind, firstbyte, lastbyte)
28  
-    local line1, offset1 = offset2lineinfo(text, firstbyte)
29  
-    print(kind, line1, offset1, offset1 + (lastbyte - firstbyte))
  14
+  dumpvar = function(kind, lnum, firstcol, lastcol)
  15
+    print(kind, lnum, firstcol, lastcol)
30 16
   end
31 17
 else
32 18
   -- My $LUA_INIT script redefines print() to enable pretty printing in the
33 19
   -- interactive prompt, which means strings are printed with surrounding
34 20
   -- quotes. This would break the communication between Vim and this script.
35  
-  dumpvar = function(text, kind, firstbyte, lastbyte)
36  
-    local line1, offset1 = offset2lineinfo(text, firstbyte)
37  
-    io.write(kind, '\t', line1, '\t', offset1, '\t', offset1 + (lastbyte - firstbyte), '\n')
  21
+  dumpvar = function(kind, lnum, firstcol, lastcol)
  22
+    io.write(kind, '\t', lnum, '\t', firstcol, '\t', lastcol, '\n')
38 23
   end
39 24
 end
40 25
 
@@ -72,7 +57,11 @@ return function(text)
72 57
         kind = 'luaInspectFieldUndefined'
73 58
       end
74 59
     end
75  
-    if kind then dumpvar(text, kind, note[1], note[2]) end
  60
+    if kind then
  61
+      local l1, c1 = unpack(note.ast.lineinfo.first, 1, 2)
  62
+      local l2, c2 = unpack(note.ast.lineinfo.last, 1, 2)
  63
+      if l1 == l2 then dumpvar(kind, l1, c1, c2) end
  64
+    end
76 65
   end
77 66
 end
78 67
 

0 notes on commit ed34601

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