Skip to content

Commit

Permalink
Merge pull request #153 from k-takata/devel
Browse files Browse the repository at this point in the history
Merge 'devel' into 'master'
  • Loading branch information
k-takata committed Jul 31, 2024
2 parents bb0e4cf + 5abb84b commit 0b2f79b
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 42 deletions.
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[![Build status](https://github.com/k-takata/minpac/workflows/CI/badge.svg)](https://github.com/k-takata/minpac/actions)
[![Build status](https://ci.appveyor.com/api/projects/status/qakftqoyx5m47ns3/branch/master?svg=true)](https://ci.appveyor.com/project/k-takata/minpac/branch/master)

minpac: A minimal package manager for Vim 8 (and Neovim)
========================================================
minpac: A minimal package manager for Vim 8+ (and Neovim)
=========================================================

Overview
--------

Minpac is a minimal package manager for Vim 8 (and Neovim). This uses the
Minpac is a minimal package manager for Vim 8+ (and Neovim). This uses the
[packages](http://vim-jp.org/vimdoc-en/repeat.html#packages) feature and
the [jobs](http://vim-jp.org/vimdoc-en/channel.html#job-channel-overview)
feature which have been newly added on Vim 8.
Expand Down Expand Up @@ -403,6 +403,13 @@ Otherwise, shows the status of the plugin and commits of last update (if any).
|----------|-------------|
| `'open'` | Specify how to open the status window.<br/>`'vertical'`: Open in vertical split.<br/>`'horizontal'`: Open in horizontal split.<br/>`'tab'`: Open in a new tab.<br/>Default: `'horizontal'` or specified value by `minpac#init()`. |

#### minpac#abort()

Abort updating the plugins. Mainly for debugging.

If you face any errors while running `minpac#update()` and you cannot run it again, you can try this.


### Hooks

Currently, minpac supports two types of hook: Post-update hooks and Finish-update hooks.
Expand Down Expand Up @@ -486,6 +493,10 @@ List of mappings available only in status window.
|`<C-k>` | Jump to previous package in list. |
|`q` | Exit the status window.<br/>(Also works for commit preview window) |

The mappings for `<C-j>` and `<C-k>` can be disabled with:
```vim
let g:no_minpac_maps = 1
```

Similar projects
----------------
Expand Down
7 changes: 6 additions & 1 deletion autoload/minpac.vim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
" ---------------------------------------------------------------------
" minpac: A minimal package manager for Vim 8 (and Neovim)
" minpac: A minimal package manager for Vim 8+ (and Neovim)
"
" Maintainer: Ken Takata
" Last Change: 2020-08-22
Expand Down Expand Up @@ -144,4 +144,9 @@ function! minpac#getpluglist()
return g:minpac#pluglist
endfunction

" Abort updating the plugins.
function! minpac#abort()
return minpac#impl#abort()
endfunction

" vim: set ts=8 sw=2 et:
2 changes: 1 addition & 1 deletion autoload/minpac/git.vim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
" ---------------------------------------------------------------------
" minpac: A minimal package manager for Vim 8 (and Neovim)
" minpac: A minimal package manager for Vim 8+ (and Neovim)
"
" Maintainer: Ken Takata
" Last Change: 2020-02-01
Expand Down
93 changes: 63 additions & 30 deletions autoload/minpac/impl.vim
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
" ---------------------------------------------------------------------
" minpac: A minimal package manager for Vim 8 (and Neovim)
" minpac: A minimal package manager for Vim 8+ (and Neovim)
"
" Maintainer: Ken Takata
" Last Change: 2020-08-22
" Last Change: 2023-12-20
" License: VIM License
" URL: https://github.com/k-takata/minpac
" ---------------------------------------------------------------------

let s:joblist = []
let s:remain_jobs = 0
let s:joblist = [] " Jobs that are currently running.
let s:jobqueue = [] " Jobs that are waiting to be started.
let s:remain_plugins = 0
let s:timer_id = -1

" Get a list of package/plugin directories.
function! minpac#impl#getpackages(...) abort
Expand Down Expand Up @@ -113,7 +115,7 @@ endfunction
function! minpac#impl#get_plugin_revision(name) abort
let l:rev = minpac#git#get_revision(g:minpac#pluglist[a:name].dir)
if l:rev != v:null
call s:echom_verbose(4, '', 'revision: ' . l:rev)
call s:echom_verbose(4, '', 'revision (' . a:name . '): ' . l:rev)
return l:rev
endif
return s:exec_plugin_cmd(a:name, ['rev-parse', 'HEAD'], 'revision')
Expand All @@ -140,9 +142,12 @@ function! s:get_plugin_branch(name) abort
endfunction


function! s:decrement_job_count() abort
let s:remain_jobs -= 1
if s:remain_jobs == 0
function! s:decrement_plugin_count() abort
let s:remain_plugins -= 1
if s:remain_plugins == 0
call timer_stop(s:timer_id)
let s:timer_id = -1

" `minpac#update()` is finished.
call s:invoke_hook('finish-update', [s:updated_plugins, s:installed_plugins], s:finish_update_hook)

Expand Down Expand Up @@ -285,6 +290,7 @@ function! s:handle_subdir(pluginfo) abort
endfunction

function! s:job_exit_cb(id, errcode, event) dict abort
" Remove myself from s:joblist.
call filter(s:joblist, {-> v:val != a:id})

let l:err = 1
Expand Down Expand Up @@ -317,7 +323,7 @@ function! s:job_exit_cb(id, errcode, event) dict abort
if l:rev ==# ''
let s:error_plugins += 1
call s:echom_verbose(1, 'error', 'Error while updating "' . self.name . '". No tags found.')
call s:decrement_job_count()
call s:decrement_plugin_count()
return
endif
endif
Expand Down Expand Up @@ -385,7 +391,7 @@ function! s:job_exit_cb(id, errcode, event) dict abort
call s:echom_verbose(1, 'error', 'Error while updating "' . self.name . '". Error code: ' . a:errcode)
endif

call s:decrement_job_count()
call s:decrement_plugin_count()
endfunction

function! s:job_err_cb(id, message, event) dict abort
Expand All @@ -401,18 +407,7 @@ function! s:job_err_cb(id, message, event) dict abort
endfor
endfunction

function! s:start_job(cmds, name, seq, ...) abort
if len(s:joblist) > 1
sleep 20m
endif
if g:minpac#opt.jobs > 0
if len(s:joblist) >= g:minpac#opt.jobs
" Call myself with a 500 ms wait.
call timer_start(500, function('s:start_job', [a:cmds, a:name, a:seq]))
return 0
endif
endif

function! s:start_job_core(cmds, name, seq) abort
let l:quote_cmds = s:quote_cmds(a:cmds)
call s:echom_verbose(4, '', 'start_job: cmds=' . string(l:quote_cmds))
let l:job = minpac#job#start(l:quote_cmds, {
Expand All @@ -422,13 +417,38 @@ function! s:start_job(cmds, name, seq, ...) abort
\ })
if l:job > 0
" It worked!
let s:joblist += [l:job]
return 0
else
call s:echom_verbose(1, 'error', 'Fail to execute: ' . a:cmds[0])
call s:decrement_job_count()
call s:decrement_plugin_count()
return 1
endif
let s:joblist += [l:job]
return 0
endfunction

function! s:timer_worker(timer) abort
if (len(s:joblist) >= g:minpac#opt.jobs) || (len(s:jobqueue) == 0)
return
endif
let l:job = remove(s:jobqueue, 0)
return s:start_job_core(l:job[0], l:job[1], l:job[2])
endfunction

function! s:start_job(cmds, name, seq, ...) abort
if len(s:joblist) > 1
sleep 20m
endif
if g:minpac#opt.jobs > 0
if len(s:joblist) >= g:minpac#opt.jobs
if s:timer_id == -1
let s:timer_id = timer_start(500, 's:timer_worker', {'repeat': -1})
endif
" Add the job to s:jobqueue.
let s:jobqueue += [[a:cmds, a:name, a:seq]]
return 0
endif
endif
return s:start_job_core(a:cmds, a:name, a:seq)
endfunction

function! s:is_same_commit(a, b) abort
Expand Down Expand Up @@ -509,7 +529,7 @@ endfunction
function! s:update_single_plugin(name, force) abort
if !has_key(g:minpac#pluglist, a:name)
call s:echoerr_verbose(1, 'Plugin not registered: ' . a:name)
call s:decrement_job_count()
call s:decrement_plugin_count()
return 1
endif

Expand All @@ -526,7 +546,7 @@ function! s:update_single_plugin(name, force) abort
let l:pluginfo.stat.installed = 1
if l:pluginfo.frozen && !a:force
call s:echom_verbose(3, '', 'Skipped: ' . a:name)
call s:decrement_job_count()
call s:decrement_plugin_count()
return 0
endif

Expand All @@ -535,7 +555,7 @@ function! s:update_single_plugin(name, force) abort
if l:ret == 0
" No need to update.
call s:echom_verbose(3, '', 'Already up-to-date: ' . a:name)
call s:decrement_job_count()
call s:decrement_plugin_count()
return 0
elseif l:ret == 1
" Same branch. Update by pull.
Expand Down Expand Up @@ -599,11 +619,11 @@ function! minpac#impl#update(...) abort
return
endif

if s:remain_jobs > 0
if s:remain_plugins > 0
call s:echom_verbose(1, '', 'Previous update has not been finished.')
return
endif
let s:remain_jobs = len(l:names)
let s:remain_plugins = len(l:names)
let s:error_plugins = 0
let s:updated_plugins = 0
let s:installed_plugins = 0
Expand Down Expand Up @@ -706,4 +726,17 @@ function! minpac#impl#is_update_ran() abort
return exists('s:installed_plugins')
endfunction

function! minpac#impl#abort() abort
let s:jobqueue = []
for l:job in s:joblist
call minpac#job#stop(l:job)
endfor
let s:joblist = []
let s:remain_plugins = 0
if s:timer_id != -1
call timer_stop(s:timer_id)
let s:timer_id = -1
endif
endfunction

" vim: set ts=8 sw=2 et:
2 changes: 1 addition & 1 deletion autoload/minpac/progress.vim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
" ---------------------------------------------------------------------
" minpac: A minimal package manager for Vim 8 (and Neovim)
" minpac: A minimal package manager for Vim 8+ (and Neovim)
"
" Maintainer: Ken Takata
" Last Change: 2020-01-28
Expand Down
8 changes: 5 additions & 3 deletions autoload/minpac/status.vim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
" ---------------------------------------------------------------------
" minpac: A minimal package manager for Vim 8 (and Neovim)
" minpac: A minimal package manager for Vim 8+ (and Neovim)
"
" Maintainer: Ken Takata
" Created By: Kristijan Husak
Expand Down Expand Up @@ -140,8 +140,10 @@ endfunction
function! s:mappings() abort
nnoremap <silent><buffer><nowait> <CR> :call <SID>openSha()<CR>
nnoremap <silent><buffer><nowait> q :q<CR>
nnoremap <silent><buffer><nowait> <C-j> :call <SID>nextPackage()<CR>
nnoremap <silent><buffer><nowait> <C-k> :call <SID>prevPackage()<CR>
if !exists("no_plugin_maps") && !exists("no_minpac_maps")
nnoremap <silent><buffer><nowait> <C-j> :call <SID>nextPackage()<CR>
nnoremap <silent><buffer><nowait> <C-k> :call <SID>prevPackage()<CR>
endif
endfunction

function! s:nextPackage() abort
Expand Down
16 changes: 14 additions & 2 deletions doc/minpac.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*minpac.txt* A minimal package manager for Vim 8 (and Neovim)
*minpac.txt* A minimal package manager for Vim 8+ (and Neovim)

Version: 3.0.0
Author: Ken Takata
Expand All @@ -23,7 +23,7 @@ USAGE |minpac-usage|
==============================================================================
OVERVIEW *minpac-overview*

Minpac is a minimal package manager for Vim 8 (and Neovim). This uses the
Minpac is a minimal package manager for Vim 8+ (and Neovim). This uses the
|packages| feature and the jobs feature (|job-channel-overview|) which have
been newly added on Vim 8.

Expand Down Expand Up @@ -481,6 +481,7 @@ minpac#getpackages([{packname}[, {packtype}[, {plugname}[, {nameonly}]]]])
" List package names.
echo minpac#getpackages("", "NAME", "", 1)
<

minpac#status([{config}]) *minpac#status()*
Print status of plugins.
When ran after |minpac#update()|, shows only installed and updated
Expand All @@ -497,6 +498,14 @@ minpac#status([{config}]) *minpac#status()*
Default: "horizontal" or specified value by
|minpac#init()|.


minpac#abort() *minpac#abort()*
Abort updating the plugins. Mainly for debugging.

If you face any errors while running |minpac#update()| and you cannot
run it again, you can try this.


------------------------------------------------------------------------------
HOOKS *minpac-hooks*

Expand Down Expand Up @@ -599,5 +608,8 @@ List of mappings available only in status window.
q Exit the status window.
(Also works for commit preview window)

The mappings for <C-j> and <C-k> can be disabled with: >
let g:no_minpac_maps = 1
==============================================================================
vim:tw=78:ts=8:ft=help:norl:
2 changes: 1 addition & 1 deletion plugin/minpac.vim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
" ---------------------------------------------------------------------
" minpac: A minimal package manager for Vim 8 (and Neovim)
" minpac: A minimal package manager for Vim 8+ (and Neovim)
"
" Maintainer: Ken Takata
" Last Change: 2020-08-22
Expand Down

0 comments on commit 0b2f79b

Please sign in to comment.