Skip to content

Commit 41a6c6d

Browse files
committedMar 31, 2024
[vim] Upgrade vim-plug
1 parent 748c084 commit 41a6c6d

File tree

1 file changed

+87
-41
lines changed

1 file changed

+87
-41
lines changed
 

‎vim/.config/nvim/autoload/plug.vim

+87-41
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ endfunction
238238

239239
function! plug#begin(...)
240240
if a:0 > 0
241-
let s:plug_home_org = a:1
242241
let home = s:path(s:plug_fnamemodify(s:plug_expand(a:1), ':p'))
243242
elseif exists('g:plug_home')
244243
let home = s:path(g:plug_home)
@@ -391,6 +390,9 @@ function! plug#end()
391390
if !empty(types)
392391
augroup filetypedetect
393392
call s:source(s:rtp(plug), 'ftdetect/**/*.vim', 'after/ftdetect/**/*.vim')
393+
if has('nvim-0.5.0')
394+
call s:source(s:rtp(plug), 'ftdetect/**/*.lua', 'after/ftdetect/**/*.lua')
395+
endif
394396
augroup END
395397
endif
396398
for type in types
@@ -438,6 +440,9 @@ endfunction
438440

439441
function! s:load_plugin(spec)
440442
call s:source(s:rtp(a:spec), 'plugin/**/*.vim', 'after/plugin/**/*.vim')
443+
if has('nvim-0.5.0')
444+
call s:source(s:rtp(a:spec), 'plugin/**/*.lua', 'after/plugin/**/*.lua')
445+
endif
441446
endfunction
442447

443448
function! s:reload_plugins()
@@ -655,6 +660,9 @@ function! s:lod(names, types, ...)
655660
let rtp = s:rtp(g:plugs[name])
656661
for dir in a:types
657662
call s:source(rtp, dir.'/**/*.vim')
663+
if has('nvim-0.5.0') " see neovim#14686
664+
call s:source(rtp, dir.'/**/*.lua')
665+
endif
658666
endfor
659667
if a:0
660668
if !s:source(rtp, a:1) && !empty(s:glob(rtp, a:2))
@@ -869,7 +877,7 @@ function! s:lastline(msg)
869877
endfunction
870878

871879
function! s:new_window()
872-
execute get(g:, 'plug_window', 'vertical topleft new')
880+
execute get(g:, 'plug_window', '-tabnew')
873881
endfunction
874882

875883
function! s:plug_window_exists()
@@ -1031,6 +1039,11 @@ function! s:is_updated(dir)
10311039
endfunction
10321040

