Skip to content

Commit d8b4a60

Browse files
committed
Update vital and fix inappropriate syntax reset
1 parent b1acf67 commit d8b4a60

File tree

5 files changed

+219
-71
lines changed

5 files changed

+219
-71
lines changed

autoload/vital/_easymotion.vim

Lines changed: 49 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
let s:self_version = expand('<sfile>:t:r')
22
let s:self_file = expand('<sfile>')
3-
4-
" Note: The extra argument to globpath() was added in Patch 7.2.051.
5-
let s:globpath_third_arg = v:version > 702 || v:version == 702 && has('patch51')
3+
let s:base_dir = expand('<sfile>:h')
64

75
let s:loaded = {}
86
let s:cache_module_path = {}
97
let s:cache_sid = {}
108

11-
let s:_vital_files_cache_runtimepath = ''
12-
let s:_vital_files_cache = []
139
let s:_unify_path_cache = {}
1410

11+
function! s:plugin_name() abort
12+
let info_file = get(split(glob(s:base_dir . '/*.vital', 1), "\n"), 0, '')
13+
return fnamemodify(info_file, ':t:r')
14+
endfunction
15+
16+
function! s:vital_files() abort
17+
if !exists('s:vital_files')
18+
let s:vital_files =
19+
\ map(
20+
\ s:plugin_name() ==# 'vital'
21+
\ ? s:_global_vital_files()
22+
\ : s:_self_vital_files(),
23+
\ 'fnamemodify(v:val, ":p:gs?[\\\\/]?/?")')
24+
endif
25+
return copy(s:vital_files)
26+
endfunction
27+
1528
function! s:import(name, ...) abort
1629
let target = {}
1730
let functions = []
@@ -67,42 +80,19 @@ function! s:unload() abort
6780
let s:loaded = {}
6881
let s:cache_sid = {}
6982
let s:cache_module_path = {}
83+
unlet! s:vital_files
7084
endfunction
7185

7286
function! s:exists(name) abort
7387
return s:_get_module_path(a:name) !=# ''
7488
endfunction
7589

7690
function! s:search(pattern) abort
77-
let paths = s:_vital_files(a:pattern)
91+
let paths = s:_extract_files(a:pattern, s:vital_files())
7892
let modules = sort(map(paths, 's:_file2module(v:val)'))
7993
return s:_uniq(modules)
8094
endfunction
8195

82-
function! s:expand_modules(entry, all) abort
83-
if type(a:entry) == type([])
84-
let candidates = s:_concat(map(copy(a:entry), 's:search(v:val)'))
85-
if empty(candidates)
86-
throw printf('vital: Any of module %s is not found', string(a:entry))
87-
endif
88-
if eval(join(map(copy(candidates), 'has_key(a:all, v:val)'), '+'))
89-
let modules = []
90-
else
91-
let modules = [candidates[0]]
92-
endif
93-
else
94-
let modules = s:search(a:entry)
95-
if empty(modules)
96-
throw printf('vital: Module %s is not found', a:entry)
97-
endif
98-
endif
99-
call filter(modules, '!has_key(a:all, v:val)')
100-
for module in modules
101-
let a:all[module] = 1
102-
endfor
103-
return modules
104-
endfunction
105-
10696
function! s:_import(name) abort
10797
if type(a:name) == type(0)
10898
return s:_build_module(a:name)
@@ -134,10 +124,8 @@ function! s:_get_module_path(name) abort
134124
if s:_is_absolute_path(a:name) && filereadable(a:name)
135125
return a:name
136126
endif
137-
if a:name ==# ''
138-
let paths = [s:self_file]
139-
elseif a:name =~# '\v^\u\w*%(\.\u\w*)*$'
140-
let paths = s:_vital_files(a:name)
127+
if a:name =~# '\v^\u\w*%(\.\u\w*)*$'
128+
let paths = s:_extract_files(a:name, s:vital_files())
141129
else
142130
throw 'vital: Invalid module name: ' . a:name
143131
endif
@@ -154,8 +142,8 @@ function! s:_get_sid_by_script(path) abort
154142
endif
155143

