diff --git a/README.md b/README.md index 140b6e79..38818be3 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ on a function, press `d`, jump quickly through `TODO` items using + [`g:doge_mapping_comment_jump_forward`](#gdoge_mapping_comment_jump_forward) + [`g:doge_mapping_comment_jump_backward`](#gdoge_mapping_comment_jump_backward) + [`g:doge_comment_interactive`](#gdoge_comment_interactive) + + [`g:doge_comment_jump_wrap`](#gdoge_comment_jump_wrap) - [Commands](#commands) + [`:DogeGenerate`](#dogegenerate) - [Help](#help) @@ -164,6 +165,12 @@ Default: `1` Jumps interactively through all `TODO` items in the generated comment. +### `g:doge_comment_jump_wrap` + +Default: `1` + +Continue to cycle among placeholders when reaching the start or end. + # Commands ### `:DogeGenerate` diff --git a/autoload/doge/comment.vim b/autoload/doge/comment.vim index b4efd0d9..640c0cb3 100644 --- a/autoload/doge/comment.vim +++ b/autoload/doge/comment.vim @@ -5,9 +5,20 @@ let s:comment_placeholder = doge#helpers#placeholder() " vint: next-line -ProhibitUnusedVariable function! s:jump_forward() abort - let l:wrap = g:doge_comment_jump_wrap ? 'w' : 'W' + let l:wrap = g:doge_comment_jump_wrap == v:true ? 'w' : 'W' let l:next_pos = search(s:comment_placeholder, 'n' . l:wrap) + if l:next_pos != 0 + \ && l:next_pos > b:doge_interactive['lnum_comment_end_pos'] + \ && g:doge_comment_jump_wrap == v:true + \ && mode() ==# 's' + " If we have more TODO items below the comment then we'll go back to the + " start position of the comment so we can continue to cycle. This option is + " a 2nd solution besides the 'w' or 'W' being used in the initial search() + " function (called at the top of this function). + return "\:" . b:doge_interactive['lnum_comment_start_pos'] . "\/" . s:comment_placeholder . "\:silent! noh\gno\" + endif + " Check if the next pos we want to jump to is still inside the comment. if l:next_pos != 0 && l:next_pos <= b:doge_interactive['lnum_comment_end_pos'] if mode() ==# 'i' @@ -29,9 +40,20 @@ endfunction " vint: next-line -ProhibitUnusedVariable function! s:jump_backward() abort - let l:wrap = g:doge_comment_jump_wrap ? 'w' : 'W' + let l:wrap = g:doge_comment_jump_wrap == v:true ? 'w' : 'W' let l:prev_pos = search(s:comment_placeholder, 'bn' . l:wrap) + if l:prev_pos != 0 + \ && l:prev_pos < b:doge_interactive['lnum_comment_start_pos'] + \ && g:doge_comment_jump_wrap == v:true + \ && mode() ==# 's' + " If we have more TODO items above the comment then we'll go forward to the + " end position of the comment so we can continue to cycle. This option is + " a 2nd solution besides the 'w' or 'W' being used in the initial search() + " function (called at the top of this function). + return "\:" . b:doge_interactive['lnum_comment_end_pos'] . "\?" . s:comment_placeholder . "\:silent! noh\gno\" + endif + " Check if the prev pos we want to jump to is still inside the comment. if l:prev_pos != 0 && l:prev_pos >= b:doge_interactive['lnum_comment_start_pos'] if mode() ==# 'i' diff --git a/doc/doge.txt b/doc/doge.txt index 1deadeb9..2b0ec32e 100644 --- a/doc/doge.txt +++ b/doc/doge.txt @@ -34,6 +34,11 @@ Whether or not to enable built-in mappings. The mapping to trigger DoGe. + *g:doge_comment_jump_wrap* +(Default: 1) + +Continue to cycle among placeholders when reaching the start or end. + *g:doge_mapping_comment_jump_forward* (Default: '') @@ -51,12 +56,6 @@ The mapping to jump backward to the previous TODO item in a comment. Requires Jumps interactively through all TODO items in the generated comment. - *g:doge_comment_jump_wrap* -(Default: 0) - -Cycle among placeholders when reaching the last one (or first one if jumping -backwards). - ============================================================================== COMMANDS *doge-commands* diff --git a/doc/tags b/doc/tags index dec030f0..a62c7d8d 100644 --- a/doc/tags +++ b/doc/tags @@ -7,6 +7,7 @@ doge#generate() doge.txt /*doge#generate()* doge#helpers#count() doge.txt /*doge#helpers#count()* doge#helpers#keyseq() doge.txt /*doge#helpers#keyseq()* doge#helpers#placeholder() doge.txt /*doge#helpers#placeholder()* +doge#helpers#trim() doge.txt /*doge#helpers#trim()* doge#indent#add() doge.txt /*doge#indent#add()* doge#token#extract() doge.txt /*doge#token#extract()* doge#token#replace() doge.txt /*doge#token#replace()* diff --git a/plugin/doge.vim b/plugin/doge.vim index c6977199..c13f93d5 100644 --- a/plugin/doge.vim +++ b/plugin/doge.vim @@ -68,15 +68,6 @@ if !exists('g:doge_mapping') let g:doge_mapping = 'd' endif -if !exists('g:doge_comment_jump_wrap') - "" - " (Default: 0) - " - " Cycle among placeholders when reaching last one (or first if jumping - " backward) - let g:doge_comment_jump_wrap = 0 -endif - if !exists('g:doge_mapping_comment_jump_forward') "" " (Default: '') @@ -103,6 +94,14 @@ if !exists('g:doge_comment_interactive') let g:doge_comment_interactive = 1 endif +if !exists('g:doge_comment_jump_wrap') + "" + " (Default: 1) + " + " Continue to cycle among placeholders when reaching the start or end. + let g:doge_comment_jump_wrap = 1 +endif + nnoremap (doge-generate) :call doge#generate() nnoremap (doge-comment-jump-forward) doge#comment#jump('forward') nnoremap (doge-comment-jump-backward) doge#comment#jump('backward') diff --git a/test/vimrc b/test/vimrc index 2659980a..cf29280c 100644 --- a/test/vimrc +++ b/test/vimrc @@ -11,6 +11,9 @@ endif " Since the key is not an easy way for Vader we'll use . let g:doge_mapping = '' +" Disable the continues comment cyling since this breaks existing tests. +let g:doge_comment_jump_wrap = 0 + " Disable interactive mode in tests, because it will break existing tests and we " want to test this manually. let g:doge_comment_interactive = 0