mirror of
https://github.com/ThePrimeagen/harpoon.git
synced 2025-07-13 17:40:25 +00:00
Merge branch 'master' into fix-merge-conflict
This commit is contained in:
commit
222b984dac
@ -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'
|
||||
```
|
||||
|
||||
@ -124,7 +123,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
|
||||
@ -147,6 +146,7 @@ require("harpoon").setup({
|
||||
save_on_toggle = false,
|
||||
save_on_change = true,
|
||||
enter_on_sendcmd = false,
|
||||
excluded_filetypes = { "harpoon" }
|
||||
},
|
||||
... your other configs ...
|
||||
})
|
||||
@ -160,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.
|
||||
|
@ -1,5 +1,6 @@
|
||||
local harpoon = require("harpoon")
|
||||
local popup = require("popup")
|
||||
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
|
||||
@ -98,24 +95,37 @@ 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")
|
||||
-- TODO: maybe vim.fn.input() can be used to implement some select_menu_item
|
||||
-- vim.api.nvim_buf_set_keymap(
|
||||
-- Harpoon_cmd_bufh,
|
||||
-- "n",
|
||||
-- "<CR>",
|
||||
-- ":lua require('harpoon.cmd-ui').select_menu_item()<CR>",
|
||||
-- {}
|
||||
-- )
|
||||
vim.api.nvim_buf_set_keymap(
|
||||
Harpoon_cmd_bufh,
|
||||
"n",
|
||||
"q",
|
||||
"<Cmd>lua require('harpoon.cmd-ui').toggle_quick_menu()<CR>",
|
||||
{ silent = true }
|
||||
)
|
||||
vim.api.nvim_buf_set_keymap(
|
||||
Harpoon_cmd_bufh,
|
||||
"n",
|
||||
"<ESC>",
|
||||
"<Cmd>lua require('harpoon.cmd-ui').toggle_quick_menu()<CR>",
|
||||
{ silent = true }
|
||||
)
|
||||
vim.api.nvim_buf_set_keymap(
|
||||
Harpoon_cmd_bufh,
|
||||
"n",
|
||||
"<CR>",
|
||||
"<Cmd>lua require('harpoon.cmd-ui').select_menu_item()<CR>",
|
||||
{}
|
||||
)
|
||||
vim.cmd(
|
||||
string.format(
|
||||
"autocmd BufWriteCmd <buffer=%s> :lua require('harpoon.cmd-ui').on_menu_save()",
|
||||
"autocmd BufWriteCmd <buffer=%s> 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 <buffer=%s> :lua require('harpoon.cmd-ui').on_menu_save()",
|
||||
"autocmd TextChanged,TextChangedI <buffer=%s> lua require('harpoon.cmd-ui').on_menu_save()",
|
||||
Harpoon_cmd_bufh
|
||||
)
|
||||
)
|
||||
@ -128,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())
|
||||
|
@ -158,6 +158,7 @@ M.setup = function(config)
|
||||
["save_on_change"] = true,
|
||||
["enter_on_sendcmd"] = false,
|
||||
["tmux_autoclose_windows"] = false,
|
||||
["excluded_filetypes"] = { "harpoon" },
|
||||
},
|
||||
}, expand_dir(
|
||||
c_config
|
||||
|
@ -115,6 +115,27 @@ 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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
M.get_index_of = function(item)
|
||||
log.trace("get_index_of():", item)
|
||||
if item == nil then
|
||||
@ -180,6 +201,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,6 +312,7 @@ 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()
|
||||
|
@ -1,6 +1,7 @@
|
||||
local harpoon = require("harpoon")
|
||||
local popup = require("popup")
|
||||
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")
|
||||
@ -103,33 +102,33 @@ M.toggle_quick_menu = function()
|
||||
Harpoon_bufh,
|
||||
"n",
|
||||
"q",
|
||||
":lua require('harpoon.ui').toggle_quick_menu()<CR>",
|
||||
"<Cmd>lua require('harpoon.ui').toggle_quick_menu()<CR>",
|
||||
{ silent = true }
|
||||
)
|
||||
vim.api.nvim_buf_set_keymap(
|
||||
Harpoon_bufh,
|
||||
"n",
|
||||
"<ESC>",
|
||||
":lua require('harpoon.ui').toggle_quick_menu()<CR>",
|
||||
"<Cmd>lua require('harpoon.ui').toggle_quick_menu()<CR>",
|
||||
{ silent = true }
|
||||
)
|
||||
vim.api.nvim_buf_set_keymap(
|
||||
Harpoon_bufh,
|
||||
"n",
|
||||
"<CR>",
|
||||
":lua require('harpoon.ui').select_menu_item()<CR>",
|
||||
"<Cmd>lua require('harpoon.ui').select_menu_item()<CR>",
|
||||
{}
|
||||
)
|
||||
vim.cmd(
|
||||
string.format(
|
||||
"autocmd BufWriteCmd <buffer=%s> :lua require('harpoon.ui').on_menu_save()",
|
||||
"autocmd BufWriteCmd <buffer=%s> lua require('harpoon.ui').on_menu_save()",
|
||||
Harpoon_bufh
|
||||
)
|
||||
)
|
||||
if global_config.save_on_change then
|
||||
vim.cmd(
|
||||
string.format(
|
||||
"autocmd TextChanged,TextChangedI <buffer=%s> :lua require('harpoon.ui').on_menu_save()",
|
||||
"autocmd TextChanged,TextChangedI <buffer=%s> lua require('harpoon.ui').on_menu_save()",
|
||||
Harpoon_bufh
|
||||
)
|
||||
)
|
||||
@ -141,7 +140,7 @@ M.toggle_quick_menu = function()
|
||||
)
|
||||
)
|
||||
vim.cmd(
|
||||
"autocmd BufLeave <buffer> ++nested ++once :silent lua require('harpoon.ui').toggle_quick_menu()"
|
||||
"autocmd BufLeave <buffer> ++nested ++once silent lua require('harpoon.ui').toggle_quick_menu()"
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -35,6 +35,9 @@ local M = {
|
||||
|
||||
return result
|
||||
end,
|
||||
is_white_space = function(str)
|
||||
return str:gsub("%s", "") == ""
|
||||
end,
|
||||
}
|
||||
|
||||
return M
|
||||
|
Loading…
x
Reference in New Issue
Block a user