Skip to content

Commit 1bab11e

Browse files
committed
fix s:numtoname
1 parent 02306ef commit 1bab11e

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

autoload/vimlparser.vim

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
"
44
" See https://github.com/vim-jp/vital.vim for vital module.
55

6-
let s:VimLParser = vital#vimlparser#import('VimlParser').import()
6+
call extend(s:, vital#vimlparser#import('VimlParser').import())
77

88
" To Vim plugin developer who want to depend on vim-vimlparser:
99
" Please use vimlparser as vital-module instead of this autoload function.
1010
" We do not ensure that future changes are backward compatible.
1111
function! vimlparser#import()
12-
return s:VimLParser
12+
return s:
1313
endfunction
1414

1515
" @brief Read input as VimScript and return stringified AST.
@@ -31,3 +31,32 @@ function! vimlparser#test(input, ...)
3131
echoerr substitute(v:throwpoint, '\.\.\zs\d\+', '\=s:numtoname(submatch(0))', 'g') . "\n" . v:exception
3232
endtry
3333
endfunction
34+
35+
if has('patch-7.4.1842')
36+
function! s:numtoname(num)
37+
for k in keys(s:)
38+
if type(s:[k]) == type({})
39+
for name in keys(s:[k])
40+
if type(s:[k][name]) == type(function('tr')) && get(s:[k][name], 'name') == a:num
41+
return printf('%s.%s', k, name)
42+
endif
43+
endfor
44+
endif
45+
endfor
46+
return a:num
47+
endfunction
48+
else
49+
function! s:numtoname(num)
50+
let sig = printf("function('%s')", a:num)
51+
for k in keys(s:)
52+
if type(s:[k]) == type({})
53+
for name in keys(s:[k])
54+
if type(s:[k][name]) == type(function('tr')) && string(s:[k][name]) == sig
55+
return printf('%s.%s', k, name)
56+
endif
57+
endfor
58+
endif
59+
endfor
60+
return a:num
61+
endfunction
62+
endif

autoload/vital/__vimlparser__/VimlParser.vim

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,6 @@ function! s:import() abort
88
return s:
99
endfunction
1010

11-
function! s:numtoname(num)
12-
let sig = printf("function('%s')", a:num)
13-
for k in keys(s:)
14-
if type(s:[k]) == type({})
15-
for name in keys(s:[k])
16-
if type(s:[k][name]) == type(function('tr')) && string(s:[k][name]) == sig
17-
return printf('%s.%s', k, name)
18-
endif
19-
endfor
20-
endif
21-
endfor
22-
return a:num
23-
endfunction
24-
2511
let s:NIL = []
2612
let s:TRUE = 1
2713
let s:FALSE = 0

0 commit comments

Comments
 (0)