Skip to content

Commit

Permalink
Merge pull request #37 from savq/dev
Browse files Browse the repository at this point in the history
Add callable metamethod. Update docs
  • Loading branch information
savq authored Jun 3, 2021
2 parents 806c769 + ffe8fb5 commit 280a49a
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 98 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Visit the [releases page](https://github.com/savq/paq-nvim/releases) for more details.

# Deprecations


### v0.8.0.

Calling the `paq` function per package is deprecated. Users should now pass a
list to the `'paq-nvim'` module instead. See the readme and documentation for
more details.

### v0.6.0.

The `hook` option is deprecated, and will be removed in Paq 1.0. Use `run` instead.

26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Paq is a Neovim package manager written in Lua.

- __Simple__: Easy to use and configure
- __Fast__: Installs and updates packages concurrently using Neovim's event-loop
- __Small__: Around 150 LOC
- __Small__: Around 250 LOC


## Requirements
Expand Down Expand Up @@ -39,20 +39,18 @@ In your init.vim or init.lua, you can write something like:

```lua
lua << EOF
require 'paq-nvim' {
-- Add your packages
'savq/paq-nvim'; -- Let Paq manage itself

local paq = require'paq-nvim'.paq -- Import module and bind `paq` function
paq 'savq/paq-nvim' -- Let Paq manage itself
'neovim/nvim-lspconfig'; -- Mind the semi-colons
'nvim-lua/completion-nvim';
'nvim-lua/lsp_extensions.nvim';

-- Add your packages

paq 'neovim/nvim-lspconfig'
paq 'nvim-lua/completion-nvim'
paq 'nvim-lua/lsp_extensions.nvim'

paq{'lervag/vimtex', opt=true} -- Use braces when passing options

paq{'dracula/vim', as='dracula'} -- Use `as` to alias a package name (here `vim`)
{'lervag/vimtex', opt=true}; -- Use braces when passing options

{'dracula/vim', as='dracula'}; -- Use `as` to alias a package name (here `vim`)
}
EOF
```

Expand All @@ -61,6 +59,10 @@ Then, run `:PaqInstall`.
In general, to add packages to Paq's list, call `paq '<gh-username>/<repo>'`
inside a Lua chunk (or in a separate Lua module).

**NOTICE:**
Calling the `paq` function per package is deprecated. Users should now pass a
list to the `'paq-nvim'` module instead.


## Commands

Expand Down
75 changes: 45 additions & 30 deletions doc/paq-nvim.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*paq-nvim.txt* Package manager for Neovim v0.4.4 Last change: 2021-04-05
*paq-nvim.txt* Package manager for Neovim v0.4.4 Last change: 2021-06-02
*paq-nvim*
*paq*

Expand Down Expand Up @@ -58,17 +58,18 @@ USAGE *paq-usage*

To get started with Paq:

1. Import the `paq-nvim` module, and bind the `paq` function:
1. Import the `paq-nvim` module:
>
local Paq = require'paq-nvim' -- Module
local paq = Paq.paq -- Function
paq 'savq/paq-nvim' -- Paq manages itself
local paq = require 'paq-nvim' -- Module
<

2. List the packages you want to install using the `paq` function with the
name of a package repository, for example:
2. Call the paq module with a the list of packages you want to install.
Each entry in the list is a package repository, for example:
>
paq 'lervag/vimtex'
paq {
'savq/paq-nvim'; -- Paq manages itself
'lervag/vimtex';
}
<

3. Run the `:PaqInstall` command.
Expand All @@ -82,69 +83,75 @@ FUNCTIONS AND COMMANDS *paq-commands*

The Paq module exports multiple functions. Most of these functions have a
command alias to make them easier to call on demand. Assuming the module is
imported as `Paq`, the functions are:
imported as `paq`, the functions are:

|Paq.paq| *Paq.paq*
|paq.__call| *paq.__call*

Add a package to Paq's (internal) list. It can take a table or a string.
When a table is passed, the first value has to be a string with the name of
the repository, like: `'<GitHub-username>/<repository-name>'`.
The `paq` module is itself a callable object. It takes as argument a list of
packages. Each element of the list can be a table or a string.

When the element is a table, the first value has to be a string with the
name of the repository, like: `'<GitHub-username>/<repository-name>'`.
The other key-value pairs in the table have to be named explicitly, see
|paq-options|. If only a string is passed, it works as if it was the first
|paq-options|. When the element is a string, it works as if it was the first
value of the table, and all other options will be set to their default
values.

Note: Lua can elide parentheses when passing a table or a string to a
function, so you can always call `paq` without parentheses.
Note: Lua can elide parentheses when passing a table to a function,
so you can always call `paq` without parentheses.


|Paq.install| *Paq.install*
|paq.install| *paq.install*
*:PaqInstall*
Installs all packages listed on your configuration, if a package is already
installed, the function ignores it.


|Paq.update| *Paq.update*
|paq.update| *paq.update*
*:PaqUpdate*
Updates the installed packages listed on your configuration. If a package
hasn't been installed with |PaqInstall|, the function ignores it.


|Paq.clean| *Paq.clean*
|paq.clean| *paq.clean*
*:PaqClean*
Removes packages found on |paq-dir| that aren't listed in your
configuration.


|Paq.list| *Paq.list*
|paq.list| *paq.list*
*:PaqList*
Lists installed packages as well as packages that were recently removed.
Recently installed or updated packages are marked with a `+` and `*`,
respectively.


|Paq.log_open| *Paq.log_open*
|paq.log_open| *paq.log_open*
*:PaqLogOpen*
Opens the |paq-log| file in a split window.


|Paq.log_clean| *Paq.log_clean*
|paq.log_clean| *paq.log_clean*
*:PaqLogClean*
Deletes the |paq-log| file.


|Paq.setup| *Paq.setup*
|paq.setup| *paq.setup*

Configures specific global behavior. It takes as single input a table,
which can have a key `path` to overwrite the default value for |paq-dir|.
This functionality exists mainly to allow testing without altering a
user's configuration.

|paq.paq| *paq.paq*

The paq function is deprecated. The `paq` module is now a callable that
takes a list of packages.

==============================================================================
PACKAGE OPTIONS *paq-options*

You can pass a table with named options to the |Paq.paq| function.
Each element in the list of packages can be a table with named options.
These options don't need to be in any particular order, as long as the
name of the repository is the first element on the table.

Expand Down Expand Up @@ -212,7 +219,10 @@ The language client `coc.nvim` recommends installing the release branch of
their repository. If we also wanted to install it as an optional package,
we could call `paq` like:
>
paq {'neoclide/coc.nvim', opt=true, branch='release'}
local paq = require 'paq-nvim'
paq {
{'neoclide/coc.nvim', opt=true, branch='release'};
}
<

==============================================================================
Expand All @@ -225,7 +235,7 @@ where Paq installs packages by running the command:
:echo stdpath('data') .. '/site/pack/paqs'
<
If you have packages that aren't managed by Paq, you shouldn't put them on
Paq's directory, since |Paq.clean| could delete them.
Paq's directory, since |paq.clean| could delete them.


==============================================================================
Expand Down Expand Up @@ -254,12 +264,15 @@ load a local plugin, namely:
- Add it to a directory in |packpath| (different from |paq-dir|)
- Modify the |runtimepath| directly

The first option is the easiest, though your plugin can end up pretty deep
in a directory hierarchy.

The second option just requires you to concatenate the path to the plugin to
your `runtimepath`. In lua, this looks like:
your `runtimepath`. In Lua (nvim 0.5), this looks like:
>
vim.o.runtimepath = vim.o.runtimepath .. ",~/path/to/your/plugin"
vim.opt.runtimepath:append("~/path/to/your/plugin")
<
Use an absolute path, and don't forget the comma!
Remember to use an absolute path.


------------------------------------------------------------------------------
Expand All @@ -286,7 +299,9 @@ writing there isn't a way to declare an autocommand using only Lua.

Example:
>
paq {'author/heavy-plugin', opt=true}
paq {
{'author/heavy-plugin', opt=true};
}
vim.cmd [[autocmd Filetype ruby packadd! heavy-plugin]]
<

Expand Down
13 changes: 7 additions & 6 deletions lua/paq-nvim.lua
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ local function list()
list_pkgs('Recently removed:', removed)
end

local function paq(args)
local function register(args)
local name, dir
if type(args) == 'string' then args = {args} end

Expand All @@ -234,25 +234,26 @@ local function paq(args)
branch = args.branch,
dir = dir,
exists = (vfn('isdirectory', {dir}) ~= 0),
run = args.run or args.hook, --wait for paq 1.0 to deprecate
run = args.run or args.hook, -- DEPRECATE 1.0
url = args.url or 'https://github.com/' .. args[1] .. '.git',
}
end

