Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Don't parse the text when it hasn't been changed.

  • Loading branch information...
commit a9205704796749a0556ce6e7a7959654b3983caa 1 parent ffe24f3
Peter Odding authored August 07, 2010

Showing 1 changed file with 21 additions and 16 deletions. Show diff stats Hide diff stats

  1. 37  luainspect.vim
37  luainspect.vim
... ...
@@ -1,6 +1,6 @@
1 1
 " Vim plug-in
2 2
 " Author: Peter Odding <peter@peterodding.com>
3  
-" Last Change: July 29, 2010
  3
+" Last Change: August 7, 2010
4 4
 " URL: http://peterodding.com/code/vim/lua-inspect/
5 5
 " Version: 0.1.5
6 6
 
@@ -44,27 +44,32 @@ function! s:RunLuaInspect() abort
44 44
   let lines = getline(1, "$")
45 45
   call insert(lines, col('.'))
46 46
   call insert(lines, line('.'))
47  
-  let l:text = join(lines, "\n")
48  
-  if has('lua') && g:lua_inspect_internal
49  
-    " Run LuaInspect using the Lua interface for Vim.
50  
-    redir => listing
51  
-    silent lua << EOF
52  
-    if io == nil then
53  
-      -- The Lua interface for Vim doesn't include io.*!
54  
-      io = { type = function() end }
55  
-    end
56  
-    require 'luainspect4vim' (vim.eval 'l:text')
  47
+  let l:input = join(lines, "\n")
  48
+  " Don't parse the text when it hasn't been changed.
  49
+  if !(exists('b:luainspect_input') && b:luainspect_input == l:input)
  50
+    if !(has('lua') && g:lua_inspect_internal)
  51
+      " Run LuaInspect as an external program.
  52
+      let b:luainspect_output = system("lua -e 'require\"luainspect4vim\" (io.read \"*a\")'", l:input)
  53
+    else
  54
+      " Run LuaInspect using the Lua interface for Vim.
  55
+      redir => b:luainspect_output
  56
+      silent lua << EOF
  57
+      if io == nil then
  58
+        -- The Lua interface for Vim previously didn't include io.*!
  59
+        io = { type = function() end }
  60
+      end
  61
+      require 'luainspect4vim' (vim.eval 'l:input')
57 62
 EOF
58  
-    redir END
59  
-  else
60  
-    " Run LuaInspect as an external program.
61  
-    let listing = system("lua -e 'require\"luainspect4vim\" (io.read \"*a\")'", l:text)
  63
+      redir END
  64
+    endif
  65
+    " Remember the text that was just parsed.
  66
+    let b:luainspect_input = l:input
62 67
   endif
63 68
   " Clear previously created highlighting.
64 69
   call s:LoadDefaultStyles()
65 70
   call s:ClearPreviousMatches()
66 71
   " Highlight variables in buffer based on positions.
67  
-  for fields in split(listing, "\n")
  72
+  for fields in split(b:luainspect_output, "\n")
68 73
     let [type, lnum, start, end] = split(fields)
69 74
     let command = 'syntax match %s /\%%%il\%%>%ic\<\w\+\>\%%<%ic/'
70 75
     execute printf(command, type, lnum, start - 1, end + 2)

0 notes on commit a920570

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