From 6a9876afd797eb306f63cda250bc2815d3f3ceef Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 15 Mar 2020 16:08:59 +0100 Subject: Add mappings to move to the next and previous to-do `[u` and `]u` for "unfinished". --- autoload/todo/motion.vim | 13 +++++++++++++ ftplugin/todo.vim | 13 +++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 autoload/todo/motion.vim diff --git a/autoload/todo/motion.vim b/autoload/todo/motion.vim new file mode 100644 index 0000000..3ebab2d --- /dev/null +++ b/autoload/todo/motion.vim @@ -0,0 +1,13 @@ +let s:INCOMPLETE_MATCHER = '^\s*[\-_!] ' + + +function! todo#motion#NextIncomplete() + normal! m' + call search(s:INCOMPLETE_MATCHER) +endfunction + + +function! todo#motion#PreviousIncomplete() + normal! m' + call search(s:INCOMPLETE_MATCHER, 'b') +endfunction diff --git a/ftplugin/todo.vim b/ftplugin/todo.vim index f392c94..a223984 100644 --- a/ftplugin/todo.vim +++ b/ftplugin/todo.vim @@ -3,6 +3,8 @@ if exists("b:did_ftplugin") endif let b:did_ftplugin = 1 +" TODO: Add no_plugin_mappings or whatever + nnoremap TwodoNewTodoBelow o- nnoremap TwodoNewTodoAbove O- @@ -13,6 +15,9 @@ nnoremap TwodoRemoveOldTodos :g/^\s*[vx] /d \| nohl nnoremap TwodoEscalate :call todo#Escalate() nnoremap TwodoDescalate :call todo#Descalate() +nnoremap TwodoNextIncomplete :call todo#motion#NextIncomplete() +nnoremap TwodoPreviousIncomplete :call todo#motion#PreviousIncomplete() + if !hasmapto('TwodoNewTodoBelow') || !maparg('n', 'n') nmap n TwodoNewTodoBelow endif @@ -44,3 +49,11 @@ endif if !hasmapto('TwodoDescalate') || !maparg('-', 'n') nmap - TwodoDescalate endif + +if !hasmapto('TwodoNextIncomplete') && !maparg(']u', 'n') + nmap ]u TwodoNextIncomplete +endif + +if !hasmapto('TwodoPreviousIncomplete') && !maparg('[u', 'n') + nmap [u TwodoPreviousIncomplete +endif -- cgit v1.2.3 From 5ee078bc4c434764f413b036fcb39ca97b5ae74e Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 21 Mar 2020 17:59:40 +0100 Subject: Try adding xmaps and omaps for next and previous commands The xmaps don't really work. Going to the next/previous TODO works, but extending the selection doesn't because of the way I set it up with the mark system. We'd probably need a more involved function here to do what we want. Currently doesn't support counts. I'll have to add that in. --- ftplugin/todo.vim | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ftplugin/todo.vim b/ftplugin/todo.vim index a223984..c876313 100644 --- a/ftplugin/todo.vim +++ b/ftplugin/todo.vim @@ -17,6 +17,10 @@ nnoremap TwodoDescalate :call todo#Descalate() nnoremap TwodoNextIncomplete :call todo#motion#NextIncomplete() nnoremap TwodoPreviousIncomplete :call todo#motion#PreviousIncomplete() +xnoremap TwodoNextIncomplete :call todo#motion#NextIncomplete()v''o +xnoremap TwodoPreviousIncomplete :call todo#motion#PreviousIncomplete()v''o +onoremap TwodoNextIncomplete :call todo#motion#NextIncomplete() +onoremap TwodoPreviousIncomplete :call todo#motion#PreviousIncomplete() if !hasmapto('TwodoNewTodoBelow') || !maparg('n', 'n') nmap n TwodoNewTodoBelow @@ -52,8 +56,12 @@ endif if !hasmapto('TwodoNextIncomplete') && !maparg(']u', 'n') nmap ]u TwodoNextIncomplete + xmap ]u TwodoNextIncomplete + omap ]u TwodoNextIncomplete endif if !hasmapto('TwodoPreviousIncomplete') && !maparg('[u', 'n') nmap [u TwodoPreviousIncomplete + xmap [u TwodoPreviousIncomplete + omap [u TwodoPreviousIncomplete endif -- cgit v1.2.3 From 953c0b15706cb7f8cded7d6792e5031e2a78228f Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 21 Mar 2020 19:20:39 +0100 Subject: todo#motion#NextIncomplete(): Add count support --- autoload/todo/motion.vim | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/autoload/todo/motion.vim b/autoload/todo/motion.vim index 3ebab2d..96877a9 100644 --- a/autoload/todo/motion.vim +++ b/autoload/todo/motion.vim @@ -2,8 +2,15 @@ let s:INCOMPLETE_MATCHER = '^\s*[\-_!] ' function! todo#motion#NextIncomplete() + let cnt = v:count1 + normal! m' - call search(s:INCOMPLETE_MATCHER) + + let i = 0 + while i < cnt + call search(s:INCOMPLETE_MATCHER) + let i += 1 + endwhile endfunction -- cgit v1.2.3 From 0fa59c30f1a6f5e1a9796e5df53c7cd955994509 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 21 Mar 2020 19:44:44 +0100 Subject: Support counts in both `NextIncomplete()` and `PreviousIncomplete()` --- autoload/todo/motion.vim | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/autoload/todo/motion.vim b/autoload/todo/motion.vim index 96877a9..27d6264 100644 --- a/autoload/todo/motion.vim +++ b/autoload/todo/motion.vim @@ -1,20 +1,24 @@ let s:INCOMPLETE_MATCHER = '^\s*[\-_!] ' -function! todo#motion#NextIncomplete() +function! s:Incomplete(search_flags) let cnt = v:count1 normal! m' let i = 0 while i < cnt - call search(s:INCOMPLETE_MATCHER) + call search(s:INCOMPLETE_MATCHER, a:search_flags) let i += 1 endwhile endfunction +function! todo#motion#NextIncomplete() + call s:Incomplete('') +endfunction + + function! todo#motion#PreviousIncomplete() - normal! m' - call search(s:INCOMPLETE_MATCHER, 'b') + call s:Incomplete('b') endfunction -- cgit v1.2.3 From cb76590a7d75f9e49273b1f5ad7fbffaf3a0fd17 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 21 Mar 2020 20:01:34 +0100 Subject: motion.vim/s:Incomplete(): Use `s` search flag to mark Learned that `search()` accepts an `s` flag to mark the previous cursor location, so figured we should take advantage of that and remove the manual mark line. --- autoload/todo/motion.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/autoload/todo/motion.vim b/autoload/todo/motion.vim index 27d6264..32a7c88 100644 --- a/autoload/todo/motion.vim +++ b/autoload/todo/motion.vim @@ -1,14 +1,14 @@ let s:INCOMPLETE_MATCHER = '^\s*[\-_!] ' -function! s:Incomplete(search_flags) +function! s:Incomplete(extra_search_flags) let cnt = v:count1 - normal! m' + let search_flags = 's' . a:extra_search_flags let i = 0 while i < cnt - call search(s:INCOMPLETE_MATCHER, a:search_flags) + call search(s:INCOMPLETE_MATCHER, search_flags) let i += 1 endwhile endfunction -- cgit v1.2.3 From 374682458aeecb6b02cd88a612201feca8a0be12 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 21 Mar 2020 20:11:00 +0100 Subject: Remove `TwodoNextIncomplete` `TwodoPreviousIncomplete` xmaps I don't really use visual mode, and don't feel like trying to make these work. --- ftplugin/todo.vim | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ftplugin/todo.vim b/ftplugin/todo.vim index c876313..22880ac 100644 --- a/ftplugin/todo.vim +++ b/ftplugin/todo.vim @@ -17,8 +17,6 @@ nnoremap TwodoDescalate :call todo#Descalate() nnoremap TwodoNextIncomplete :call todo#motion#NextIncomplete() nnoremap TwodoPreviousIncomplete :call todo#motion#PreviousIncomplete() -xnoremap TwodoNextIncomplete :call todo#motion#NextIncomplete()v''o -xnoremap TwodoPreviousIncomplete :call todo#motion#PreviousIncomplete()v''o onoremap TwodoNextIncomplete :call todo#motion#NextIncomplete() onoremap TwodoPreviousIncomplete :call todo#motion#PreviousIncomplete() @@ -56,12 +54,10 @@ endif if !hasmapto('TwodoNextIncomplete') && !maparg(']u', 'n') nmap ]u TwodoNextIncomplete - xmap ]u TwodoNextIncomplete omap ]u TwodoNextIncomplete endif if !hasmapto('TwodoPreviousIncomplete') && !maparg('[u', 'n') nmap [u TwodoPreviousIncomplete - xmap [u TwodoPreviousIncomplete omap [u TwodoPreviousIncomplete endif -- cgit v1.2.3 From c7ac0e17fe4acb714b135f9b4ffac24351b3de56 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 21 Mar 2020 20:17:22 +0100 Subject: Add conditions for `[u` `]u` default omaps I put these in the normal mode conditions for ease of testing and implementation. Now check the mappings properly. --- ftplugin/todo.vim | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ftplugin/todo.vim b/ftplugin/todo.vim index 22880ac..e7664d8 100644 --- a/ftplugin/todo.vim +++ b/ftplugin/todo.vim @@ -52,12 +52,18 @@ if !hasmapto('TwodoDescalate') || !maparg('-', 'n') nmap - TwodoDescalate endif -if !hasmapto('TwodoNextIncomplete') && !maparg(']u', 'n') +if !hasmapto('TwodoNextIncomplete', 'n') && !maparg(']u', 'n') nmap ]u TwodoNextIncomplete +endif + +if !hasmapto('TwodoNextIncomplete', 'o') && !maparg(']u', 'o') omap ]u TwodoNextIncomplete endif -if !hasmapto('TwodoPreviousIncomplete') && !maparg('[u', 'n') +if !hasmapto('TwodoPreviousIncomplete', 'n') && !maparg('[u', 'n') nmap [u TwodoPreviousIncomplete +endif + +if !hasmapto('TwodoPreviousIncomplete', 'o') && !maparg('[u', 'o') omap [u TwodoPreviousIncomplete endif -- cgit v1.2.3