diff --git a/README.md b/README.md index 5e50f64..834a317 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,7 @@ The following default mappings are included: mx Set mark x m, Set the next available alphabetical (lowercase) mark m; Toggle the next available mark at the current line + Mx Toggle a inputed mark at the current line dmx Delete mark x dm- Delete all marks on the current line dm Delete all marks in the current buffer @@ -115,6 +116,7 @@ The following keys are available to be passed to the mapping table: ``` set_next Set next available lowercase mark at cursor. toggle Toggle next available mark at cursor. + toggle_mark Toggle a inputed mark at the current line. delete_line Deletes all marks on current line. delete_buf Deletes all marks in current buffer. next Goes to next mark in buffer. @@ -146,6 +148,7 @@ marks.nvim also provides a list of `` mappings for you, in case you want t (Marks-set) (Marks-setnext) (Marks-toggle) +(Marks-togglemark) (Marks-delete) (Marks-deleteline) (Marks-deletebuf) diff --git a/doc/marks-nvim.txt b/doc/marks-nvim.txt index d9c6135..88f8e01 100644 --- a/doc/marks-nvim.txt +++ b/doc/marks-nvim.txt @@ -169,6 +169,7 @@ The following mappings are defined by default: mx Set mark x m, Set the next available alphabetical (lowercase) mark m; Toggle the next available mark at the current line + Mx Toggle a inputed mark at the current line dmx Delete mark x dm- Delete all marks on the current line dm Delete all marks in the current buffer @@ -192,6 +193,7 @@ The following are the available keys of the mapping table (see above as well): set_next Set the next available alphabetical mark set Set a named mark (will wait for input). toggle Toggle a mark at the cursor. + toggle_mark Toggle a inputed mark at the current line. next Move to the next mark prev Move to the previous mark. delete Delete a mark (will wait for input). @@ -258,6 +260,7 @@ on the functionality of each mapping): (Marks-set) (Marks-setnext) (Marks-toggle) + (Marks-togglemark) (Marks-delete) (Marks-deleteline) (Marks-deletebuf) diff --git a/doc/tags b/doc/tags new file mode 100644 index 0000000..1057350 --- /dev/null +++ b/doc/tags @@ -0,0 +1,32 @@ +:BookmarksList marks-nvim.txt /*:BookmarksList* +:BookmarksListAll marks-nvim.txt /*:BookmarksListAll* +:BookmarksQFList marks-nvim.txt /*:BookmarksQFList* +:BookmarksQFListAll marks-nvim.txt /*:BookmarksQFListAll* +:MarksListAll marks-nvim.txt /*:MarksListAll* +:MarksListBuf marks-nvim.txt /*:MarksListBuf* +:MarksListGlobal marks-nvim.txt /*:MarksListGlobal* +:MarksQFListAll marks-nvim.txt /*:MarksQFListAll* +:MarksQFListBuf marks-nvim.txt /*:MarksQFListBuf* +:MarksQFListGlobal marks-nvim.txt /*:MarksQFListGlobal* +:MarksToggleSigns marks-nvim.txt /*:MarksToggleSigns* +MarkSignHL marks-nvim.txt /*MarkSignHL* +MarkSignNumHL marks-nvim.txt /*MarkSignNumHL* +MarkVirtTextHL marks-nvim.txt /*MarkVirtTextHL* +marks-bookmark_config marks-nvim.txt /*marks-bookmark_config* +marks-bookmarks marks-nvim.txt /*marks-bookmarks* +marks-builtin marks-nvim.txt /*marks-builtin* +marks-cmds marks-nvim.txt /*marks-cmds* +marks-contrib marks-nvim.txt /*marks-contrib* +marks-cyclic marks-nvim.txt /*marks-cyclic* +marks-default_mappings marks-nvim.txt /*marks-default_mappings* +marks-excluded_filetypes marks-nvim.txt /*marks-excluded_filetypes* +marks-force_write_shada marks-nvim.txt /*marks-force_write_shada* +marks-introduction marks-nvim.txt /*marks-introduction* +marks-license marks-nvim.txt /*marks-license* +marks-mappings marks-nvim.txt /*marks-mappings* +marks-nvim marks-nvim.txt /*marks-nvim* +marks-refresh_interval marks-nvim.txt /*marks-refresh_interval* +marks-setup marks-nvim.txt /*marks-setup* +marks-sign_priority marks-nvim.txt /*marks-sign_priority* +marks-signs marks-nvim.txt /*marks-signs* +marks.nvim marks-nvim.txt /*marks.nvim* diff --git a/lua/marks/init.lua b/lua/marks/init.lua index 32dbc96..31269c9 100644 --- a/lua/marks/init.lua +++ b/lua/marks/init.lua @@ -31,6 +31,21 @@ function M.toggle() end end +function M.toggle_mark() + local err, input = pcall(function() + return string.char(vim.fn.getchar()) + end) + if not err then + return + end + + if utils.is_valid_mark(input) then + if not M.excluded_fts[vim.bo.ft] then + M.mark_state:toggle_mark(input) + end + end +end + function M.delete() local err, input = pcall(function() return string.char(vim.fn.getchar()) @@ -138,6 +153,7 @@ M.mappings = { set = "m", set_next = "m,", toggle = "m;", + toggle_mark = "M", next = "m]", prev = "m[", preview = "m:", diff --git a/lua/marks/mark.lua b/lua/marks/mark.lua index 8c3607d..fb76157 100644 --- a/lua/marks/mark.lua +++ b/lua/marks/mark.lua @@ -150,6 +150,24 @@ function Mark:toggle_mark_cursor() end end +function Mark:toggle_mark(mark) + local bufnr = a.nvim_get_current_buf() + local pos = a.nvim_win_get_cursor(0) + + local is_marked = false + local buffer = self.buffers[bufnr] + if buffer and buffer.placed_marks[mark] and buffer.placed_marks[mark].line == pos[1] then + is_marked = true + end + + if is_marked then + self:delete_mark(mark) + else + self:register_mark(mark, pos[1], pos[2], bufnr) + vim.cmd("normal! m" .. mark) + end +end + function Mark:delete_buf_marks(clear) clear = utils.option_nil(clear, true) local bufnr = a.nvim_get_current_buf() diff --git a/plugin/marks.vim b/plugin/marks.vim index e15c4b5..5cf08cd 100644 --- a/plugin/marks.vim +++ b/plugin/marks.vim @@ -25,6 +25,7 @@ command! BookmarksQFListAll exe "lua require'marks'.bookmark_state:all_to_list(' nnoremap (Marks-set) lua require'marks'.set() nnoremap (Marks-setnext) lua require'marks'.set_next() nnoremap (Marks-toggle) lua require'marks'.toggle() +nnoremap (Marks-togglemark) lua require'marks'.toggle_mark() nnoremap (Marks-delete) lua require'marks'.delete() nnoremap (Marks-deleteline) lua require'marks'.delete_line() nnoremap (Marks-deletebuf) lua require'marks'.delete_buf()