156144
let path = s:_unify_path(a:path)
157-
for line in filter(split(s:_redir('scriptnames'), "\n"),
158-
\ 'stridx(v:val, s:self_version) > 0')
145+
let p = 'stridx(v:val, s:self_version) > 0 || stridx(v:val, "__latest__") > 0'
146+
for line in filter(split(s:_redir('scriptnames'), "\n"), p)
159147
let list = matchlist(line, '^\s*\(\d\+\):\s\+\(.\+\)\s*$')
160148
if !empty(list) && s:_unify_path(list[2]) ==# path
161149
let s:cache_sid[a:path] = list[1] - 0
@@ -191,28 +179,21 @@ else
191179
endfunction
192180
endif
193181

194-
if s:globpath_third_arg
195-
function! s:_runtime_files(path) abort
196-
return split(globpath(&runtimepath, a:path, 1), "\n")
197-
endfunction
198-
else
199-
function! s:_runtime_files(path) abort
200-
return split(globpath(&runtimepath, a:path), "\n")
201-
endfunction
202-
endif
182+
function! s:_self_vital_files() abort
183+
let base = s:base_dir . '/*/**/*.vim'
184+
return split(glob(base, 1), "\n")
185+
endfunction
203186

204-
function! s:_vital_files(pattern) abort
205-
if s:_vital_files_cache_runtimepath !=# &runtimepath
206-
let path = printf('autoload/vital/%s/**/*.vim', s:self_version)
207-
let s:_vital_files_cache = s:_runtime_files(path)
208-
let mod = ':p:gs?[\\/]\+?/?'
209-
call map(s:_vital_files_cache, 'fnamemodify(v:val, mod)')
210-
let s:_vital_files_cache_runtimepath = &runtimepath
211-
endif
212-
let target = substitute(a:pattern, '\.', '/', 'g')
213-
let target = substitute(target, '\*', '[^/]*', 'g')
214-
let regexp = printf('autoload/vital/%s/%s.vim', s:self_version, target)
215-
return filter(copy(s:_vital_files_cache), 'v:val =~# regexp')
187+
function! s:_global_vital_files() abort
188+
let pattern = 'autoload/vital/__latest__/**/*.vim'
189+
return split(globpath(&runtimepath, pattern, 1), "\n")
190+
endfunction
191+
192+
function! s:_extract_files(pattern, files) abort
193+
let tr = {'.': '/', '*': '[^/]*', '**': '.*'}
194+
let target = substitute(a:pattern, '\.\|\*\*\?', '\=tr[submatch(0)]', 'g')
195+
let regexp = printf('autoload/vital/[^/]\+/%s.vim$', target)
196+
return filter(a:files, 'v:val =~# regexp')
216197
endfunction
217198

218199
" Copy from System.Filepath
@@ -241,10 +222,17 @@ function! s:_build_module(sid) abort
241222
call module._vital_created(module)
242223
endif
243224
let export_module = filter(copy(module), 'v:key =~# "^\\a"')
225+
" Cache module before calling module.vital_debug() to avoid cyclic
226+
" dependences but remove the cache if module._vital_loaded() fails.
244227
let s:loaded[a:sid] = get(g:, 'vital_debug', 0) ? module : export_module
245228
if has_key(module, '_vital_loaded')
246-
let V = vital#{s:self_version}#new()
247-
call module._vital_loaded(V)
229+
try
230+
let V = vital#{s:self_version}#new()
231+
call module._vital_loaded(V)
232+
catch
233+
unlet s:loaded[a:sid]
234+
throw 'vital: fail to call ._vital_loaded(): ' . v:exception
235+
endtry
248236
endif
249237
return copy(s:loaded[a:sid])
250238
endfunction
@@ -286,14 +274,6 @@ else
286274
endfunction
287275
endif
288276

289-
function! s:_concat(lists) abort
290-
let result_list = []
291-
for list in a:lists
292-
let result_list += list
293-
endfor
294-
return result_list
295-
endfunction
296-
297277
function! s:_redir(cmd) abort
298278
let [save_verbose, save_verbosefile] = [&verbose, &verbosefile]
299279
set verbose=0 verbosefile=
@@ -305,5 +285,6 @@ function! s:_redir(cmd) abort
305285
endfunction
306286

