From e27f59e93850dfc5a6b77a1d92dbc729b47ffa8a Mon Sep 17 00:00:00 2001 From: Alan Ciccotelli Date: Thu, 4 Nov 2021 00:40:40 +0000 Subject: [PATCH 1/3] 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 2/3] 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 3/3] 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