10331041
function! s:do(pull, force, todo)
1042+
if has('nvim')
1043+
" Reset &rtp to invalidate Neovim cache of loaded Lua modules
1044+
" See https://github.com/junegunn/vim-plug/pull/1157#issuecomment-1809226110
1045+
let &rtp = &rtp
1046+
endif
10341047
for [name, spec] in items(a:todo)
10351048
if !isdirectory(spec.dir)
10361049
continue
@@ -1092,12 +1105,14 @@ endfunction
10921105
function! s:checkout(spec)
10931106
let sha = a:spec.commit
10941107
let output = s:git_revision(a:spec.dir)
1108+
let error = 0
10951109
if !empty(output) && !s:hash_match(sha, s:lines(output)[0])
10961110
let credential_helper = s:git_version_requirement(2) ? '-c credential.helper= ' : ''
10971111
let output = s:system(
10981112
\ 'git '.credential_helper.'fetch --depth 999999 && git checkout '.plug#shellescape(sha).' --', a:spec.dir)
1113+
let error = v:shell_error
10991114
endif
1100-
return output
1115+
return [output, error]
11011116
endfunction
11021117

11031118
function! s:finish(pull)
@@ -1158,7 +1173,7 @@ function! s:update_impl(pull, force, args) abort
11581173
let threads = (len(args) > 0 && args[-1] =~ '^[1-9][0-9]*$') ?
11591174
\ remove(args, -1) : get(g:, 'plug_threads', 16)
11601175

1161-
let managed = filter(copy(g:plugs), 's:is_managed(v:key)')
1176+
let managed = filter(deepcopy(g:plugs), 's:is_managed(v:key)')
11621177
let todo = empty(args) ? filter(managed, '!v:val.frozen || !isdirectory(v:val.dir)') :
11631178
\ filter(managed, 'index(args, v:key) >= 0')
11641179

@@ -1292,9 +1307,11 @@ function! s:update_finish()
12921307
if !pos
12931308
continue
12941309
endif
1310+
let out = ''
1311+
let error = 0
12951312
if has_key(spec, 'commit')
12961313
call s:log4(name, 'Checking out '.spec.commit)
1297-
let out = s:checkout(spec)
1314+
let [out, error] = s:checkout(spec)
12981315
elseif has_key(spec, 'tag')
12991316
let tag = spec.tag
13001317
if tag =~ '\*'
@@ -1307,19 +1324,16 @@ function! s:update_finish()
13071324
endif
13081325
call s:log4(name, 'Checking out '.tag)
13091326
let out = s:system('git checkout -q '.plug#shellescape(tag).' -- 2>&1', spec.dir)
1310-
else
1311-
let branch = s:git_origin_branch(spec)
1312-
call s:log4(name, 'Merging origin/'.s:esc(branch))
1313-
let out = s:system('git checkout -q '.plug#shellescape(branch).' -- 2>&1'
1314-
\. (has_key(s:update.new, name) ? '' : ('&& git merge --ff-only '.plug#shellescape('origin/'.branch).' 2>&1')), spec.dir)
1327+
let error = v:shell_error
13151328
endif
1316-
if !v:shell_error && filereadable(spec.dir.'/.gitmodules') &&
1329+
if !error && filereadable(spec.dir.'/.gitmodules') &&
13171330
\ (s:update.force || has_key(s:update.new, name) || s:is_updated(spec.dir))
13181331
call s:log4(name, 'Updating submodules. This may take a while.')
13191332
let out .= s:bang('git submodule update --init --recursive'.s:submodule_opt.' 2>&1', spec.dir)
1333+
let error = v:shell_error
13201334
endif
13211335
let msg = s:format_message(v:shell_error ? 'x': '-', name, out)
1322-
if v:shell_error
1336+
if error
13231337
call add(s:update.errors, name)
13241338
call s:regress_bar()
13251339
silent execute pos 'd _'
@@ -1382,7 +1396,9 @@ function! s:job_out_cb(self, data) abort
13821396
if !self.running || self.tick % len(s:jobs) == 0
13831397
let bullet = self.running ? (self.new ? '+' : '*') : (self.error ? 'x' : '-')
13841398
let result = self.error ? join(self.lines, "\n") : s:last_non_empty_line(self.lines)
1385-
call s:log(bullet, self.name, result)
1399+
if len(result)
1400+
call s:log(bullet, self.name, result)
1401+
endif
13861402
endif
13871403
endfunction
13881404

@@ -1406,16 +1422,17 @@ function! s:nvim_cb(job_id, data, event) dict abort
14061422
\ s:job_cb('s:job_exit_cb', self, 0, a:data)
14071423
endfunction
14081424

1409-
function! s:spawn(name, cmd, opts)
1410-
let job = { 'name': a:name, 'running': 1, 'error': 0, 'lines': [''],
1411-
\ 'new': get(a:opts, 'new', 0) }
1425+
function! s:spawn(name, spec, queue, opts)
1426+
let job = { 'name': a:name, 'spec': a:spec, 'running': 1, 'error': 0, 'lines': [''],
1427+
\ 'new': get(a:opts, 'new', 0), 'queue': copy(a:queue) }
1428+
let Item = remove(job.queue, 0)
1429+
let argv = type(Item) == s:TYPE.funcref ? call(Item, [a:spec]) : Item
14121430
let s:jobs[a:name] = job
14131431

14141432
if s:nvim
14151433
if has_key(a:opts, 'dir')
14161434
let job.cwd = a:opts.dir
14171435
endif
1418-
let argv = a:cmd
14191436
call extend(job, {
14201437
\ 'on_stdout': function('s:nvim_cb'),
14211438
\ 'on_stderr': function('s:nvim_cb'),
@@ -1431,7 +1448,7 @@ function! s:spawn(name, cmd, opts)
14311448
\ 'Invalid arguments (or job table is full)']
14321449
endif
14331450
elseif s:vim8
1434-
let cmd = join(map(copy(a:cmd), 'plug#shellescape(v:val, {"script": 0})'))
1451+
let cmd = join(map(copy(argv), 'plug#shellescape(v:val, {"script": 0})'))
14351452
if has_key(a:opts, 'dir')
14361453
let cmd = s:with_cd(cmd, a:opts.dir, 0)
14371454
endif
@@ -1451,27 +1468,34 @@ function! s:spawn(name, cmd, opts)
14511468
let job.lines = ['Failed to start job']
14521469
endif
14531470
else
1454-
let job.lines = s:lines(call('s:system', has_key(a:opts, 'dir') ? [a:cmd, a:opts.dir] : [a:cmd]))
1471+
let job.lines = s:lines(call('s:system', has_key(a:opts, 'dir') ? [argv, a:opts.dir] : [argv]))
14551472
let job.error = v:shell_error != 0
14561473
let job.running = 0
14571474
endif
14581475
endfunction
14591476

14601477
function! s:reap(name)
1461-
let job = s:jobs[a:name]
1478+
let job = remove(s:jobs, a:name)
14621479
if job.error
14631480
call add(s:update.errors, a:name)
14641481
elseif get(job, 'new', 0)
14651482
let s:update.new[a:name] = 1
14661483
endif
1467-
let s:update.bar .= job.error ? 'x' : '='
14681484

1469-
let bullet = job.error ? 'x' : '-'
1485+
let more = len(get(job, 'queue', []))
1486+
let bullet = job.error ? 'x' : more ? (job.new ? '+' : '*') : '-'
14701487
let result = job.error ? join(job.lines, "\n") : s:last_non_empty_line(job.lines)
1471-
call s:log(bullet, a:name, empty(result) ? 'OK' : result)
1472-
call s:bar()
1488+
if len(result)
1489+
call s:log(bullet, a:name, result)
1490+
endif
14731491

1474-
call remove(s:jobs, a:name)
1492+
if !job.error && more
1493+
let job.spec.queue = job.queue
1494+
let s:update.todo[a:name] = job.spec
1495+
else
1496+
let s:update.bar .= job.error ? 'x' : '='
1497+
call s:bar()
1498+
endif
14751499
endfunction
14761500

14771501
function! s:bar()
@@ -1524,6 +1548,16 @@ function! s:update_vim()
15241548
call s:tick()
15251549
endfunction
15261550

1551+
function! s:checkout_command(spec)
1552+
let a:spec.branch = s:git_origin_branch(a:spec)
1553+
return ['git', 'checkout', '-q', a:spec.branch, '--']
1554+
endfunction
1555+
1556+
function! s:merge_command(spec)
1557+
let a:spec.branch = s:git_origin_branch(a:spec)
1558+
return ['git', 'merge', '--ff-only', 'origin/'.a:spec.branch]
1559+
endfunction
1560+
15271561
function! s:tick()
15281562
let pull = s:update.pull
15291563
let prog = s:progress_opt(s:nvim || s:vim8)
@@ -1538,13 +1572,18 @@ while 1 " Without TCO, Vim stack is bound to explode
15381572

15391573
let name = keys(s:update.todo)[0]
15401574
let spec = remove(s:update.todo, name)
1541-
let new = empty(globpath(spec.dir, '.git', 1))
1575+
let queue = get(spec, 'queue', [])
1576+
let new = empty(globpath(spec.dir, '.git', 1))
15421577

1543-
call s:log(new ? '+' : '*', name, pull ? 'Updating ...' : 'Installing ...')
1544-
redraw
1578+
if empty(queue)
1579+
call s:log(new ? '+' : '*', name, pull ? 'Updating ...' : 'Installing ...')
1580+
redraw
1581+
endif
15451582

15461583
let has_tag = has_key(spec, 'tag')
1547-
if !new
1584+
if len(queue)
1585+
call s:spawn(name, spec, queue, { 'dir': spec.dir })
1586+
elseif !new
15481587
let [error, _] = s:git_validate(spec, 0)
15491588
if empty(error)
15501589
if pull
@@ -1555,7 +1594,11 @@ while 1 " Without TCO, Vim stack is bound to explode
15551594
if !empty(prog)
15561595
call add(cmd, prog)
15571596
endif
1558-
call s:spawn(name, cmd, { 'dir': spec.dir })
1597+
let queue = [cmd, split('git remote set-head origin -a')]
1598+
if !has_tag && !has_key(spec, 'commit')
1599+
call extend(queue, [function('s:checkout_command'), function('s:merge_command')])
1600+
endif
1601+
call s:spawn(name, spec, queue, { 'dir': spec.dir })
15591602
else
15601603
let s:jobs[name] = { 'running': 0, 'lines': ['Already installed'], 'error': 0 }
15611604
endif
@@ -1570,7 +1613,7 @@ while 1 " Without TCO, Vim stack is bound to explode
15701613
if !empty(prog)
15711614
call add(cmd, prog)
15721615
endif
1573-
call s:spawn(name, extend(cmd, [spec.uri, s:trim(spec.dir)]), { 'new': 1 })
1616+
call s:spawn(name, spec, [extend(cmd, [spec.uri, s:trim(spec.dir)]), function('s:checkout_command'), function('s:merge_command')], { 'new': 1 })
15741617
endif
15751618

15761619
if !s:jobs[name].running
@@ -2346,18 +2389,21 @@ function! s:git_validate(spec, check_branch)
23462389
\ current_branch, origin_branch)
23472390
endif
23482391
if empty(err)
2349-
let [ahead, behind] = split(s:lastline(s:system([
2350-
\ 'git', 'rev-list', '--count', '--left-right',
2351-
\ printf('HEAD...origin/%s', origin_branch)
2352-
\ ], a:spec.dir)), '\t')
2353-
if !v:shell_error && ahead
2354-
if behind
2392+
let ahead_behind = split(s:lastline(s:system([
2393+
\ 'git', 'rev-list', '--count', '--left-right',
2394+
\ printf('HEAD...origin/%s', origin_branch)
2395+
\ ], a:spec.dir)), '\t')
2396+
if v:shell_error || len(ahead_behind) != 2
2397+
let err = "Failed to compare with the origin. The default branch might have changed.\nPlugClean required."
2398+
else
2399+
let [ahead, behind] = ahead_behind
2400+
if ahead && behind
23552401
" Only mention PlugClean if diverged, otherwise it's likely to be
23562402
" pushable (and probably not that messed up).
23572403
let err = printf(
23582404
\ "Diverged from origin/%s (%d commit(s) ahead and %d commit(s) behind!\n"
23592405
\ .'Backup local changes and run PlugClean and PlugUpdate to reinstall it.', origin_branch, ahead, behind)
2360-
else
2406+
elseif ahead
23612407
let err = printf("Ahead of origin/%s by %d commit(s).\n"
23622408
\ .'Cannot update until local changes are pushed.',
23632409
\ origin_branch, ahead)
@@ -2389,7 +2435,7 @@ function! s:clean(force)
23892435
let errs = {}
23902436
let [cnt, total] = [0, len(g:plugs)]
23912437
for [name, spec] in items(g:plugs)
2392-
if !s:is_managed(name)
2438+
if !s:is_managed(name) || get(spec, 'frozen', 0)
23932439
call add(dirs, spec.dir)
23942440
else
23952441
let [err, clean] = s:git_validate(spec, 1)
@@ -2637,8 +2683,8 @@ function! s:preview_commit()
26372683
return
26382684
endif
26392685

2640-
if exists('g:plug_pwindow') && !s:is_preview_window_open()
2641-
execute g:plug_pwindow
2686+
if !s:is_preview_window_open()
2687+
execute get(g:, 'plug_pwindow', 'vertical rightbelow new')
26422688
execute 'e' title
26432689
else
26442690
execute 'pedit' title

0 commit comments

Comments
 (0)