Merge branch 'master' into fix-merge-conflict

This commit is contained in:
Pranav Rao 2021-11-09 17:07:42 -05:00 committed by GitHub
commit 222b984dac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 83 additions and 32 deletions

View File

@ -32,7 +32,6 @@ Simply install via your favorite plugin manager.
```vim ```vim
Plug 'nvim-lua/plenary.nvim' " don't forget to add this one if you don't have it yet! 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' 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. This feature adds ability to change commands while working inside a project.
Just call the following function to edit commands inside the list Just call the following function to edit commands inside the list
```lua ```lua
lua require('harpoon.ui-cmd').toggle_quick_menu() lua require('harpoon.cmd-ui').toggle_quick_menu()
``` ```
### Setup ### Setup
@ -147,6 +146,7 @@ require("harpoon").setup({
save_on_toggle = false, save_on_toggle = false,
save_on_change = true, save_on_change = true,
enter_on_sendcmd = false, enter_on_sendcmd = false,
excluded_filetypes = { "harpoon" }
}, },
... your other configs ... ... your other configs ...
}) })
@ -160,6 +160,7 @@ require("harpoon").setup({
what I have found). what I have found).
* `enter_on_sendcmd` will set harpoon to run the command immediately as it's * `enter_on_sendcmd` will set harpoon to run the command immediately as it's
passed to the terminal when calling `sendCommand`. 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 #### Preconfigured Terminal Commands
These are project specific commands that you wish to execute on the regular. These are project specific commands that you wish to execute on the regular.

View File

@ -1,5 +1,6 @@
local harpoon = require("harpoon") 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 log = require("harpoon.dev").log
local term = require("harpoon.term") local term = require("harpoon.term")
@ -53,17 +54,13 @@ local function create_window()
} }
end end
local function is_white_space(str)
return str:gsub("%s", "") == ""
end
local function get_menu_items() local function get_menu_items()
log.trace("_get_menu_items()") log.trace("_get_menu_items()")
local lines = vim.api.nvim_buf_get_lines(Harpoon_cmd_bufh, 0, -1, true) local lines = vim.api.nvim_buf_get_lines(Harpoon_cmd_bufh, 0, -1, true)
local indices = {} local indices = {}
for _, line in pairs(lines) do 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) table.insert(indices, line)
end end
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, "filetype", "harpoon")
vim.api.nvim_buf_set_option(Harpoon_cmd_bufh, "buftype", "acwrite") 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_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(
-- vim.api.nvim_buf_set_keymap( Harpoon_cmd_bufh,
-- Harpoon_cmd_bufh, "n",
-- "n", "q",
-- "<CR>", "<Cmd>lua require('harpoon.cmd-ui').toggle_quick_menu()<CR>",
-- ":lua require('harpoon.cmd-ui').select_menu_item()<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( vim.cmd(
string.format( 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 Harpoon_cmd_bufh
) )
) )
if global_config.save_on_change then if global_config.save_on_change then
vim.cmd( vim.cmd(
string.format( 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 Harpoon_cmd_bufh
) )
) )
@ -128,6 +138,20 @@ M.toggle_quick_menu = function()
) )
end 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() M.on_menu_save = function()
log.trace("cmd-ui#on_menu_save()") log.trace("cmd-ui#on_menu_save()")
term.set_cmd_list(get_menu_items()) term.set_cmd_list(get_menu_items())

View File

