Skip to content

Commit

Permalink
feat: Enable continues cycling with surrounding TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoomen committed Sep 11, 2019
1 parent d78e4f4 commit 1321811
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 17 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ on a function, press `<Leader>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)
Expand Down Expand Up @@ -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`
Expand Down
26 changes: 24 additions & 2 deletions autoload/doge/comment.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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 "\<Esc>:" . b:doge_interactive['lnum_comment_start_pos'] . "\<CR>/" . s:comment_placeholder . "\<CR>:silent! noh\<CR>gno\<C-g>"
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'
Expand All @@ -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 "\<Esc>:" . b:doge_interactive['lnum_comment_end_pos'] . "\<CR>?" . s:comment_placeholder . "\<CR>:silent! noh\<CR>gno\<C-g>"
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'
Expand Down
11 changes: 5 additions & 6 deletions doc/doge.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<Tab>')

Expand All @@ -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*

Expand Down
1 change: 1 addition & 0 deletions doc/tags
Original file line number Diff line number Diff line change
Expand Up @@ -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()*
Expand Down
17 changes: 8 additions & 9 deletions plugin/doge.vim
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,6 @@ if !exists('g:doge_mapping')
let g:doge_mapping = '<Leader>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: '<Tab>')
Expand All @@ -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 <Plug>(doge-generate) :call doge#generate()<CR>
nnoremap <expr> <Plug>(doge-comment-jump-forward) doge#comment#jump('forward')
nnoremap <expr> <Plug>(doge-comment-jump-backward) doge#comment#jump('backward')
Expand Down
3 changes: 3 additions & 0 deletions test/vimrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ endif
" Since the <Leader> key is not an easy way for Vader we'll use <C-d>.
let g:doge_mapping = '<C-d>'

" 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
Expand Down

0 comments on commit 1321811

Please sign in to comment.