Skip to content

Commit

Permalink
feat(nvim): rework mark utils, add quickfix marks
Browse files Browse the repository at this point in the history
  • Loading branch information
sbulav committed Feb 23, 2024
1 parent f947355 commit 22f46a3
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 11 deletions.
11 changes: 5 additions & 6 deletions nvim/after/plugin/keymap.vim
Original file line number Diff line number Diff line change
Expand Up @@ -216,17 +216,16 @@ nnoremap <leader>o :w <bar> %bd <bar> e# <bar> bd# <CR>
nnoremap ; q:A
" Simply run a make command
nnoremap <leader>m :Telescope marks<CR>
nnoremap <leader>md :delmarks!<CR> <bar> :delmarks A-Z <CR> <bar> :lua require("utils.marks").refresh()<CR>
nnoremap mo mO <bar>:lua require("utils.marks").refresh()<CR>
nnoremap <A-n> `N
nnoremap <A-e> `E
nnoremap <A-i> `I
nnoremap <A-o> `O
nnoremap <BS>n mN <bar>:lua require("utils.marks").refresh()<CR>
nnoremap <BS>e mE <bar>:lua require("utils.marks").refresh()<CR>
nnoremap <BS>i mI <bar>:lua require("utils.marks").refresh()<CR>
nnoremap <BS>o mO <bar>:lua require("utils.marks").refresh()<CR>
nnoremap <leader>m :lua require("utils.marks").marks_to_quickfix_list() <CR>
nnoremap <leader><leader>n mN <bar>:lua require("utils.marks").refresh()<CR>
nnoremap <leader><leader>e mE <bar>:lua require("utils.marks").refresh()<CR>
nnoremap <leader><leader>i mI <bar>:lua require("utils.marks").refresh()<CR>
nnoremap <leader><leader>o mO <bar>:lua require("utils.marks").refresh()<CR>
nnoremap mn mN <bar>:lua require("utils.marks").refresh()<CR>
nnoremap me mE <bar>:lua require("utils.marks").refresh()<CR>
nnoremap mi mI <bar>:lua require("utils.marks").refresh()<CR>
Expand Down
11 changes: 10 additions & 1 deletion nvim/lua/plugins/qf_helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ return {
"stevearc/qf_helper.nvim",
event = "VeryLazy",
config = function()
require("qf_helper").setup {}
require("qf_helper").setup {
quickfix = {
autoclose = true, -- Autoclose qf if it's the only open window
default_bindings = true, -- Set up recommended bindings in qf window
default_options = true, -- Set recommended buffer and window options
max_height = 10, -- Max qf height when using open() or toggle()
min_height = 1, -- Min qf height when using open() or toggle()
track_location = false, -- Keep qf updated with your current location
},
}
end,
}
6 changes: 3 additions & 3 deletions nvim/lua/utils/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ function M.cheatSheetCommand(detect_language)

local command = ""
if searchPhrase == nil then
command = language
command = language
else
command = language .. "/" .. searchPhrase
end
command = language .. "/" .. searchPhrase
end

M.info("cht.sh/" .. command, "Cheat Sheet Query")
return ("!curl -s cht.sh/" .. command)
Expand Down
31 changes: 30 additions & 1 deletion nvim/lua/utils/marks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ end
local function is_lower(char)
return (97 <= char:byte() and char:byte() <= 122)
end

local function path_exists(path)
return vim.loop.fs_stat(path) and true or false
end
local function define_sign(name)
if is_upper(name) then
vim.fn.sign_define(name, {
Expand Down Expand Up @@ -68,6 +70,33 @@ local function add_local_marks()
end
end

function M.marks_to_quickfix_list()
local global_marks = {
items = vim.fn.getmarklist(),
name_func = function(mark, _)
-- get buffer name if it is opened, otherwise get file name
return vim.api.nvim_get_mark(mark, {})[4]
end,
}
local marks_table = {}
for _, v in ipairs(global_marks.items) do
-- strip the first single quote character
local mark_name = string.sub(v.mark, 2, 3)
local _, lnum, col, _ = unpack(v.pos)
local row = {
text = mark_name,
filename = vim.fs.normalize(v.file),
lnum = lnum,
col = col,
}
if string.find("NEIO", mark_name) and path_exists(row.filename) then
table.insert(marks_table, row)
end
end
vim.fn.setqflist({}, " ", { title = "Bookmarks", id = "$", items = marks_table })
vim.cmd [[QFToggle]]
end

function M.setup(user_config)
if not user_config then
config = Defaults
Expand Down

0 comments on commit 22f46a3

Please sign in to comment.