307287
function! vital#{s:self_version}#new() abort
308-
return s:_import('')
288+
let sid = s:_get_sid_by_script(s:self_file)
289+
return s:_build_module(sid)
309290
endfunction

autoload/vital/_easymotion/HitAHint/Motion.vim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ function! s:Hinter._show_hint_for_win(winnr) abort
507507
let hints += self._show_hint_for_line(a:winnr, lnum, col2hint)
508508
endfor
509509
" Restore syntax and show hints after replacing all lines for performance.
510-
if !self.config.do_shade
510+
if !s:can_preserve_syntax && !self.config.do_shade
511511
let &l:syntax = self.save_syntax[a:winnr]
512512
endif
513513
execute 'highlight! link Conceal' self.config.highlight.target
@@ -778,3 +778,4 @@ endfunction
778778
function! s:throw(message) abort
779779
throw 'vital: HitAHint.Motion: ' . a:message
780780
endfunction
781+

autoload/vital/_easymotion/Vim/Buffer.vim

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ set cpo&vim
44
function! s:_vital_loaded(V) abort
55
let s:V = a:V
66
let s:P = s:V.import('Prelude')
7+
let s:G = s:V.import('Vim.Guard')
78
endfunction
89

910
function! s:_vital_depends() abort
10-
return ['Prelude']
11+
return ['Prelude', 'Vim.Guard']
1112
endfunction
1213

1314
if exists('*getcmdwintype')
@@ -89,6 +90,54 @@ function! s:get_last_selected() abort
8990
endif
9091
endfunction
9192

93+
function! s:read_content(content, ...) abort
94+
let options = extend({
95+
\ 'tempfile': '',
96+
\ 'fileformat': '',
97+
\ 'encoding': '',
98+
\ 'binary': 0,
99+
\ 'nobinary': 0,
100+
\ 'bad': '',
101+
\ 'edit': 0,
102+
\}, get(a:000, 0, {}))
103+
let tempfile = empty(options.tempfile) ? tempname() : options.tempfile
104+
let optnames = [
105+
\ empty(options.fileformat) ? '' : '++ff=' . options.fileformat,
106+
\ empty(options.encoding) ? '' : '++enc=' . options.encoding,
107+
\ empty(options.binary) ? '' : '++bin',
108+
\ empty(options.nobinary) ? '' : '++nobin',
109+
\ empty(options.bad) ? '' : '++bad=' . options.bad,
110+
\ empty(options.edit) ? '' : '++edit',
111+
\]
112+
let optname = join(filter(optnames, '!empty(v:val)'))
113+
try
114+
call writefile(a:content, tempfile)
115+
execute printf('keepalt keepjumps read %s%s',
116+
\ empty(optname) ? '' : optname . ' ',
117+
\ fnameescape(tempfile),
118+
\)
119+
finally
120+
call delete(tempfile)
121+
endtry
122+
endfunction
123+
124+
function! s:edit_content(content, ...) abort
125+
let options = extend({
126+
\ 'edit': 1,
127+
\}, get(a:000, 0, {}))
128+
let guard = s:G.store('&l:modifiable')
129+
let saved_view = winsaveview()
130+
try
131+
let &l:modifiable=1
132+
silent keepjumps %delete _
133+
silent call s:read_content(a:content, options)
134+
silent keepjumps 1delete _
135+
finally
136+
keepjump call winrestview(saved_view)
137+
call guard.restore()
138+
endtry
139+
setlocal nomodified
140+
endfunction
92141

