Skip to content

Commit

Permalink
feat: Add support for interactive comments insert below
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoomen committed Jun 20, 2019
1 parent d37dcc6 commit 94b3f59
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
9 changes: 9 additions & 0 deletions autoload/doge/comment.vim
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ function! doge#comment#update_interactive_comment_info() abort
while trim(getline(l:lnum_comment_end_pos)) =~# printf('\m^%s', l:comment_last_line)
let l:lnum_comment_end_pos += 1
endwhile

" If we're still at the same line we're probably dealing with python
" comments (or something equivalent) where it only has an opener and
" closer and each comment line does not start with a comment leader, so
" just search for the last line of the comment
if l:lnum_comment_end_pos == line('.')
let l:lnum_comment_end_pos = search(l:comment_last_line, 'nW')
endif

let b:doge_interactive['lnum_comment_end_pos'] = l:lnum_comment_end_pos - 1
endif
endif
Expand Down
38 changes: 19 additions & 19 deletions autoload/doge/generate.vim
Original file line number Diff line number Diff line change
Expand Up @@ -103,29 +103,29 @@ function! doge#generate#pattern(pattern) abort
" Write the comment.
call append(l:comment_lnum_insert_position, l:comment)

" Enable interactive mode.
if g:doge_comment_interactive == v:true
if a:pattern['comment']['insert'] ==# 'below'
" TODO: implement python
let l:todo_match = search('TODO', 'nW', l:comment_lnum_insert_position + len(l:comment))
else
let l:todo_match = search('TODO', 'bnW', l:comment_lnum_insert_position + 1)

if l:todo_match != 0
let l:todo_count = doge#helpers#count(
\ 'TODO',
\ (l:comment_lnum_insert_position + 1),
\ (l:comment_lnum_insert_position + 1 + len(l:comment))
\ )
if l:todo_count > 0
let b:doge_interactive = {
\ 'comment': l:comment,
\ 'lnum_comment_start_pos': (l:comment_lnum_insert_position + 1),
\ 'lnum_comment_end_pos': (l:comment_lnum_insert_position + len(l:comment)),
\ }
" Go to the top of the comment and select the first TODO.
exe l:comment_lnum_insert_position + 1
call search('TODO', 'W')
execute("normal! viwo\<C-g>")
endif
endif
if l:todo_match != 0
let l:todo_count = doge#helpers#count(
\ 'TODO',
\ (l:comment_lnum_insert_position + 1),
\ (l:comment_lnum_insert_position + 1 + len(l:comment))
\ )
if l:todo_count > 0
let b:doge_interactive = {
\ 'comment': l:comment,
\ 'lnum_comment_start_pos': (l:comment_lnum_insert_position + 1),
\ 'lnum_comment_end_pos': (l:comment_lnum_insert_position + len(l:comment)),
\ }
" Go to the top of the comment and select the first TODO.
exe l:comment_lnum_insert_position + 1
call search('TODO', 'W')
execute("normal! viwo\<C-g>")
endif
endif
endif
Expand Down

0 comments on commit 94b3f59

Please sign in to comment.