@@ -238,7 +238,6 @@ endfunction
238
238
239
239
function ! plug#begin (... )
240
240
if a: 0 > 0
241
- let s: plug_home_org = a: 1
242
241
let home = s: path (s: plug_fnamemodify (s: plug_expand (a: 1 ), ' :p' ))
243
242
elseif exists (' g:plug_home' )
244
243
let home = s: path (g: plug_home )
@@ -391,6 +390,9 @@ function! plug#end()
391
390
if ! empty (types)
392
391
augroup filetypedetect
393
392
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
394
396
augroup END
395
397
endif
396
398
for type in types
@@ -438,6 +440,9 @@ endfunction
438
440
439
441
function ! s: load_plugin (spec)
440
442
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
441
446
endfunction
442
447
443
448
function ! s: reload_plugins ()
@@ -655,6 +660,9 @@ function! s:lod(names, types, ...)
655
660
let rtp = s: rtp (g: plugs [name])
656
661
for dir in a: types
657
662
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
658
666
endfor
659
667
if a: 0
660
668
if ! s: source (rtp , a: 1 ) && ! empty (s: glob (rtp , a: 2 ))
@@ -869,7 +877,7 @@ function! s:lastline(msg)
869
877
endfunction
870
878
871
879
function ! s: new_window ()
872
- execute get (g: , ' plug_window' , ' vertical topleft new ' )
880
+ execute get (g: , ' plug_window' , ' -tabnew ' )
873
881
endfunction
874
882
875
883
function ! s: plug_window_exists ()
@@ -1031,6 +1039,11 @@ function! s:is_updated(dir)
1031
1039
endfunction
1032
1040
1033
1041
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
1034
1047
for [name, spec] in items (a: todo )
1035
1048
if ! isdirectory (spec.dir )
1036
1049
continue
@@ -1092,12 +1105,14 @@ endfunction
1092
1105
function ! s: checkout (spec)
1093
1106
let sha = a: spec .commit
1094
1107
let output = s: git_revision (a: spec .dir )
1108
+ let error = 0
1095
1109
if ! empty (output) && ! s: hash_match (sha, s: lines (output)[0 ])
1096
1110
let credential_helper = s: git_version_requirement (2 ) ? ' -c credential.helper= ' : ' '
1097
1111
let output = s: system (
1098
1112
\ ' git ' .credential_helper.' fetch --depth 999999 && git checkout ' .plug#shellescape (sha).' --' , a: spec .dir )
1113
+ let error = v: shell_error
1099
1114
endif
1100
- return output
1115
+ return [ output, error ]
1101
1116
endfunction
1102
1117
1103
1118
function ! s: finish (pull)
@@ -1158,7 +1173,7 @@ function! s:update_impl(pull, force, args) abort
1158
1173
let threads = (len (args ) > 0 && args [-1 ] = ~ ' ^[1-9][0-9]*$' ) ?
1159
1174
\ remove (args , -1 ) : get (g: , ' plug_threads' , 16 )
1160
1175
1161
- let managed = filter (copy (g: plugs ), ' s:is_managed(v:key)' )
1176
+ let managed = filter (deepcopy (g: plugs ), ' s:is_managed(v:key)' )
1162
1177
let todo = empty (args ) ? filter (managed, ' !v:val.frozen || !isdirectory(v:val.dir)' ) :
1163
1178
\ filter (managed, ' index(args, v:key) >= 0' )
1164
1179
@@ -1292,9 +1307,11 @@ function! s:update_finish()
1292
1307
if ! pos
1293
1308
continue
1294
1309
endif
1310
+ let out = ' '
1311
+ let error = 0
1295
1312
if has_key (spec, ' commit' )
1296
1313
call s: log4 (name, ' Checking out ' .spec.commit)
1297
- let out = s: checkout (spec)
1314
+ let [ out, error ] = s: checkout (spec)
1298
1315
elseif has_key (spec, ' tag' )
1299
1316
let tag = spec.tag
1300
1317
if tag = ~ ' \*'
@@ -1307,19 +1324,16 @@ function! s:update_finish()
1307
1324
endif
1308
1325
call s: log4 (name, ' Checking out ' .tag )
1309
1326
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
1315
1328
endif
1316
- if ! v: shell_error && filereadable (spec.dir .' /.gitmodules' ) &&
1329
+ if ! error && filereadable (spec.dir .' /.gitmodules' ) &&
1317
1330
\ (s: update .force || has_key (s: update .new , name) || s: is_updated (spec.dir ))
1318
1331
call s: log4 (name, ' Updating submodules. This may take a while.' )
1319
1332
let out .= s: bang (' git submodule update --init --recursive' .s: submodule_opt .' 2>&1' , spec.dir )
1333
+ let error = v: shell_error
1320
1334
endif
1321
1335
let msg = s: format_message (v: shell_error ? ' x' : ' -' , name, out)
1322
- if v: shell_error
1336
+ if error
1323
1337
call add (s: update .errors, name)
1324
1338
call s: regress_bar ()
1325
1339
silent execute pos ' d _'
@@ -1382,7 +1396,9 @@ function! s:job_out_cb(self, data) abort
1382
1396
if ! self .running || self .tick % len (s: jobs ) == 0
1383
1397
let bullet = self .running ? (self .new ? ' +' : ' *' ) : (self .error ? ' x' : ' -' )
1384
1398
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
1386
1402
endif
1387
1403
endfunction
1388
1404
@@ -1406,16 +1422,17 @@ function! s:nvim_cb(job_id, data, event) dict abort
1406
1422
\ s: job_cb (' s:job_exit_cb' , self , 0 , a: data )
1407
1423
endfunction
1408
1424
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
1412
1430
let s: jobs [a: name ] = job
1413
1431
1414
1432
if s: nvim
1415
1433
if has_key (a: opts , ' dir' )
1416
1434
let job.cwd = a: opts .dir
1417
1435
endif
1418
- let argv = a: cmd
1419
1436
call extend (job, {
1420
1437
\ ' on_stdout' : function (' s:nvim_cb' ),
1421
1438
\ ' on_stderr' : function (' s:nvim_cb' ),
@@ -1431,7 +1448,7 @@ function! s:spawn(name, cmd, opts)
1431
1448
\ ' Invalid arguments (or job table is full)' ]
1432
1449
endif
1433
1450
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})' ))
1435
1452
if has_key (a: opts , ' dir' )
1436
1453
let cmd = s: with_cd (cmd, a: opts .dir , 0 )
1437
1454
endif
@@ -1451,27 +1468,34 @@ function! s:spawn(name, cmd, opts)
1451
1468
let job.lines = [' Failed to start job' ]
1452
1469
endif
1453
1470
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 ]))
1455
1472
let job.error = v: shell_error != 0
1456
1473
let job.running = 0
1457
1474
endif
1458
1475
endfunction
1459
1476
1460
1477
function ! s: reap (name)
1461
- let job = s: jobs[ a: name]
1478
+ let job = remove ( s: jobs, a: name)
1462
1479
if job.error
1463
1480
call add (s: update .errors, a: name )
1464
1481
elseif get (job, ' new' , 0 )
1465
1482
let s: update .new [a: name ] = 1
1466
1483
endif
1467
- let s: update .bar .= job.error ? ' x' : ' ='
1468
1484
1469
- let bullet = job.error ? ' x' : ' -'
1485
+ let more = len (get (job, ' queue' , []))
1486
+ let bullet = job.error ? ' x' : more ? (job.new ? ' +' : ' *' ) : ' -'
1470
1487
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
1473
1491
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
1475
1499
endfunction
1476
1500
1477
1501
function ! s: bar ()
@@ -1524,6 +1548,16 @@ function! s:update_vim()
1524
1548
call s: tick ()
1525
1549
endfunction
1526
1550
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
+
1527
1561
function ! s: tick ()
1528
1562
let pull = s: update .pull
1529
1563
let prog = s: progress_opt (s: nvim || s: vim8 )
@@ -1538,13 +1572,18 @@ while 1 " Without TCO, Vim stack is bound to explode
1538
1572
1539
1573
let name = keys (s: update .todo )[0 ]
1540
1574
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 ))
1542
1577
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
1545
1582
1546
1583
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
1548
1587
let [error , _] = s: git_validate (spec, 0 )
1549
1588
if empty (error )
1550
1589
if pull
@@ -1555,7 +1594,11 @@ while 1 " Without TCO, Vim stack is bound to explode
1555
1594
if ! empty (prog)
1556
1595
call add (cmd, prog)
1557
1596
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 })
1559
1602
else
1560
1603
let s: jobs [name] = { ' running' : 0 , ' lines' : [' Already installed' ], ' error' : 0 }
1561
1604
endif
@@ -1570,7 +1613,7 @@ while 1 " Without TCO, Vim stack is bound to explode
1570
1613
if ! empty (prog)
1571
1614
call add (cmd, prog)
1572
1615
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 })
1574
1617
endif
1575
1618
1576
1619
if ! s: jobs [name].running
@@ -2346,18 +2389,21 @@ function! s:git_validate(spec, check_branch)
2346
2389
\ current_branch, origin_branch)
2347
2390
endif
2348
2391
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.\n PlugClean required."
2398
+ else
2399
+ let [ahead, behind] = ahead_behind
2400
+ if ahead && behind
2355
2401
" Only mention PlugClean if diverged, otherwise it's likely to be
2356
2402
" pushable (and probably not that messed up).
2357
2403
let err = printf (
2358
2404
\ " Diverged from origin/%s (%d commit(s) ahead and %d commit(s) behind!\n "
2359
2405
\ .' Backup local changes and run PlugClean and PlugUpdate to reinstall it.' , origin_branch, ahead, behind)
2360
- else
2406
+ elseif ahead
2361
2407
let err = printf (" Ahead of origin/%s by %d commit(s).\n "
2362
2408
\ .' Cannot update until local changes are pushed.' ,
2363
2409
\ origin_branch, ahead)
@@ -2389,7 +2435,7 @@ function! s:clean(force)
2389
2435
let errs = {}
2390
2436
let [cnt, total] = [0 , len (g: plugs )]
2391
2437
for [name, spec] in items (g: plugs )
2392
- if ! s: is_managed (name)
2438
+ if ! s: is_managed (name) || get (spec, ' frozen ' , 0 )
2393
2439
call add (dirs, spec.dir )
2394
2440
else
2395
2441
let [err, clean] = s: git_validate (spec, 1 )
@@ -2637,8 +2683,8 @@ function! s:preview_commit()
2637
2683
return
2638
2684
endif
2639
2685
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 ' )
2642
2688
execute ' e' title
2643
2689
else
2644
2690
execute ' pedit' title
0 commit comments