From 5193f23ecca0a9c03edc0250131db2ad3a530409 Mon Sep 17 00:00:00 2001 From: adgai19 Date: Sat, 23 Oct 2021 10:15:00 +0530 Subject: [PATCH 01/10] fixed command for cmd-ui --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 13e7778..b84bc2e 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,7 @@ lua require("harpoon.term").sendCommand(1, "ls -la") This feature adds ability to change commands while working inside a project. Just call the following function to edit commands inside the list ```lua -lua require('harpoon.ui-cmd').toggle_quick_menu() +lua require('harpoon.cmd-ui').toggle_quick_menu() ``` ### Setup From 212584d2819bb40d29459aba1c40a614be8adeeb Mon Sep 17 00:00:00 2001 From: Sebastian Lyng Johansen Date: Wed, 27 Oct 2021 21:46:05 +0200 Subject: [PATCH 02/10] remove popup.nvim as dependency --- README.md | 1 - lua/harpoon/cmd-ui.lua | 2 +- lua/harpoon/ui.lua | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b84bc2e..f1596fb 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,6 @@ Simply install via your favorite plugin manager. ```vim Plug 'nvim-lua/plenary.nvim' " don't forget to add this one if you don't have it yet! -Plug 'nvim-lua/popup.nvim' Plug 'ThePrimeagen/harpoon' ``` diff --git a/lua/harpoon/cmd-ui.lua b/lua/harpoon/cmd-ui.lua index 7a03cd0..ea764cf 100644 --- a/lua/harpoon/cmd-ui.lua +++ b/lua/harpoon/cmd-ui.lua @@ -1,5 +1,5 @@ local harpoon = require("harpoon") -local popup = require("popup") +local popup = require("plenary.popup") local log = require("harpoon.dev").log local term = require("harpoon.term") diff --git a/lua/harpoon/ui.lua b/lua/harpoon/ui.lua index ece2b3c..b448b94 100644 --- a/lua/harpoon/ui.lua +++ b/lua/harpoon/ui.lua @@ -1,5 +1,5 @@ local harpoon = require("harpoon") -local popup = require("popup") +local popup = require("plenary.popup") local Marked = require("harpoon.mark") local log = require("harpoon.dev").log From e27f59e93850dfc5a6b77a1d92dbc729b47ffa8a Mon Sep 17 00:00:00 2001 From: Alan Ciccotelli Date: Thu, 4 Nov 2021 00:40:40 +0000 Subject: [PATCH 03/10] feat: added excluded_filetypes option to avoid adding unwanted filetypes to the harpoon menu list. --- README.md | 2 ++ lua/harpoon/init.lua | 1 + lua/harpoon/mark.lua | 15 +++++++++++++++ 3 files changed, 18 insertions(+) diff --git a/README.md b/README.md index f1596fb..746666d 100644 --- a/README.md +++ b/README.md @@ -146,6 +146,7 @@ require("harpoon").setup({ save_on_toggle = false, save_on_change = true, enter_on_sendcmd = false, + excluded_filetypes = {"harpoon"} }, ... your other configs ... }) @@ -159,6 +160,7 @@ require("harpoon").setup({ what I have found). * `enter_on_sendcmd` will set harpoon to run the command immediately as it's passed to the terminal when calling `sendCommand`. +* `excluded_filetypes` filetypes that you want to prevent from adding to the harpoon list menu. #### Preconfigured Terminal Commands These are project specific commands that you wish to execute on the regular. diff --git a/lua/harpoon/init.lua b/lua/harpoon/init.lua index ae184ad..85609a2 100644 --- a/lua/harpoon/init.lua +++ b/lua/harpoon/init.lua @@ -157,6 +157,7 @@ M.setup = function(config) ["save_on_toggle"] = false, ["save_on_change"] = true, ["enter_on_sendcmd"] = false, + ["excluded_filetypes"] = {"harpoon"} }, }, expand_dir( c_config diff --git a/lua/harpoon/mark.lua b/lua/harpoon/mark.lua index b87e209..53f4346 100644 --- a/lua/harpoon/mark.lua +++ b/lua/harpoon/mark.lua @@ -115,6 +115,18 @@ local function validate_buf_name(buf_name) end end +local function filter_filetype() + local current_filetype = vim.bo.filetype + local excluded_filetypes = harpoon.get_global_settings().excluded_filetypes + for filetype = 1, #excluded_filetypes do + if(current_filetype == excluded_filetypes[filetype] or current_filetype == "harpoon") then + log.error('filter_filetype(): This filetype cannot be added or is included in the "excluded_filetypes" option') + error('This filetype cannot be added or is included in the "excluded_filetypes" option') + return + end + end +end + M.get_index_of = function(item) log.trace("get_index_of():", item) if item == nil then @@ -180,6 +192,7 @@ M.valid_index = function(idx) end M.add_file = function(file_name_or_buf_id) + filter_filetype(); local buf_name = get_buf_name(file_name_or_buf_id) log.trace("add_file():", buf_name) @@ -290,11 +303,13 @@ M.get_length = function() end M.set_current_at = function(idx) + filter_filetype() local buf_name = get_buf_name() log.trace("set_current_at(): Setting id", idx, buf_name) local config = harpoon.get_mark_config() local current_idx = M.get_index_of(buf_name) + -- Remove it if it already exists if M.valid_index(current_idx) then config.marks[current_idx] = create_mark("") From 2ed6b3e8ae9217aa73c3f4cf1596abc514943e60 Mon Sep 17 00:00:00 2001 From: Alan Ciccotelli Date: Fri, 5 Nov 2021 12:43:36 +0000 Subject: [PATCH 04/10] fix: removed harpoon check from loop, lint/format fix --- README.md | 2 +- lua/harpoon/init.lua | 2 +- lua/harpoon/mark.lua | 20 +++++++++++++++----- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 746666d..1e0fbd0 100644 --- a/README.md +++ b/README.md @@ -146,7 +146,7 @@ require("harpoon").setup({ save_on_toggle = false, save_on_change = true, enter_on_sendcmd = false, - excluded_filetypes = {"harpoon"} + excluded_filetypes = { "harpoon" } }, ... your other configs ... }) diff --git a/lua/harpoon/init.lua b/lua/harpoon/init.lua index 85609a2..86300b2 100644 --- a/lua/harpoon/init.lua +++ b/lua/harpoon/init.lua @@ -157,7 +157,7 @@ M.setup = function(config) ["save_on_toggle"] = false, ["save_on_change"] = true, ["enter_on_sendcmd"] = false, - ["excluded_filetypes"] = {"harpoon"} + ["excluded_filetypes"] = { "harpoon" }, }, }, expand_dir( c_config diff --git a/lua/harpoon/mark.lua b/lua/harpoon/mark.lua index 53f4346..14817fe 100644 --- a/lua/harpoon/mark.lua +++ b/lua/harpoon/mark.lua @@ -118,10 +118,21 @@ end local function filter_filetype() local current_filetype = vim.bo.filetype local excluded_filetypes = harpoon.get_global_settings().excluded_filetypes + + if current_filetype == "harpoon" then + log.error("filter_filetype(): You can't add harpoon to the harpoon") + error("You can't add harpoon to the harpoon") + return + end + for filetype = 1, #excluded_filetypes do - if(current_filetype == excluded_filetypes[filetype] or current_filetype == "harpoon") then - log.error('filter_filetype(): This filetype cannot be added or is included in the "excluded_filetypes" option') - error('This filetype cannot be added or is included in the "excluded_filetypes" option') + if current_filetype == excluded_filetypes[filetype] then + log.error( + 'filter_filetype(): This filetype cannot be added or is included in the "excluded_filetypes" option' + ) + error( + 'This filetype cannot be added or is included in the "excluded_filetypes" option' + ) return end end @@ -192,7 +203,7 @@ M.valid_index = function(idx) end M.add_file = function(file_name_or_buf_id) - filter_filetype(); + filter_filetype() local buf_name = get_buf_name(file_name_or_buf_id) log.trace("add_file():", buf_name) @@ -309,7 +320,6 @@ M.set_current_at = function(idx) local config = harpoon.get_mark_config() local current_idx = M.get_index_of(buf_name) - -- Remove it if it already exists if M.valid_index(current_idx) then config.marks[current_idx] = create_mark("") From 0eced8969b788a846fed0860708a26c857aa6674 Mon Sep 17 00:00:00 2001 From: Alan Date: Fri, 5 Nov 2021 16:39:13 +0000 Subject: [PATCH 05/10] refactor: replaced loop for tbl_contains --- lua/harpoon/mark.lua | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/lua/harpoon/mark.lua b/lua/harpoon/mark.lua index 14817fe..6d7fd3d 100644 --- a/lua/harpoon/mark.lua +++ b/lua/harpoon/mark.lua @@ -125,16 +125,14 @@ local function filter_filetype() return end - for filetype = 1, #excluded_filetypes do - if current_filetype == excluded_filetypes[filetype] then - log.error( - 'filter_filetype(): This filetype cannot be added or is included in the "excluded_filetypes" option' - ) - error( - 'This filetype cannot be added or is included in the "excluded_filetypes" option' - ) - return - end + if vim.tbl_contains(excluded_filetypes, current_filetype) then + log.error( + 'filter_filetype(): This filetype cannot be added or is included in the "excluded_filetypes" option' + ) + error( + 'This filetype cannot be added or is included in the "excluded_filetypes" option' + ) + return end end From f227419697ce183197fa61771918daa49eefc12c Mon Sep 17 00:00:00 2001 From: clbrunet Date: Sun, 7 Nov 2021 15:47:04 +0100 Subject: [PATCH 06/10] refactor(ui): use 'number' option in quick_menu like in cmd-ui --- lua/harpoon/cmd-ui.lua | 7 ++----- lua/harpoon/ui.lua | 13 ++++++------- lua/harpoon/utils.lua | 3 +++ 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/lua/harpoon/cmd-ui.lua b/lua/harpoon/cmd-ui.lua index ea764cf..dc72714 100644 --- a/lua/harpoon/cmd-ui.lua +++ b/lua/harpoon/cmd-ui.lua @@ -1,5 +1,6 @@ local harpoon = require("harpoon") local popup = require("plenary.popup") +local utils = require("harpoon.utils") local log = require("harpoon.dev").log local term = require("harpoon.term") @@ -53,17 +54,13 @@ local function create_window() } end -local function is_white_space(str) - return str:gsub("%s", "") == "" -end - local function get_menu_items() log.trace("_get_menu_items()") local lines = vim.api.nvim_buf_get_lines(Harpoon_cmd_bufh, 0, -1, true) local indices = {} for _, line in pairs(lines) do - if not is_white_space(line) then + if not utils.is_white_space(line) then table.insert(indices, line) end end diff --git a/lua/harpoon/ui.lua b/lua/harpoon/ui.lua index b448b94..927f326 100644 --- a/lua/harpoon/ui.lua +++ b/lua/harpoon/ui.lua @@ -1,6 +1,7 @@ local harpoon = require("harpoon") local popup = require("plenary.popup") local Marked = require("harpoon.mark") +local utils = require("harpoon.utils") local log = require("harpoon.dev").log local M = {} @@ -60,12 +61,9 @@ local function get_menu_items() local lines = vim.api.nvim_buf_get_lines(Harpoon_bufh, 0, -1, true) local indices = {} - for idx = 1, #lines do - local space_location = string.find(lines[idx], " ") - log.debug("_get_menu_items():", idx, space_location) - - if space_location ~= nil then - table.insert(indices, string.sub(lines[idx], space_location + 1)) + for _, line in pairs(lines) do + if not utils.is_white_space(line) then + table.insert(indices, line) end end @@ -91,9 +89,10 @@ M.toggle_quick_menu = function() if file == "" then file = "(empty)" end - contents[idx] = string.format("%d %s", idx, file) + contents[idx] = string.format("%s", file) end + vim.api.nvim_win_set_option(Harpoon_win_id, "number", true) vim.api.nvim_buf_set_name(Harpoon_bufh, "harpoon-menu") vim.api.nvim_buf_set_lines(Harpoon_bufh, 0, #contents, false, contents) vim.api.nvim_buf_set_option(Harpoon_bufh, "filetype", "harpoon") diff --git a/lua/harpoon/utils.lua b/lua/harpoon/utils.lua index 11161df..dd40766 100644 --- a/lua/harpoon/utils.lua +++ b/lua/harpoon/utils.lua @@ -6,6 +6,9 @@ local M = { normalize_path = function(item) return Path:new(item):make_relative(vim.loop.cwd()) end, + is_white_space = function(str) + return str:gsub("%s", "") == "" + end, } return M From 2802a19c89f6308cabc02170d3617dee311035ab Mon Sep 17 00:00:00 2001 From: clbrunet Date: Sun, 7 Nov 2021 17:43:03 +0100 Subject: [PATCH 07/10] feat(cmd-ui): add 'q' and '' keymaps to close the quick menu --- lua/harpoon/cmd-ui.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lua/harpoon/cmd-ui.lua b/lua/harpoon/cmd-ui.lua index dc72714..ad1d197 100644 --- a/lua/harpoon/cmd-ui.lua +++ b/lua/harpoon/cmd-ui.lua @@ -95,6 +95,20 @@ M.toggle_quick_menu = function() vim.api.nvim_buf_set_option(Harpoon_cmd_bufh, "filetype", "harpoon") vim.api.nvim_buf_set_option(Harpoon_cmd_bufh, "buftype", "acwrite") vim.api.nvim_buf_set_option(Harpoon_cmd_bufh, "bufhidden", "delete") + vim.api.nvim_buf_set_keymap( + Harpoon_cmd_bufh, + "n", + "q", + ":lua require('harpoon.cmd-ui').toggle_quick_menu()", + { silent = true } + ) + vim.api.nvim_buf_set_keymap( + Harpoon_cmd_bufh, + "n", + "", + ":lua require('harpoon.cmd-ui').toggle_quick_menu()", + { silent = true } + ) -- TODO: maybe vim.fn.input() can be used to implement some select_menu_item -- vim.api.nvim_buf_set_keymap( -- Harpoon_cmd_bufh, From 9571887e57f7df490004717e0254cc81bedf5779 Mon Sep 17 00:00:00 2001 From: clbrunet Date: Sun, 7 Nov 2021 17:44:46 +0100 Subject: [PATCH 08/10] feat(cmd-ui): add keymap for selecting menu item The selected command is sent to terminal index got from vim.fn.input --- lua/harpoon/cmd-ui.lua | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/lua/harpoon/cmd-ui.lua b/lua/harpoon/cmd-ui.lua index ad1d197..67698bf 100644 --- a/lua/harpoon/cmd-ui.lua +++ b/lua/harpoon/cmd-ui.lua @@ -109,14 +109,13 @@ M.toggle_quick_menu = function() ":lua require('harpoon.cmd-ui').toggle_quick_menu()", { silent = true } ) - -- TODO: maybe vim.fn.input() can be used to implement some select_menu_item - -- vim.api.nvim_buf_set_keymap( - -- Harpoon_cmd_bufh, - -- "n", - -- "", - -- ":lua require('harpoon.cmd-ui').select_menu_item()", - -- {} - -- ) + vim.api.nvim_buf_set_keymap( + Harpoon_cmd_bufh, + "n", + "", + ":lua require('harpoon.cmd-ui').select_menu_item()", + {} + ) vim.cmd( string.format( "autocmd BufWriteCmd :lua require('harpoon.cmd-ui').on_menu_save()", @@ -139,6 +138,20 @@ M.toggle_quick_menu = function() ) end +M.select_menu_item = function() + log.trace("cmd-ui#select_menu_item()") + local cmd = vim.fn.line(".") + close_menu(true) + local answer = vim.fn.input("Terminal index (default to 1): ") + if answer == "" then + answer = "1" + end + local idx = tonumber(answer) + if idx then + term.sendCommand(idx, cmd) + end +end + M.on_menu_save = function() log.trace("cmd-ui#on_menu_save()") term.set_cmd_list(get_menu_items()) From 031cfa6f9c2e7fbcaa3d9fce78704633625e1da7 Mon Sep 17 00:00:00 2001 From: clbrunet Date: Tue, 9 Nov 2021 08:01:32 +0100 Subject: [PATCH 09/10] fix: use instead of ':' in quick menus remaps Quick menus remaps now work even if a user uses a ':' remap. --- c.c | 1 + lua/harpoon/cmd-ui.lua | 10 +++++----- lua/harpoon/ui.lua | 12 ++++++------ 3 files changed, 12 insertions(+), 11 deletions(-) create mode 100644 c.c diff --git a/c.c b/c.c new file mode 100644 index 0000000..86ae29c --- /dev/null +++ b/c.c @@ -0,0 +1 @@ +ba diff --git a/lua/harpoon/cmd-ui.lua b/lua/harpoon/cmd-ui.lua index 67698bf..470673f 100644 --- a/lua/harpoon/cmd-ui.lua +++ b/lua/harpoon/cmd-ui.lua @@ -99,33 +99,33 @@ M.toggle_quick_menu = function() Harpoon_cmd_bufh, "n", "q", - ":lua require('harpoon.cmd-ui').toggle_quick_menu()", + "lua require('harpoon.cmd-ui').toggle_quick_menu()", { silent = true } ) vim.api.nvim_buf_set_keymap( Harpoon_cmd_bufh, "n", "", - ":lua require('harpoon.cmd-ui').toggle_quick_menu()", + "lua require('harpoon.cmd-ui').toggle_quick_menu()", { silent = true } ) vim.api.nvim_buf_set_keymap( Harpoon_cmd_bufh, "n", "", - ":lua require('harpoon.cmd-ui').select_menu_item()", + "lua require('harpoon.cmd-ui').select_menu_item()", {} ) vim.cmd( string.format( - "autocmd BufWriteCmd :lua require('harpoon.cmd-ui').on_menu_save()", + "autocmd BufWriteCmd lua require('harpoon.cmd-ui').on_menu_save()", Harpoon_cmd_bufh ) ) if global_config.save_on_change then vim.cmd( string.format( - "autocmd TextChanged,TextChangedI :lua require('harpoon.cmd-ui').on_menu_save()", + "autocmd TextChanged,TextChangedI lua require('harpoon.cmd-ui').on_menu_save()", Harpoon_cmd_bufh ) ) diff --git a/lua/harpoon/ui.lua b/lua/harpoon/ui.lua index 927f326..c9c4f46 100644 --- a/lua/harpoon/ui.lua +++ b/lua/harpoon/ui.lua @@ -102,33 +102,33 @@ M.toggle_quick_menu = function() Harpoon_bufh, "n", "q", - ":lua require('harpoon.ui').toggle_quick_menu()", + "lua require('harpoon.ui').toggle_quick_menu()", { silent = true } ) vim.api.nvim_buf_set_keymap( Harpoon_bufh, "n", "", - ":lua require('harpoon.ui').toggle_quick_menu()", + "lua require('harpoon.ui').toggle_quick_menu()", { silent = true } ) vim.api.nvim_buf_set_keymap( Harpoon_bufh, "n", "", - ":lua require('harpoon.ui').select_menu_item()", + "lua require('harpoon.ui').select_menu_item()", {} ) vim.cmd( string.format( - "autocmd BufWriteCmd :lua require('harpoon.ui').on_menu_save()", + "autocmd BufWriteCmd lua require('harpoon.ui').on_menu_save()", Harpoon_bufh ) ) if global_config.save_on_change then vim.cmd( string.format( - "autocmd TextChanged,TextChangedI :lua require('harpoon.ui').on_menu_save()", + "autocmd TextChanged,TextChangedI lua require('harpoon.ui').on_menu_save()", Harpoon_bufh ) ) @@ -140,7 +140,7 @@ M.toggle_quick_menu = function() ) ) vim.cmd( - "autocmd BufLeave ++nested ++once :silent lua require('harpoon.ui').toggle_quick_menu()" + "autocmd BufLeave ++nested ++once silent lua require('harpoon.ui').toggle_quick_menu()" ) end From f7c24f4fdc5c5365b802f882cccfc2d7b4447180 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Brunet?= Date: Tue, 9 Nov 2021 17:58:34 +0100 Subject: [PATCH 10/10] Delete c.c I'm sorry, i added this file by mistake. --- c.c | 1 - 1 file changed, 1 deletion(-) delete mode 100644 c.c diff --git a/c.c b/c.c deleted file mode 100644 index 86ae29c..0000000 --- a/c.c +++ /dev/null @@ -1 +0,0 @@ -ba