Skip to content

Commit 0e12923

Browse files
committed
Make ]] commands jump between top-level functions
Inline-defined functions tend to be small enough that it's not useful to jump between them. Instead, jump between top-level functions (defined at file scope) instead. Bug where jumping back jumps past a function still occurs.
1 parent 48dce99 commit 0e12923

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

autoload/xolox/lua.vim

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ let g:xolox#lua#version = '0.8'
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'
10+
let s:function_regex = '\v^(\w.*)?\zs<function>'
1011

1112
function! xolox#lua#includeexpr(fname) " {{{1
1213
" Search module path for matching Lua scripts.
@@ -200,7 +201,8 @@ endfunction
200201
function! s:getfunscope()
201202
let firstpos = [0, 1, 1, 0]
202203
let lastpos = getpos('$')
203-
while search('\<function\>', 'bW')
204+
" Only jumps between top-level function scope.
205+
while search(s:function_regex, 'bW')
204206
if xolox#lua#tokeniscode()
205207
let firstpos = getpos('.')
206208
break
@@ -216,7 +218,8 @@ function! xolox#lua#jumpthisfunc(forward) " {{{1
216218
let cpos = [line('.'), col('.')]
217219
let fpos = [1, 1]
218220
let lpos = [line('$'), 1]
219-
while search('\<function\>', a:forward ? 'W' : 'bW')
221+
" Only jumps between top-level function scope.
222+
while search(s:function_regex, a:forward ? 'W' : 'bW')
220223
if xolox#lua#tokeniscode()
221224
break
222225
endif
@@ -236,7 +239,8 @@ function! xolox#lua#jumpotherfunc(forward) " {{{1
236239
" jump to the start/end of the function
237240
call xolox#lua#jumpthisfunc(a:forward)
238241
" search for the previous/next function
239-
while search('\<function\>', a:forward ? 'W' : 'bW')
242+
" Only jumps between top-level function scope.
243+
while search(s:function_regex, a:forward ? 'W' : 'bW')
240244
" ignore strings and comments containing 'function'
241245
if xolox#lua#tokeniscode()
242246
return 1

0 commit comments

Comments
 (0)