93142
let &cpo = s:save_cpo
94143
unlet s:save_cpo
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
let s:save_cpo = &cpo
2+
set cpo&vim
3+
4+
" Use a Funcref as a special term UNDEFINED
5+
function! s:undefined() abort
6+
return 'undefined'
7+
endfunction
8+
let s:UNDEFINED = function('s:undefined')
9+
10+
function! s:_vital_created(module) abort
11+
" define constant variables
12+
if !exists('s:const')
13+
let s:const = {}
14+
let s:const.is_local_variable_supported =
15+
\ v:version > 703 || (v:version == 703 && has('patch560'))
16+
lockvar s:const
17+
endif
18+
call extend(a:module, s:const)
19+
endfunction
20+
function! s:_throw(msg) abort
21+
throw printf('vital: Vim.Guard: %s', a:msg)
22+
endfunction
23+
24+
let s:option = {}
25+
function! s:_new_option(name) abort
26+
if a:name !~# '^&'
27+
call s:_throw(printf(
28+
\'An option name "%s" requires to be started from "&"', a:name
29+
\))
30+
elseif !exists(a:name)
31+
call s:_throw(printf(
32+
\'An option name "%s" does not exist', a:name
33+
\))
34+
endif
35+
let option = copy(s:option)
36+
let option.name = a:name
37+
let option.value = eval(a:name)
38+
return option
39+
endfunction
40+
function! s:option.restore() abort
41+
execute printf('let %s = %s', self.name, string(self.value))
42+
endfunction
43+
44+
let s:variable = {}
45+
function! s:_new_variable(name, ...) abort
46+
if a:0 == 0
47+
let m = matchlist(a:name, '^\([bwtg]:\)\(.*\)$')
48+
if empty(m)
49+
call s:_throw(printf(
50+
\ join([
51+
\ 'An variable name "%s" requires to start from b:, w:, t:, or g:',
52+
\ 'while no {namespace} is specified',
53+
\ ]),
54+
\ a:name,
55+
\))
56+
endif
57+
let [prefix, name] = m[1 : 2]
58+
let namespace = eval(prefix)
59+
else
60+
let name = a:name
61+
let namespace = a:1
62+
endif
63+
let variable = copy(s:variable)
64+
let variable.name = name
65+
let variable.value = get(namespace, name, s:UNDEFINED)
66+
let variable.value =
67+
\ type(variable.value) == type({}) || type(variable.value) == type([])
68+
\ ? deepcopy(variable.value)
69+
\ : variable.value
70+
let variable._namespace = namespace
71+
return variable
72+
endfunction
73+
function! s:variable.restore() abort
74+
" unlet the variable to prevent variable type mis-match in case
75+
silent! unlet! self._namespace[self.name]
76+
if type(self.value) == type(s:UNDEFINED) && self.value == s:UNDEFINED
77+
" do nothing, leave the variable as undefined
78+
else
79+
let self._namespace[self.name] = self.value
80+
endif
81+
endfunction
82+
83+
let s:guard = {}
84+
function! s:store(...) abort
85+
let resources = []
86+
for meta in a:000
87+
if type(meta) == type([])
88+
call add(resources, call('s:_new_variable', meta))
89+
elseif type(meta) == type('')
90+
if meta =~# '^[bwtgls]:'
91+
" Note:
92+
" To improve an error message, handle l:XXX or s:XXX as well
93+
call add(resources, s:_new_variable(meta))
94+
elseif meta =~# '^&'
95+
call add(resources, s:_new_option(meta))
96+
else
97+
call s:_throw(printf(
98+
\ 'Unknown option or variable "%s" was specified',
99+
\ meta
100+
\))
101+
endif
102+
endif
103+
unlet meta
104+
endfor
105+
let guard = copy(s:guard)
106+
let guard._resources = resources
107+
return guard
108+
endfunction
109+
function! s:guard.restore() abort
110+
for resource in self._resources
111+
call resource.restore()
112+
endfor
113+
endfunction
114+
115+
let &cpo = s:save_cpo
116+
unlet! s:save_cpo
117+
" vim:set et ts=2 sts=2 sw=2 tw=0 fdm=marker:

autoload/vital/easymotion.vital

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
easymotion
2-
65c9afb0799cb950cbaf9258aefc6c3ad700a98f
2+
e083c2e654d057a09b3e18dfbb728b41de89f4a1
33

44
Over.Commandline.Base
55
Over.Commandline.Modules.Cancel

0 commit comments

Comments
 (0)