Skip to content

Commit

Permalink
feat: Document doge#helpers#count function
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoomen committed Jun 20, 2019
1 parent 9a4f2ec commit 1c0ffca
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
21 changes: 19 additions & 2 deletions autoload/doge/helpers.vim
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
let s:save_cpo = &cpoptions
set cpoptions&vim

""
" @public
" @function doge#helpers#count({word} [, {lnum_start}, {lnum_end} ])
" Returns the amount of occurences of a word.
"
" The 2nd and 3rd arguments, named lnum_start and lnum_end, can be used to
" limit the count in-between a range of lines. Both have to be supplied at the
" same time. When not specified the default value for the range will be '%',
" indicating a full buffer count.
" NOTE: When lnum_start is a bigger number than lnum_end then these values
" will be flipped to ensure a correct range format.
function! doge#helpers#count(word, ...) abort
let l:cursor_pos = getpos('.')
let l:range = '%'
if (type(a:1) == v:t_number && type(a:2) == v:t_number) && (a:1 < a:2)
let l:range = printf('%s,%s', a:1, a:2)
if (type(a:1) == v:t_number && type(a:2) == v:t_number)
if a:1 < a:2
let l:range = printf('%s,%s', a:1, a:2)
else
" When a:1 is a bigger number than a:2 then these values will be flipped
" to ensure a correct range format.
let l:range = printf('%s,%s', a:2, a:1)
endif
endif
try
let l:cnt = execute(l:range . 's/' . a:word . '//gn')
Expand Down
11 changes: 11 additions & 0 deletions doc/doge.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ doge#comment#update_interactive_comment_info()
doge#generate#pattern({pattern}) *doge#generate#pattern()*
Generates a comment based on a given pattern.

doge#helpers#count({word} [, {lnum_start}, {lnum_end} ])
*doge#helpers#count()*
Returns the amount of occurences of a word.

The 2nd and 3rd arguments, named lnum_start and lnum_end, can be used to
limit the count in-between a range of lines. Both have to be supplied at the
same time. When not specified the default value for the range will be '%',
indicating a full buffer count. NOTE: When lnum_start is a bigger number
than lnum_end then these values will be flipped to ensure a correct range
format.

doge#indent#add({lnum}, {text}) *doge#indent#add()*
Indent a string based on a given line its indent.

Expand Down
1 change: 1 addition & 0 deletions doc/tags
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ doge#comment#jump_forward() doge.txt /*doge#comment#jump_forward()*
doge#comment#update_interactive_comment_info() doge.txt /*doge#comment#update_interactive_comment_info()*
doge#generate#pattern() doge.txt /*doge#generate#pattern()*
doge#generate() doge.txt /*doge#generate()*
doge#helpers#count() doge.txt /*doge#helpers#count()*
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

0 comments on commit 1c0ffca

Please sign in to comment.