comparison .shared/.vim/autoload/plug.vim @ 304:ce9014cb4240

vim plugin update
author Steve Huston <huston@princeton.edu>
date Fri, 02 May 2025 16:28:10 -0400
parents df0b24d4fabd
children
comparison
equal deleted inserted replaced
303:d29c29690818 304:ce9014cb4240
1 " vim-plug: Vim plugin manager 1 " vim-plug: Vim plugin manager
2 " ============================ 2 " ============================
3 " 3 "
4 " Download plug.vim and put it in ~/.vim/autoload 4 " 1. Download plug.vim and put it in 'autoload' directory
5 " 5 "
6 " # Vim
6 " curl -fLo ~/.vim/autoload/plug.vim --create-dirs \ 7 " curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
7 " https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim 8 " https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
8 " 9 "
9 " Edit your .vimrc 10 " # Neovim
11 " sh -c 'curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs \
12 " https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
10 " 13 "
11 " call plug#begin('~/.vim/plugged') 14 " 2. Add a vim-plug section to your ~/.vimrc (or ~/.config/nvim/init.vim for Neovim)
12 " 15 "
13 " " Make sure you use single quotes 16 " call plug#begin()
14 " 17 "
15 " " Shorthand notation; fetches https://github.com/junegunn/vim-easy-align 18 " " List your plugins here
16 " Plug 'junegunn/vim-easy-align' 19 " Plug 'tpope/vim-sensible'
17 " 20 "
18 " " Any valid git URL is allowed
19 " Plug 'https://github.com/junegunn/vim-github-dashboard.git'
20 "
21 " " Multiple Plug commands can be written in a single line using | separators
22 " Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'
23 "
24 " " On-demand loading
25 " Plug 'preservim/nerdtree', { 'on': 'NERDTreeToggle' }
26 " Plug 'tpope/vim-fireplace', { 'for': 'clojure' }
27 "
28 " " Using a non-default branch
29 " Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' }
30 "
31 " " Using a tagged release; wildcard allowed (requires git 1.9.2 or above)
32 " Plug 'fatih/vim-go', { 'tag': '*' }
33 "
34 " " Plugin options
35 " Plug 'nsf/gocode', { 'tag': 'v.20150303', 'rtp': 'vim' }
36 "
37 " " Plugin outside ~/.vim/plugged with post-update hook
38 " Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
39 "
40 " " Unmanaged plugin (manually installed and updated)
41 " Plug '~/my-prototype-plugin'
42 "
43 " " Initialize plugin system
44 " call plug#end() 21 " call plug#end()
45 " 22 "
46 " Then reload .vimrc and :PlugInstall to install plugins. 23 " 3. Reload the file or restart Vim, then you can,
47 " 24 "
48 " Plug options: 25 " :PlugInstall to install plugins
26 " :PlugUpdate to update plugins
27 " :PlugDiff to review the changes from the last update
28 " :PlugClean to remove plugins no longer in the list
49 " 29 "
50 "| Option | Description | 30 " For more information, see https://github.com/junegunn/vim-plug
51 "| ----------------------- | ------------------------------------------------ |
52 "| `branch`/`tag`/`commit` | Branch/tag/commit of the repository to use |
53 "| `rtp` | Subdirectory that contains Vim plugin |
54 "| `dir` | Custom directory for the plugin |
55 "| `as` | Use different name for the plugin |
56 "| `do` | Post-update hook (string or funcref) |
57 "| `on` | On-demand loading: Commands or `<Plug>`-mappings |
58 "| `for` | On-demand loading: File types |
59 "| `frozen` | Do not update unless explicitly specified |
60 "
61 " More information: https://github.com/junegunn/vim-plug
62 " 31 "
63 " 32 "
64 " Copyright (c) 2017 Junegunn Choi 33 " Copyright (c) 2024 Junegunn Choi
65 " 34 "
66 " MIT License 35 " MIT License
67 " 36 "
68 " Permission is hereby granted, free of charge, to any person obtaining 37 " Permission is hereby granted, free of charge, to any person obtaining
69 " a copy of this software and associated documentation files (the 38 " a copy of this software and associated documentation files (the
236 return s:plug_call('tempname') 205 return s:plug_call('tempname')
237 endfunction 206 endfunction
238 207
239 function! plug#begin(...) 208 function! plug#begin(...)
240 if a:0 > 0 209 if a:0 > 0
241 let s:plug_home_org = a:1
242 let home = s:path(s:plug_fnamemodify(s:plug_expand(a:1), ':p')) 210 let home = s:path(s:plug_fnamemodify(s:plug_expand(a:1), ':p'))
243 elseif exists('g:plug_home') 211 elseif exists('g:plug_home')
244 let home = s:path(g:plug_home) 212 let home = s:path(g:plug_home)
245 elseif has('nvim') 213 elseif has('nvim')
246 let home = stdpath('data') . '/plugged' 214 let home = stdpath('data') . '/plugged'
402 endif 370 endif
403 endfor 371 endfor
404 372
405 for [cmd, names] in items(lod.cmd) 373 for [cmd, names] in items(lod.cmd)
406 execute printf( 374 execute printf(
407 \ 'command! -nargs=* -range -bang -complete=file %s call s:lod_cmd(%s, "<bang>", <line1>, <line2>, <q-args>, %s)', 375 \ has('patch-7.4.1898')
408 \ cmd, string(cmd), string(names)) 376 \ ? 'command! -nargs=* -range -bang -complete=file %s call s:lod_cmd(%s, "<bang>", <line1>, <line2>, <q-args>, <q-mods> ,%s)'
377 \ : 'command! -nargs=* -range -bang -complete=file %s call s:lod_cmd(%s, "<bang>", <line1>, <line2>, <q-args>, %s)'
378 \ , cmd, string(cmd), string(names))
409 endfor 379 endfor
410 380
411 for [map, names] in items(lod.map) 381 for [map, names] in items(lod.map)
412 for [mode, map_prefix, key_prefix] in 382 for [mode, map_prefix, key_prefix] in
413 \ [['i', '<C-\><C-O>', ''], ['n', '', ''], ['v', '', 'gv'], ['o', '', '']] 383 \ [['i', '<C-\><C-O>', ''], ['n', '', ''], ['v', '', 'gv'], ['o', '', '']]
681 execute 'autocmd! PlugLOD FileType' a:pat 651 execute 'autocmd! PlugLOD FileType' a:pat
682 call s:doautocmd('filetypeplugin', 'FileType') 652 call s:doautocmd('filetypeplugin', 'FileType')
683 call s:doautocmd('filetypeindent', 'FileType') 653 call s:doautocmd('filetypeindent', 'FileType')
684 endfunction 654 endfunction
685 655
686 function! s:lod_cmd(cmd, bang, l1, l2, args, names) 656 if has('patch-7.4.1898')
687 call s:lod(a:names, ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin']) 657 function! s:lod_cmd(cmd, bang, l1, l2, args, mods, names)
688 call s:dobufread(a:names) 658 call s:lod(a:names, ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin'])
689 execute printf('%s%s%s %s', (a:l1 == a:l2 ? '' : (a:l1.','.a:l2)), a:cmd, a:bang, a:args) 659 call s:dobufread(a:names)
690 endfunction 660 execute printf('%s %s%s%s %s', a:mods, (a:l1 == a:l2 ? '' : (a:l1.','.a:l2)), a:cmd, a:bang, a:args)
661 endfunction
662 else
663 function! s:lod_cmd(cmd, bang, l1, l2, args, names)
664 call s:lod(a:names, ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin'])
665 call s:dobufread(a:names)
666 execute printf('%s%s%s %s', (a:l1 == a:l2 ? '' : (a:l1.','.a:l2)), a:cmd, a:bang, a:args)
667 endfunction
668 endif
691 669
692 function! s:lod_map(map, names, with_prefix, prefix) 670 function! s:lod_map(map, names, with_prefix, prefix)
693 call s:lod(a:names, ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin']) 671 call s:lod(a:names, ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin'])
694 call s:dobufread(a:names) 672 call s:dobufread(a:names)
695 let extra = '' 673 let extra = ''
813 endfunction 791 endfunction
814 792
815 function! s:syntax() 793 function! s:syntax()
816 syntax clear 794 syntax clear
817 syntax region plug1 start=/\%1l/ end=/\%2l/ contains=plugNumber 795 syntax region plug1 start=/\%1l/ end=/\%2l/ contains=plugNumber
818 syntax region plug2 start=/\%2l/ end=/\%3l/ contains=plugBracket,plugX 796 syntax region plug2 start=/\%2l/ end=/\%3l/ contains=plugBracket,plugX,plugAbort
819 syn match plugNumber /[0-9]\+[0-9.]*/ contained 797 syn match plugNumber /[0-9]\+[0-9.]*/ contained
820 syn match plugBracket /[[\]]/ contained 798 syn match plugBracket /[[\]]/ contained
821 syn match plugX /x/ contained 799 syn match plugX /x/ contained
800 syn match plugAbort /\~/ contained
822 syn match plugDash /^-\{1}\ / 801 syn match plugDash /^-\{1}\ /
823 syn match plugPlus /^+/ 802 syn match plugPlus /^+/
824 syn match plugStar /^*/ 803 syn match plugStar /^*/
825 syn match plugMessage /\(^- \)\@<=.*/ 804 syn match plugMessage /\(^- \)\@<=.*/
826 syn match plugName /\(^- \)\@<=[^ ]*:/ 805 syn match plugName /\(^- \)\@<=[^ ]*:/
841 syn keyword Function PlugInstall PlugStatus PlugUpdate PlugClean 820 syn keyword Function PlugInstall PlugStatus PlugUpdate PlugClean
842 hi def link plug1 Title 821 hi def link plug1 Title
843 hi def link plug2 Repeat 822 hi def link plug2 Repeat
844 hi def link plugH2 Type 823 hi def link plugH2 Type
845 hi def link plugX Exception 824 hi def link plugX Exception
825 hi def link plugAbort Ignore
846 hi def link plugBracket Structure 826 hi def link plugBracket Structure
847 hi def link plugNumber Number 827 hi def link plugNumber Number
848 828
849 hi def link plugDash Special 829 hi def link plugDash Special
850 hi def link plugPlus Constant 830 hi def link plugPlus Constant
938 if exists(evar) 918 if exists(evar)
939 throw evar.' detected. Cannot proceed.' 919 throw evar.' detected. Cannot proceed.'
940 endif 920 endif
941 endfor 921 endfor
942 922
943 call s:job_abort() 923 call s:job_abort(0)
944 if s:switch_in() 924 if s:switch_in()
945 if b:plug_preview == 1 925 if b:plug_preview == 1
946 pc 926 pc
947 endif 927 endif
948 enew 928 enew
974 954
975 function! s:close_pane() 955 function! s:close_pane()
976 if b:plug_preview == 1 956 if b:plug_preview == 1
977 pc 957 pc
978 let b:plug_preview = -1 958 let b:plug_preview = -1
959 elseif exists('s:jobs') && !empty(s:jobs)
960 call s:job_abort(1)
979 else 961 else
980 bd 962 bd
981 endif 963 endif
982 endfunction 964 endfunction
983 965
1101 1083
1102 function! s:hash_match(a, b) 1084 function! s:hash_match(a, b)
1103 return stridx(a:a, a:b) == 0 || stridx(a:b, a:a) == 0 1085 return stridx(a:a, a:b) == 0 || stridx(a:b, a:a) == 0
1104 endfunction 1086 endfunction
1105 1087
1088 function! s:disable_credential_helper()
1089 return s:git_version_requirement(2) && get(g:, 'plug_disable_credential_helper', 1)
1090 endfunction
1091
1106 function! s:checkout(spec) 1092 function! s:checkout(spec)
1107 let sha = a:spec.commit 1093 let sha = a:spec.commit
1108 let output = s:git_revision(a:spec.dir) 1094 let output = s:git_revision(a:spec.dir)
1109 let error = 0 1095 let error = 0
1110 if !empty(output) && !s:hash_match(sha, s:lines(output)[0]) 1096 if !empty(output) && !s:hash_match(sha, s:lines(output)[0])
1111 let credential_helper = s:git_version_requirement(2) ? '-c credential.helper= ' : '' 1097 let credential_helper = s:disable_credential_helper() ? '-c credential.helper= ' : ''
1112 let output = s:system( 1098 let output = s:system(
1113 \ 'git '.credential_helper.'fetch --depth 999999 && git checkout '.plug#shellescape(sha).' --', a:spec.dir) 1099 \ 'git '.credential_helper.'fetch --depth 999999 && git checkout '.plug#shellescape(sha).' --', a:spec.dir)
1114 let error = v:shell_error 1100 let error = v:shell_error
1115 endif 1101 endif
1116 return [output, error] 1102 return [output, error]
1356 call setline(1, 'Updated. Elapsed time: ' . split(reltimestr(reltime(s:update.start)))[0] . ' sec.') 1342 call setline(1, 'Updated. Elapsed time: ' . split(reltimestr(reltime(s:update.start)))[0] . ' sec.')
1357 call s:switch_out('normal! gg') 1343 call s:switch_out('normal! gg')
1358 endif 1344 endif
1359 endfunction 1345 endfunction
1360 1346
1361 function! s:job_abort() 1347 function! s:mark_aborted(name, message)
1348 let attrs = { 'running': 0, 'error': 1, 'abort': 1, 'lines': [a:message] }
1349 let s:jobs[a:name] = extend(get(s:jobs, a:name, {}), attrs)
1350 endfunction
1351
1352 function! s:job_abort(cancel)
1362 if (!s:nvim && !s:vim8) || !exists('s:jobs') 1353 if (!s:nvim && !s:vim8) || !exists('s:jobs')
1363 return 1354 return
1364 endif 1355 endif
1365 1356
1366 for [name, j] in items(s:jobs) 1357 for [name, j] in items(s:jobs)
1370 silent! call job_stop(j.jobid) 1361 silent! call job_stop(j.jobid)
1371 endif 1362 endif
1372 if j.new 1363 if j.new
1373 call s:rm_rf(g:plugs[name].dir) 1364 call s:rm_rf(g:plugs[name].dir)
1374 endif 1365 endif
1366 if a:cancel
1367 call s:mark_aborted(name, 'Aborted')
1368 endif
1375 endfor 1369 endfor
1376 let s:jobs = {} 1370
1371 if a:cancel
1372 for todo in values(s:update.todo)
1373 let todo.abort = 1
1374 endfor
1375 else
1376 let s:jobs = {}
1377 endif
1377 endfunction 1378 endfunction
1378 1379
1379 function! s:last_non_empty_line(lines) 1380 function! s:last_non_empty_line(lines)
1380 let len = len(a:lines) 1381 let len = len(a:lines)
1381 for idx in range(len) 1382 for idx in range(len)
1383 if !empty(line) 1384 if !empty(line)
1384 return line 1385 return line
1385 endif 1386 endif
1386 endfor 1387 endfor
1387 return '' 1388 return ''
1389 endfunction
1390
1391 function! s:bullet_for(job, ...)
1392 if a:job.running
1393 return a:job.new ? '+' : '*'
1394 endif
1395 if get(a:job, 'abort', 0)
1396 return '~'
1397 endif
1398 return a:job.error ? 'x' : get(a:000, 0, '-')
1388 endfunction 1399 endfunction
1389 1400
1390 function! s:job_out_cb(self, data) abort 1401 function! s:job_out_cb(self, data) abort
1391 let self = a:self 1402 let self = a:self
1392 let data = remove(self.lines, -1) . a:data 1403 let data = remove(self.lines, -1) . a:data
1393 let lines = map(split(data, "\n", 1), 'split(v:val, "\r", 1)[-1]') 1404 let lines = map(split(data, "\n", 1), 'split(v:val, "\r", 1)[-1]')
1394 call extend(self.lines, lines) 1405 call extend(self.lines, lines)
1395 " To reduce the number of buffer updates 1406 " To reduce the number of buffer updates
1396 let self.tick = get(self, 'tick', -1) + 1 1407 let self.tick = get(self, 'tick', -1) + 1
1397 if !self.running || self.tick % len(s:jobs) == 0 1408 if !self.running || self.tick % len(s:jobs) == 0
1398 let bullet = self.running ? (self.new ? '+' : '*') : (self.error ? 'x' : '-')
1399 let result = self.error ? join(self.lines, "\n") : s:last_non_empty_line(self.lines) 1409 let result = self.error ? join(self.lines, "\n") : s:last_non_empty_line(self.lines)
1400 if len(result) 1410 if len(result)
1401 call s:log(bullet, self.name, result) 1411 call s:log(s:bullet_for(self), self.name, result)
1402 endif 1412 endif
1403 endif 1413 endif
1404 endfunction 1414 endfunction
1405 1415
1406 function! s:job_exit_cb(self, data) abort 1416 function! s:job_exit_cb(self, data) abort
1410 call s:tick() 1420 call s:tick()
1411 endfunction 1421 endfunction
1412 1422
1413 function! s:job_cb(fn, job, ch, data) 1423 function! s:job_cb(fn, job, ch, data)
1414 if !s:plug_window_exists() " plug window closed 1424 if !s:plug_window_exists() " plug window closed
1415 return s:job_abort() 1425 return s:job_abort(0)
1416 endif 1426 endif
1417 call call(a:fn, [a:job, a:data]) 1427 call call(a:fn, [a:job, a:data])
1418 endfunction 1428 endfunction
1419 1429
1420 function! s:nvim_cb(job_id, data, event) dict abort 1430 function! s:nvim_cb(job_id, data, event) dict abort
1482 elseif get(job, 'new', 0) 1492 elseif get(job, 'new', 0)
1483 let s:update.new[a:name] = 1 1493 let s:update.new[a:name] = 1
1484 endif 1494 endif
1485 1495
1486 let more = len(get(job, 'queue', [])) 1496 let more = len(get(job, 'queue', []))
1487 let bullet = job.error ? 'x' : more ? (job.new ? '+' : '*') : '-'
1488 let result = job.error ? join(job.lines, "\n") : s:last_non_empty_line(job.lines) 1497 let result = job.error ? join(job.lines, "\n") : s:last_non_empty_line(job.lines)
1489 if len(result) 1498 if len(result)
1490 call s:log(bullet, a:name, result) 1499 call s:log(s:bullet_for(job), a:name, result)
1491 endif 1500 endif
1492 1501
1493 if !job.error && more 1502 if !job.error && more
1494 let job.spec.queue = job.queue 1503 let job.spec.queue = job.queue
1495 let s:update.todo[a:name] = job.spec 1504 let s:update.todo[a:name] = job.spec
1496 else 1505 else
1497 let s:update.bar .= job.error ? 'x' : '=' 1506 let s:update.bar .= s:bullet_for(job, '=')
1498 call s:bar() 1507 call s:bar()
1499 endif 1508 endif
1500 endfunction 1509 endfunction
1501 1510
1502 function! s:bar() 1511 function! s:bar()
1571 return 1580 return
1572 endif 1581 endif
1573 1582
1574 let name = keys(s:update.todo)[0] 1583 let name = keys(s:update.todo)[0]
1575 let spec = remove(s:update.todo, name) 1584 let spec = remove(s:update.todo, name)
1585 if get(spec, 'abort', 0)
1586 call s:mark_aborted(name, 'Skipped')
1587 call s:reap(name)
1588 continue
1589 endif
1590
1576 let queue = get(spec, 'queue', []) 1591 let queue = get(spec, 'queue', [])
1577 let new = empty(globpath(spec.dir, '.git', 1)) 1592 let new = empty(globpath(spec.dir, '.git', 1))
1578 1593
1579 if empty(queue) 1594 if empty(queue)
1580 call s:log(new ? '+' : '*', name, pull ? 'Updating ...' : 'Installing ...') 1595 call s:log(new ? '+' : '*', name, pull ? 'Updating ...' : 'Installing ...')
1586 call s:spawn(name, spec, queue, { 'dir': spec.dir }) 1601 call s:spawn(name, spec, queue, { 'dir': spec.dir })
1587 elseif !new 1602 elseif !new
1588 let [error, _] = s:git_validate(spec, 0) 1603 let [error, _] = s:git_validate(spec, 0)
1589 if empty(error) 1604 if empty(error)
1590 if pull 1605 if pull
1591 let cmd = s:git_version_requirement(2) ? ['git', '-c', 'credential.helper=', 'fetch'] : ['git', 'fetch'] 1606 let cmd = s:disable_credential_helper() ? ['git', '-c', 'credential.helper=', 'fetch'] : ['git', 'fetch']
1592 if has_tag && !empty(globpath(spec.dir, '.git/shallow')) 1607 if has_tag && !empty(globpath(spec.dir, '.git/shallow'))
1593 call extend(cmd, ['--depth', '99999999']) 1608 call extend(cmd, ['--depth', '99999999'])
1594 endif 1609 endif
1595 if !empty(prog) 1610 if !empty(prog)
1596 call add(cmd, prog) 1611 call add(cmd, prog)
2311 endif 2326 endif
2312 endfunction 2327 endfunction
2313 2328
2314 function! s:with_cd(cmd, dir, ...) 2329 function! s:with_cd(cmd, dir, ...)
2315 let script = a:0 > 0 ? a:1 : 1 2330 let script = a:0 > 0 ? a:1 : 1
2316 return printf('cd%s %s && %s', s:is_win ? ' /d' : '', plug#shellescape(a:dir, {'script': script}), a:cmd) 2331 let pwsh = s:is_powershell(&shell)
2332 let cd = s:is_win && !pwsh ? 'cd /d' : 'cd'
2333 let sep = pwsh ? ';' : '&&'
2334 return printf('%s %s %s %s', cd, plug#shellescape(a:dir, {'script': script, 'shell': &shell}), sep, a:cmd)
2317 endfunction 2335 endfunction
2318 2336
2319 function! s:system(cmd, ...) 2337 function! s:system(cmd, ...)
2320 let batchfile = '' 2338 let batchfile = ''
2321 try 2339 try
2434 " List of valid directories 2452 " List of valid directories
2435 let dirs = [] 2453 let dirs = []
2436 let errs = {} 2454 let errs = {}
2437 let [cnt, total] = [0, len(g:plugs)] 2455 let [cnt, total] = [0, len(g:plugs)]
2438 for [name, spec] in items(g:plugs) 2456 for [name, spec] in items(g:plugs)
2439 if !s:is_managed(name) 2457 if !s:is_managed(name) || get(spec, 'frozen', 0)
2440 call add(dirs, spec.dir) 2458 call add(dirs, spec.dir)
2441 else 2459 else
2442 let [err, clean] = s:git_validate(spec, 1) 2460 let [err, clean] = s:git_validate(spec, 1)
2443 if clean 2461 if clean
2444 let errs[spec.dir] = s:lines(err)[0] 2462 let errs[spec.dir] = s:lines(err)[0]