local function setup(args)
local function setup(self, args)
assert(type(args) == 'table')
if type(args.path) == 'string' then
paq_dir = args.path
end
return self
end

return {
return setmetatable({
install = function() compat.tbl_map(install, packages) end,
update = function() compat.tbl_map(update, packages) end,
clean = clean,
list = list,
setup = setup,
paq = paq,
paq = register, -- DEPRECATE 1.0
log_open = function() cmd('sp ' .. LOGFILE) end,
log_clean = function() uv.fs_unlink(LOGFILE); print('Paq log file deleted') end,
}
},{__call=function(self, tbl) packages={} num_pkgs=0 compat.tbl_map(register, tbl) return self end})
89 changes: 39 additions & 50 deletions test/test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,8 @@ local cmd = vim.api.nvim_command
local vfn = vim.api.nvim_call_function

cmd('packadd paq-nvim')

local TESTPATH = vfn('stdpath', {'data'}) .. '/site/pack/test/'

local function reload_paq()
local Pq
package.loaded['paq-nvim'] = nil
Pq = require('paq-nvim')
Pq.setup {
path = TESTPATH,
}
return Pq
end
local paq = require('paq-nvim'):setup{path=TESTPATH}

local function test_branch(path, branch)
local stdout = uv.new_pipe(false)
Expand All @@ -28,7 +18,9 @@ local function test_branch(path, branch)
assert(code == 0, "Paq-test: failed to get git branch")
stdout:read_stop()
stdout:close()
end)
end
)

