Skip to content

Commit 2f39c1d

Browse files
authored
Merge pull request #725 from vim-jp/liberate-from-redir
vitalizer: Liberate from 'redir'
2 parents 336d8ab + fa0eba0 commit 2f39c1d

File tree

2 files changed

+5
-26
lines changed

2 files changed

+5
-26
lines changed

autoload/vital/vital.vim

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,7 @@ function! s:_format_throwpoint(throwpoint) abort
186186
endfunction
187187

188188
function! s:_get_file_by_func_name(name) abort
189-
try
190-
redir => body
191-
silent execute 'verbose function' a:name
192-
finally
193-
redir END
194-
endtry
189+
let body = execute(printf('verbose function %s', a:name))
195190
let lines = split(body, "\n")
196191
let signature = matchstr(lines[0], '^\s*\zs.*')
197192
let file = matchstr(lines[1], '^\t\%(Last set from\|.\{-}:\)\s*\zs.*$')
@@ -265,7 +260,7 @@ function! s:_sid(path, filter_pattern) abort
265260
if has_key(s:cache_sid, unified_path)
266261
return s:cache_sid[unified_path]
267262
endif
268-
for line in filter(split(s:_execute(':scriptnames'), "\n"), 'v:val =~# a:filter_pattern')
263+
for line in filter(split(execute(':scriptnames'), "\n"), 'v:val =~# a:filter_pattern')
269264
let [_, sid, path; __] = matchlist(line, '^\s*\(\d\+\):\s\+\(.\+\)\s*$')
270265
if s:_unify_path(path) is# unified_path
271266
let s:cache_sid[unified_path] = sid
@@ -275,21 +270,6 @@ function! s:_sid(path, filter_pattern) abort
275270
return 0
276271
endfunction
277272

278-
" We want to use an execute() builtin function instead of s:_execute(),
279-
" however there is a bug in execute().
280-
" execute() returns empty string when it is called in
281-
" completion function of user defined ex command.
282-
" https://github.com/vim-jp/issues/issues/1129
283-
function! s:_execute(cmd) abort
284-
let [save_verbose, save_verbosefile] = [&verbose, &verbosefile]
285-
set verbose=0 verbosefile=
286-
redir => res
287-
silent! execute a:cmd
288-
redir END
289-
let [&verbose, &verbosefile] = [save_verbose, save_verbosefile]
290-
return res
291-
endfunction
292-
293273
if filereadable(expand('<sfile>:r') . '.VIM') " is case-insensitive or not
294274
let s:_unify_path_cache = {}
295275
" resolve() is slow, so we cache results.
@@ -314,7 +294,7 @@ endif
314294
" copied and modified from Vim.ScriptLocal
315295
let s:SNR = join(map(range(len("\<SNR>")), '"[\\x" . printf("%0x", char2nr("\<SNR>"[v:val])) . "]"'), '')
316296
function! s:sid2sfuncs(sid) abort
317-
let fs = split(s:_execute(printf(':function /^%s%s_', s:SNR, a:sid)), "\n")
297+
let fs = split(execute(printf(':function /^%s%s_', s:SNR, a:sid)), "\n")
318298
let r = {}
319299
let pattern = printf('\m^function\s<SNR>%d_\zs\w\{-}\ze(', a:sid)
320300
for fname in map(fs, 'matchstr(v:val, pattern)')

test/Interpreter/Brainf__k.vimspec

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ Describe Interpreter.Brainf__k
77

88
Describe .run_vim_parse_execute()
99
It shows hello world
10-
redir => output
11-
silent call BF.run_vim_parse_execute("++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.")
12-
redir END
10+
let script = '++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.'
11+
let output = execute(printf('call BF.run_vim_parse_execute("%s")', script))
1312
Assert Equals(output, "Hello World!\n")
1413
End
1514
End

0 commit comments

Comments
 (0)