Skip to content

Commit 9160dee

Browse files
committed
Try to resolve pull request #23 (workaround for table indexes in globals.lua)
See pull request #23 on GitHub: #23
1 parent 1d7aaec commit 9160dee

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

‎autoload/xolox/lua.vim‎

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
" Last Change: June 16, 2014
44
" URL: http://peterodding.com/code/vim/lua-ftplugin
55

6-
let g:xolox#lua#version = '0.7.13'
6+
let g:xolox#lua#version = '0.7.17'
77
let s:miscdir = expand('<sfile>:p:h:h:h') . '/misc/lua-ftplugin'
88
let s:omnicomplete_script = s:miscdir . '/omnicomplete.lua'
99
let s:globals_script = s:miscdir . '/globals.lua'
@@ -132,7 +132,9 @@ function! s:highlighterrors()
132132
endfunction
133133

134134
function! xolox#lua#checkglobals(verbose) " {{{1
135-
let output = xolox#lua#dofile(s:globals_script, [expand('%'), a:verbose])
135+
let curfile = expand('%')
136+
call xolox#misc#msg#debug("lua.vim %s: Checking for undefined globals in '%s' using '%s' ..", g:xolox#lua#version, curfile, s:globals_script)
137+
let output = xolox#lua#dofile(s:globals_script, [curfile, a:verbose])
136138
call setqflist(eval('[' . join(output, ',') . ']'), 'r')
137139
cwindow
138140
endfunction
@@ -472,13 +474,31 @@ endfunction
472474
function! xolox#lua#dofile(pathname, arguments) " {{{1
473475
if has('lua')
474476
" Use the Lua Interface for Vim.
477+
call xolox#misc#msg#debug("lua.vim %s: Running '%s' using Lua Interface for Vim ..", g:xolox#lua#version, a:pathname)
475478
redir => output
476-
lua arg = vim.eval('a:arguments')
477-
execute 'silent luafile' fnameescape(a:pathname)
479+
" https://github.com/xolox/vim-lua-ftplugin/pull/23 reports that somewhere
480+
" in the communication between Vim and Lua someone switches from one based
481+
" indexes to zero based indexes, breaking the Vim plug-in. I haven't been
482+
" able to reproduce this but the following code is intended to compensate
483+
" should the problem occur. As a bonus it's compatible with how the Lua
484+
" interpreter runs Lua scripts :-)
485+
silent lua << EOL
486+
local script = vim.eval('a:pathname')
487+
arg = vim.eval('a:arguments')
488+
if arg[0] == nil then
489+
-- Keep the list order, just set arg[0] to the pathname of the script.
490+
arg[0] = script
491+
else
492+
-- Insert the pathname of the script in arg[0], shifting up arguments.
493+
table.insert(arg, 0, script)
494+
end
495+
dofile(script)
496+
EOL
478497
redir END
479498
return split(output, "\n")
480499
else
481500
" Use the command line Lua interpreter.
501+
call xolox#misc#msg#debug("lua.vim %s: Running '%s' using command line Lua interpreter ..", g:xolox#lua#version, a:pathname)
482502
let interpreter = xolox#misc#escape#shell(xolox#misc#option#get('lua_interpreter_path', 'lua'))
483503
let pathname = xolox#misc#escape#shell(a:pathname)
484504
let arguments = join(map(a:arguments, 'xolox#misc#escape#shell(v:val)'))

0 commit comments

Comments
 (0)