Skip to content

Commit

Permalink
Merge pull request #25 from nedbat/master
Browse files Browse the repository at this point in the history
Add RecolorAllWords to apply the colors to a split
  • Loading branch information
Luis Vasconcellos committed Jan 8, 2017
2 parents 6de4e70 + cd3c3c5 commit 1bb3927
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions plugin/interestingwords.vim
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,24 @@ function! ColorWord(word, mode)
let s:interestingModes[n] = a:mode
let s:mids[a:word] = mid

call s:apply_color_to_word(n, a:word, a:mode, mid)

call s:markRecentlyUsed(n)

endfunction

function! s:apply_color_to_word(n, word, mode, mid)
let case = s:checkIgnoreCase(a:word) ? '\c' : '\C'
if a:mode == 'v'
let pat = case . '\V\zs' . escape(a:word, '\') . '\ze'
else
let pat = case . '\V\<' . escape(a:word, '\') . '\>'
endif

call matchadd("InterestingWord" . (n + 1), pat, 1, mid)

call s:markRecentlyUsed(n)

try
call matchadd("InterestingWord" . (a:n + 1), pat, 1, a:mid)
catch /E801/ " match id already taken.
endtry
endfunction

function! s:nearest_group_at_cursor() abort
Expand Down Expand Up @@ -153,6 +160,18 @@ function! UncolorAllWords()
endfor
endfunction

function! RecolorAllWords()
let i = 0
for word in s:interestingWords
if (type(word) == 1)
let mode = s:interestingModes[i]
let mid = s:mids[word]
call s:apply_color_to_word(i, word, mode, mid)
endif
let i += 1
endfor
endfunction

" returns true if the ignorecase flag needs to be used
function! s:checkIgnoreCase(word)
" return false if case sensitive is used
Expand Down

0 comments on commit 1bb3927

Please sign in to comment.