Skip to content

Commit

Permalink
feat: add support for lazy plugin manager
Browse files Browse the repository at this point in the history
  • Loading branch information
arsham committed Jan 7, 2023
1 parent 8a7136c commit 5575fab
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 43 deletions.
54 changes: 39 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ you can create notes on current position to either lists.
1. [Demo](#demo)
2. [Requirements](#requirements)
3. [Installation](#installation)
- [Lazy](#lazy)
- [Packer](#packer)
- [Config](#config)
- [Lazy Loading](#lazy-loading)
4. [Related Projects](#related-projects)
Expand All @@ -33,7 +35,7 @@ Adding notes to the list:
## Requirements

This library supports [Neovim
0.7.0](https://github.com/neovim/neovim/releases/tag/v0.7.0) and newer.
v0.7.0](https://github.com/neovim/neovim/releases/tag/v0.7.0) and newer.

This plugin depends are the following libraries. Please make sure to add them
as dependencies in your package manager:
Expand All @@ -45,13 +47,29 @@ plugin to get the most out of your lists.

## Installation

Use your favourite package manager to install this library. Packer example:
Use your favourite package manager to install this library.

### Lazy

```lua
{
"arsham/listish.nvim",
dependencies = { "arsham/arshlib.nvim" },
config = true,
-- or to provide configuration
-- config = { theme_list = false, ..}
}
```

### Packer

```lua
use({
"arsham/listish.nvim",
requires = { "arsham/arshlib.nvim" },
config = function() require("listish").config({}) end,
"arsham/listish.nvim",
requires = { "arsham/arshlib.nvim" },
config = function()
require("listish").config({})
end,
})
```

Expand All @@ -64,8 +82,8 @@ To disable set them to `false`. For example:

```lua
require("listish").config({
theme_list = false,
local_list = false,
theme_list = false,
local_list = false,
})
```

Expand Down Expand Up @@ -107,14 +125,20 @@ events or when the first quickfix/local list is opened. Packer example:

```lua
use({
"arsham/listish.nvim",
requires = { "arsham/arshlib.nvim" },
config = function() require("listish").config({}) end,
keys = {
"<leader>qq", "<leader>qn", "<leader>qo",
"<leader>ww", "<leader>wn", "<leader>wo",
},
ft = { "qf" },
"arsham/listish.nvim",
requires = { "arsham/arshlib.nvim" },
config = function()
require("listish").config({})
end,
keys = {
"<leader>qq",
"<leader>qn",
"<leader>qo",
"<leader>ww",
"<leader>wn",
"<leader>wo",
},
ft = { "qf" },
})
```

Expand Down
25 changes: 25 additions & 0 deletions lua/listish/annotations.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-- Annotations {{{
---@class HighlightOpt
---@field style string
---@field link? string if defined, everything else is ignored
---@field guifg string
---@field guibg string
---@field guisp string
---@field ctermfg string
---@field ctermbg string

---@class Quick
---@field command fun(name: string, command: string|function, opts?: table) Creates a command from provided specifics.
---@field normal fun(mode: string, motion: string, special: boolean?) Executes a command in normal mode.
---@field selection_contents fun(): string Returns the contents of the visually selected region.
---@field buffer_command fun(name: string, command: string|function, opts?: table) Creates a command from provided specifics on current buffer.
---@field call_and_centre fun(fn: fun()) Pushes the current location to the jumplist and calls the fn callback, then centres the cursor.
---@field cmd_and_centre fun(cmd: string) Pushes the current location to the jumplist and calls the cmd, then centres the cursor.
---@field highlight fun(group: string, opt: HighlightOpt) --Create a highlight group.

---@class ListItem
---@field bufnr number
---@field lnum number
---@field col number
---@field text string
-- }}}
2 changes: 1 addition & 1 deletion lua/listish/health.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local M = {}
local health = vim.health or require("health")
local health = vim.health

local libs = {
arshlib = "arsham/arshlib.nvim",
Expand Down
54 changes: 27 additions & 27 deletions lua/listish/init.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---@type Quick
local quick = require("arshlib.quick")

---When using `dd` in the quickfix list, remove the item from the quickfix
Expand Down Expand Up @@ -41,16 +42,11 @@ local function delete_list_item() -- {{{
end
end --}}}

-- @class ListItem
-- @field bufnr number
-- @field lnum number
-- @field col number
-- @field text string

---Inserts the current position of the cursor in the qf/local list with the
-- note.
-- @param items ListItem[]
-- @param is_local boolean if true, the item goes into the local list.
---@param items ListItem[]
---@param is_local boolean if true, the item goes into the local list.
local function insert_list(items, is_local) --{{{
local cur_list = {}
if is_local then
Expand All @@ -71,8 +67,8 @@ end --}}}
local unique_id = "Z"

---Inserts the current position of the cursor in the qf/local list.
-- @param note string
-- @param is_local boolean if true, the item goes into the local list.
---@param note string
---@param is_local boolean if true, the item goes into the local list.
local function insert_note_to_list(note, is_local) --{{{
local location = vim.api.nvim_win_get_cursor(0)
local item = {
Expand Down Expand Up @@ -117,7 +113,7 @@ end --}}}

---Opens a popup for a note, and adds the current line and column with the note
-- to the list.
-- @param is_local boolean if true, the item goes into the local list.
---@param is_local boolean if true, the item goes into the local list.
local function add_note(is_local) --{{{
vim.ui.input({
prompt = "Note: ",
Expand All @@ -132,6 +128,7 @@ end --}}}
function _G.add_quickfix_note()
add_note(false)
end
-- selene: allow(global_usage)
function _G.add_locallist_note()
add_note(true)
end
Expand All @@ -144,6 +141,7 @@ function _G.insert_to_quickfix()
end

---Add the current line and the column to the local list.
-- selene: allow(global_usage)
function _G.insert_to_locallist()
local line = vim.api.nvim_get_current_line()
insert_note_to_list(line, true)
Expand Down Expand Up @@ -193,10 +191,10 @@ function _G.qftf(info) --{{{
end --}}}

---Creates a mapping for jumping through lists.
-- @param key string the key to map.
-- @param next string the command to execute if there is a next item.
-- @param wrap string the command to execute if there is no next item.
-- @param desc string the description of the mapping.
---@param key string the key to map.
---@param next string the command to execute if there is a next item.
---@param wrap string the command to execute if there is no next item.
---@param desc string the description of the mapping.
local function jump_list_mapping(key, next, wrap, desc) --{{{
if not key then
-- this makes the config simpler.
Expand Down Expand Up @@ -244,11 +242,11 @@ local defaults = { --{{{
},
} --}}}

local function config(opts)
opts = vim.tbl_deep_extend("force", defaults, opts)
local function setup(opts)
opts = vim.tbl_deep_extend("force", defaults, opts or {})
local string_type = { "string", "nil", "boolean" }
-- Validations {{{
-- stylua: ignore start
-- stylua: ignore
vim.validate({
opts = { opts, { "table", false } },
theme_list = { opts.theme_list, { "boolean", "nil" }, false },
Expand Down Expand Up @@ -303,8 +301,7 @@ local function config(opts)
if opts.quickfix.open then
vim.keymap.set("n", opts.quickfix.open, function()
vim.cmd.copen()
end,
{ silent = true, desc = "open quickfix list" })
end, { silent = true, desc = "open quickfix list" })
end

if opts.quickfix.on_cursor then
Expand All @@ -321,6 +318,7 @@ local function config(opts)
end, { expr = true, desc = "add to quickfix list with node" })
end

-- stylua: ignore
if opts.quickfix.clear then
vim.keymap.set("n", opts.quickfix.clear, clearqflist,
{ silent = true, desc = "drop quickfix list" }
Expand All @@ -330,17 +328,15 @@ local function config(opts)
if opts.quickfix.close then
vim.keymap.set("n", opts.quickfix.close, function()
vim.cmd.cclose()
end,
{ silent = true, desc = "close quickfix list" })
end, { silent = true, desc = "close quickfix list" })
end
-- }}}

-- Local list mappings {{{
if opts.locallist.open then
vim.keymap.set("n", opts.locallist.open, function()
vim.api.nvim_command("silent! lopen")
end, { silent = true, desc = "open local list" }
)
end, { silent = true, desc = "open local list" })
end

if opts.locallist.on_cursor then
Expand All @@ -350,13 +346,15 @@ local function config(opts)
end, { expr = true, desc = "add to local list" })
end

-- stylua: ignore
if opts.locallist.add_note then
vim.keymap.set("n", opts.locallist.add_note, function()
vim.opt.opfunc = "v:lua.add_locallist_note"
return "g@<cr>"
end, { expr = true, desc = "add to local list with node" })
end

-- stylua: ignore
if opts.locallist.clear then
vim.keymap.set("n", opts.locallist.clear, clearloclist,
{ silent = true, desc = "drop local list" }
Expand All @@ -366,14 +364,14 @@ local function config(opts)
if opts.locallist.close then
vim.keymap.set("n", opts.locallist.close, function()
vim.cmd.lclose()
end,
{ silent = true, desc = "close local list" })
end, { silent = true, desc = "close local list" })
end
-- }}}

jump_list_mapping(opts.quickfix.next, "cnext", "cfirst", "jump to next item in qf list")
jump_list_mapping(opts.quickfix.prev, "cprevious", "clast", "jump to previous item in qf list")
jump_list_mapping(opts.locallist.next, "lnext", "lfirst", "jump to next item in local list")
-- stylua: ignore
jump_list_mapping(opts.locallist.prev, "lprevious", "llast", "jump to previous item in local list")

if opts.in_list_dd then
Expand All @@ -393,7 +391,8 @@ local function config(opts)
pattern = "qf",
desc = "delete from qf/local lists",
callback = function()
vim.keymap.set( "n", opts.in_list_dd, delete_list_item,
-- stylua: ignore
vim.keymap.set("n", opts.in_list_dd, delete_list_item,
{ buffer = true, desc = "delete from qf/local lists" }
)
end,
Expand All @@ -404,7 +403,8 @@ end

return {
insert_list = insert_list,
config = config,
setup = setup,
config = setup,
}

-- vim: fdm=marker fdl=0

0 comments on commit 5575fab

Please sign in to comment.