coq_nvim icon indicating copy to clipboard operation
coq_nvim copied to clipboard

Enable to use <tab> as jump_to_mark key

Open mozzieongit opened this issue 2 years ago • 3 comments

Hi, first of all: thanks for the software :)

I'm currently tinkering with my configuration and don't like the default keymap of <c-h> for jump_to_mark when using snippets (as I use it as backspace) and would like to change it to <tab>, but that would disable tab for the entire mode as the Nav_marks-function is always called, that prints, that no more marks are left, and exits to normal mode.

Could you add the functionality, that

  1. COQ.Nav_mark() doesn't exit to normal mode, when no more marks are left (and silently ignores that circumstance)
  2. Add a function that returns the number of marks left, so that I could do something like: imap <silent><expr> <tab> luaeval('COQ.count_marks()') > 0 ? "<c-\><c-n><cmd>lua COQ.Nav_mark()<cr>" : "<tab>"

This would also enable to continue using <c-h> as the key for jump_to_mark and also as backspace (as of vim's default behavior).

Or does it have side effects that I'm not aware of, as I've not used this plugin a lot yet?

mozzieongit avatar Aug 12 '22 19:08 mozzieongit

I created a very ugly solution using the following change to coq:

diff --git i/coq/server/registrants/marks.py w/coq/server/registrants/marks.py
index 8d4db872..bb5bf81d 100644
--- i/coq/server/registrants/marks.py
+++ w/coq/server/registrants/marks.py
@@ -159,3 +159,15 @@ def nav_mark(nvim: Nvim, stack: Stack) -> None:
     else:
         msg = LANG("no more marks")
         write(nvim, msg)
+
+@rpc(blocking=True)
+def if_marks(nvim: Nvim, stack: Stack) -> bool:
+    ns = create_ns(nvim, ns=NS)
+    win = cur_win(nvim)
+    buf = win_get_buf(nvim, win=win)
+
+    # Very ugly way of finding out whether there's marks available
+    if marks := deque(_marks(nvim, ns=ns, win=win, buf=buf)):
+        return True
+    else:
+        return False

And I defined in my ~/.vimrc:

imap <silent><expr> <tab> luaeval('COQ.If_marks()') ? "<c-\><c-n><cmd>lua COQ.Nav_mark()<cr>" : "<tab>"

However I'm not sure about this solution, and I use <S-tab> as the jump_to_mark key, to avoid potential breakage in the future..


In general, it'd be interesting if there was some "Super-tab" setting that would make insert mode <tab> do all of the following:

  • If pop up menu is closed and there are no marks available, send a regular "<Tab>" character ('\t') to the document.
  • If items are available in pop up menu, select the new item from there.
  • If marks are available, jump to the next one.

Coc has this feature, see:

https://github.com/neoclide/coc.nvim/blob/4b2c89a96b18f7d61dfa89acf2ea10ba230a1c60/doc/coc.txt#L450-L467

doronbehar avatar Aug 27 '22 06:08 doronbehar

See also:

https://github.com/ms-jpq/coq_nvim/pull/249

doronbehar avatar Aug 28 '22 06:08 doronbehar

+1 for this feature

neumannjan avatar May 13 '23 14:05 neumannjan