@ -158,6 +158,7 @@ M.setup = function(config)
["save_on_change"] = true, ["save_on_change"] = true,
["enter_on_sendcmd"] = false, ["enter_on_sendcmd"] = false,
["tmux_autoclose_windows"] = false, ["tmux_autoclose_windows"] = false,
["excluded_filetypes"] = { "harpoon" },
}, },
}, expand_dir( }, expand_dir(
c_config c_config

View File

@ -115,6 +115,27 @@ local function validate_buf_name(buf_name)
end end
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) M.get_index_of = function(item)
log.trace("get_index_of():", item) log.trace("get_index_of():", item)
if item == nil then if item == nil then
@ -180,6 +201,7 @@ M.valid_index = function(idx)
end end
M.add_file = function(file_name_or_buf_id) M.add_file = function(file_name_or_buf_id)
filter_filetype()
local buf_name = get_buf_name(file_name_or_buf_id) local buf_name = get_buf_name(file_name_or_buf_id)
log.trace("add_file():", buf_name) log.trace("add_file():", buf_name)
@ -290,6 +312,7 @@ M.get_length = function()
end end
M.set_current_at = function(idx) M.set_current_at = function(idx)
filter_filetype()
local buf_name = get_buf_name() local buf_name = get_buf_name()
log.trace("set_current_at(): Setting id", idx, buf_name) log.trace("set_current_at(): Setting id", idx, buf_name)
local config = harpoon.get_mark_config() local config = harpoon.get_mark_config()

View File

@ -1,6 +1,7 @@
local harpoon = require("harpoon") local harpoon = require("harpoon")
local popup = require("popup") local popup = require("plenary.popup")
local Marked = require("harpoon.mark") local Marked = require("harpoon.mark")
local utils = require("harpoon.utils")
local log = require("harpoon.dev").log local log = require("harpoon.dev").log
local M = {} 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 lines = vim.api.nvim_buf_get_lines(Harpoon_bufh, 0, -1, true)
local indices = {} local indices = {}
for idx = 1, #lines do for _, line in pairs(lines) do
local space_location = string.find(lines[idx], " ") if not utils.is_white_space(line) then
log.debug("_get_menu_items():", idx, space_location) table.insert(indices, line)
if space_location ~= nil then
table.insert(indices, string.sub(lines[idx], space_location + 1))
end end
end end
@ -91,9 +89,10 @@ M.toggle_quick_menu = function()
if file == "" then if file == "" then
file = "(empty)" file = "(empty)"
end end
contents[idx] = string.format("%d %s", idx, file) contents[idx] = string.format("%s", file)
end 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_name(Harpoon_bufh, "harpoon-menu")
vim.api.nvim_buf_set_lines(Harpoon_bufh, 0, #contents, false, contents) vim.api.nvim_buf_set_lines(Harpoon_bufh, 0, #contents, false, contents)
vim.api.nvim_buf_set_option(Harpoon_bufh, "filetype", "harpoon") vim.api.nvim_buf_set_option(Harpoon_bufh, "filetype", "harpoon")
@ -103,33 +102,33 @@ M.toggle_quick_menu = function()
Harpoon_bufh, Harpoon_bufh,
"n", "n",
"q", "q",
":lua require('harpoon.ui').toggle_quick_menu()<CR>", "<Cmd>lua require('harpoon.ui').toggle_quick_menu()<CR>",
{ silent = true } { silent = true }
) )
vim.api.nvim_buf_set_keymap( vim.api.nvim_buf_set_keymap(
Harpoon_bufh, Harpoon_bufh,
"n", "n",
"<ESC>", "<ESC>",
":lua require('harpoon.ui').toggle_quick_menu()<CR>", "<Cmd>lua require('harpoon.ui').toggle_quick_menu()<CR>",
{ silent = true } { silent = true }
) )
vim.api.nvim_buf_set_keymap( vim.api.nvim_buf_set_keymap(
Harpoon_bufh, Harpoon_bufh,
"n", "n",
"<CR>", "<CR>",
":lua require('harpoon.ui').select_menu_item()<CR>", "<Cmd>lua require('harpoon.ui').select_menu_item()<CR>",
{} {}
) )
vim.cmd( vim.cmd(
string.format( 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 Harpoon_bufh
) )
) )
if global_config.save_on_change then if global_config.save_on_change then
vim.cmd( vim.cmd(
string.format( 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 Harpoon_bufh
) )
) )
@ -141,7 +140,7 @@ M.toggle_quick_menu = function()
) )
) )
vim.cmd( 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 end

View File

@ -35,6 +35,9 @@ local M = {
return result return result
end, end,
is_white_space = function(str)
return str:gsub("%s", "") == ""
end,
} }
return M return M