stdout:read_start(function(err, data)
assert(not err, err)
if data then
Expand All @@ -37,51 +29,48 @@ local function test_branch(path, branch)
end)
end

local function load_pkgs()
paq {
{'badbadnotgood', opt=true}; -- should fail to parse
{'rust-lang/rust.vim', opt=true}; -- test opt
{'JuliaEditorSupport/julia-vim', as='julia'}; -- test as

local Pq = reload_paq()
local paq = Pq.paq

paq{'badbadnotgood', opt=true} -- should fail to parse
paq{'rust-lang/rust.vim', opt=true} -- test opt
paq{'JuliaEditorSupport/julia-vim', as='julia'} -- test as

paq{as='wiki', -- test url + as
url='https://github.com/lervag/wiki.vim',
}
{as='wiki', url='https://github.com/lervag/wiki.vim'}; -- test url + as

paq {'junegunn/fzf', -- test run function
run=function() vfn('fzf#install', {}) end,
}
{'junegunn/fzf', run=function() vfn('fzf#install', {}) end}; -- test run function

paq {'autozimu/LanguageClient-neovim', -- test branch + run command
branch = 'next',
run = 'bash install.sh',
{'autozimu/LanguageClient-neovim', branch='next', run='bash install.sh'}; -- branch + run command
}
end

Pq.install()
cmd('sleep 20') -- plenty of time for plugins to download

assert(uv.fs_scandir(TESTPATH .. 'opt/rust.vim'))
assert(uv.fs_scandir(TESTPATH .. 'start/julia'))
assert(uv.fs_scandir(TESTPATH .. 'start/wiki'))
assert(uv.fs_scandir(TESTPATH .. 'start/fzf'))
assert(uv.fs_scandir(TESTPATH .. 'start/LanguageClient-neovim'))



test_branch('start/LanguageClient-neovim', 'next')
cmd('sleep 20')
local function test_install()
paq.install()
uv.sleep(5000)
assert(uv.fs_scandir(TESTPATH .. 'opt/rust.vim'))
assert(uv.fs_scandir(TESTPATH .. 'start/julia'))
assert(uv.fs_scandir(TESTPATH .. 'start/wiki'))
assert(uv.fs_scandir(TESTPATH .. 'start/fzf'))
assert(uv.fs_scandir(TESTPATH .. 'start/LanguageClient-neovim'))

---- Check clean() doesn't delete everything
Pq = reload_paq()
Pq.paq{'JuliaEditorSupport/julia-vim', as='julia'}
Pq.clean()
assert(uv.fs_scandir(TESTPATH .. 'start/julia'))
--test_branch('start/LanguageClient-neovim', 'next')
end

local function test_clean()
paq {
{'JuliaEditorSupport/julia-vim', as='julia'};
{'autozimu/LanguageClient-neovim', branch='next', run='bash install.sh'};
}
paq.clean()
assert(uv.fs_scandir(TESTPATH .. 'start/julia'))
end

local function main()
load_pkgs()
test_install()
test_clean()
uv.sleep(5000)
--paq.clean()
end

cmd('sleep 20')
Pq = reload_paq()
Pq.clean()
main()

print('Paq-test: FINISHED')

0 comments on commit 280a49a

Please sign in to comment.