From 5575fab73462701c152c7f863c3afff16fe7405b Mon Sep 17 00:00:00 2001 From: Arsham Shirvani Date: Sat, 7 Jan 2023 23:19:30 +0000 Subject: [PATCH] feat: add support for lazy plugin manager --- README.md | 54 ++++++++++++++++++++++++++----------- lua/listish/annotations.lua | 25 +++++++++++++++++ lua/listish/health.lua | 2 +- lua/listish/init.lua | 54 ++++++++++++++++++------------------- 4 files changed, 92 insertions(+), 43 deletions(-) create mode 100644 lua/listish/annotations.lua diff --git a/README.md b/README.md index 57c64da..9eee097 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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: @@ -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, }) ``` @@ -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, }) ``` @@ -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 = { - "qq", "qn", "qo", - "ww", "wn", "wo", - }, - ft = { "qf" }, + "arsham/listish.nvim", + requires = { "arsham/arshlib.nvim" }, + config = function() + require("listish").config({}) + end, + keys = { + "qq", + "qn", + "qo", + "ww", + "wn", + "wo", + }, + ft = { "qf" }, }) ``` diff --git a/lua/listish/annotations.lua b/lua/listish/annotations.lua new file mode 100644 index 0000000..528004b --- /dev/null +++ b/lua/listish/annotations.lua @@ -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 +-- }}} diff --git a/lua/listish/health.lua b/lua/listish/health.lua index 4c14162..30ca0e8 100644 --- a/lua/listish/health.lua +++ b/lua/listish/health.lua @@ -1,5 +1,5 @@ local M = {} -local health = vim.health or require("health") +local health = vim.health local libs = { arshlib = "arsham/arshlib.nvim", diff --git a/lua/listish/init.lua b/lua/listish/init.lua index 3e8323e..20e616b 100644 --- a/lua/listish/init.lua +++ b/lua/listish/init.lua @@ -1,3 +1,4 @@ +---@type Quick local quick = require("arshlib.quick") ---When using `dd` in the quickfix list, remove the item from the quickfix @@ -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 @@ -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 = { @@ -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: ", @@ -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 @@ -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) @@ -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. @@ -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 }, @@ -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 @@ -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" } @@ -330,8 +328,7 @@ 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 -- }}} @@ -339,8 +336,7 @@ local function config(opts) 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 @@ -350,6 +346,7 @@ 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" @@ -357,6 +354,7 @@ local function config(opts) 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" } @@ -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 @@ -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, @@ -404,7 +403,8 @@ end return { insert_list = insert_list, - config = config, + setup = setup, + config = setup, } -- vim: fdm=marker fdl=0