From ddbc1fd31bc5ac7b364cbb3724d447afe7070e43 Mon Sep 17 00:00:00 2001 From: Yuto Tokunaga Date: Thu, 13 Jun 2019 03:52:54 +0000 Subject: [PATCH 01/11] add feature to highlight characters to which the cursor can move directly --- autoload/clever_f.vim | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/autoload/clever_f.vim b/autoload/clever_f.vim index e078ee5..d63df5a 100644 --- a/autoload/clever_f.vim +++ b/autoload/clever_f.vim @@ -13,10 +13,12 @@ let g:clever_f_hide_cursor_on_cmdline = get(g:, 'clever_f_hide_cursor_on_cmdlin let g:clever_f_timeout_ms = get(g:, 'clever_f_timeout_ms', 0) let g:clever_f_mark_char = get(g:, 'clever_f_mark_char', 1) let g:clever_f_repeat_last_char_inputs = get(g:, 'clever_f_repeat_last_char_inputs', ["\"]) +let g:clever_f_mark_direct = get(g:, 'clever_f_mark_direct', 0) " below variables must be set before loading this script let g:clever_f_mark_cursor_color = get(g:, 'clever_f_mark_cursor_color', 'Cursor') let g:clever_f_mark_char_color = get(g:, 'clever_f_mark_char_color', 'CleverFDefaultLabel') +let g:clever_f_mark_direct_color = get(g:, 'clever_f_mark_direct_color', 'CleverFDefaultLabel') let g:clever_f_clean_labels_eagerly = get(g:, 'clever_f_clean_labels_eagerly', 1) " highlight labels @@ -32,6 +34,9 @@ endif if g:clever_f_mark_char execute 'highlight link CleverFChar' g:clever_f_mark_char_color endif +if g:clever_f_mark_direct + execute 'highlight link CleverFDirect' g:clever_f_mark_direct_color +endif if g:clever_f_clean_labels_eagerly augroup plugin-clever-f-permanent-finalizer @@ -96,6 +101,36 @@ function! s:is_timedout() abort return elapsed_ms > g:clever_f_timeout_ms endfunction +function! s:mark_direct(forward, count) abort + let line = getline('.') + let c_start = col('.') + let c_end = col('.')-2 + let l = line('.') + + if (a:forward && c_start+1 > len(line)-1) || + \(!a:forward && c_end + 1 < 0) + return + endif + + let r = a:forward ? range(c_start, len(line)-1) + \ : range(c_end, 0, -1) + let d = {} + let ms = [] + for c in r + let ch = line[c] + " TODO: migemo suport + " TODO: `g:clever_f_smart_case` and `g:clever_f_ignore_case` support + let d[ch] = get(d, ch, 0)+1 + if ch =~ '[\x01-\x7E]' && d[ch] == a:count + " NOTE: should not use `matchaddpos(group, [...position])`, + " because the maximum number of position is 8 + let m = matchaddpos('CleverFDirect', [[l, c+1]]) + call add(ms, m) + endif + endfor + return ms +endfunction + function! s:mark_char_in_current_line(map, char) abort let regex = '\%' . line('.') . 'l' . s:generate_pattern(a:map, a:char) call matchadd('CleverFChar', regex , 999) @@ -148,6 +183,10 @@ function! clever_f#find_with(map) abort endif endif try + if g:clever_f_mark_direct + let direct_markers = s:mark_direct(a:map =~# '\l', v:count1) + redraw + endif if g:clever_f_show_prompt | echon 'clever-f: ' | endif let s:previous_map[mode] = a:map let s:first_move[mode] = 1 @@ -186,6 +225,11 @@ function! clever_f#find_with(map) abort if g:clever_f_show_prompt | redraw! | endif finally if g:clever_f_mark_cursor | call matchdelete(cursor_marker) | endif + if g:clever_f_mark_direct + for m in direct_markers + call matchdelete(m) + endfor + endif if g:clever_f_hide_cursor_on_cmdline if s:ON_NVIM && mode ==# 'no' " Do not preserve previous value at operator-pending mode on Neovim (#44) From 4c5d61e71561113405a7c63075d25ab3f6817328 Mon Sep 17 00:00:00 2001 From: Yuto Tokunaga Date: Thu, 13 Jun 2019 06:21:46 +0000 Subject: [PATCH 02/11] support `g:clever_f_smart_case` and `g:clever_f_ignore_case` --- autoload/clever_f.vim | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/autoload/clever_f.vim b/autoload/clever_f.vim index d63df5a..2ab2ff8 100644 --- a/autoload/clever_f.vim +++ b/autoload/clever_f.vim @@ -112,16 +112,24 @@ function! s:mark_direct(forward, count) abort return endif + if g:clever_f_ignore_case + let line = tolower(line) + endif + let r = a:forward ? range(c_start, len(line)-1) \ : range(c_end, 0, -1) let d = {} let ms = [] for c in r let ch = line[c] + let ch_lower = tolower(ch) " TODO: migemo suport - " TODO: `g:clever_f_smart_case` and `g:clever_f_ignore_case` support + if ch !~ '^\a$' | continue | endif let d[ch] = get(d, ch, 0)+1 - if ch =~ '[\x01-\x7E]' && d[ch] == a:count + if g:clever_f_smart_case && ch =~# '\L' + let d[ch_lower] = get(d, ch_lower, 0)+1 + endif + if d[ch] == a:count || (g:clever_f_smart_case && d[ch_lower] == a:count) " NOTE: should not use `matchaddpos(group, [...position])`, " because the maximum number of position is 8 let m = matchaddpos('CleverFDirect', [[l, c+1]]) From 39d2336bb0e81ed8b0a376ebdce2891d0eca2d69 Mon Sep 17 00:00:00 2001 From: Yuto Tokunaga Date: Thu, 13 Jun 2019 07:57:08 +0000 Subject: [PATCH 03/11] add tests --- test/test.vimspec | 77 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/test/test.vimspec b/test/test.vimspec index 1570c88..e69406f 100644 --- a/test/test.vimspec +++ b/test/test.vimspec @@ -41,6 +41,8 @@ Describe default config Assert Equals(g:clever_f_mark_char_color, 'CleverFDefaultLabel') Assert Equals(g:clever_f_repeat_last_char_inputs, ["\"]) Assert Equals(g:clever_f_clean_labels_eagerly, 1) + Assert Equals(g:clever_f_mark_direct, 0) + Assert Equals(g:clever_f_mark_direct_color, 'CleverFDefaultLabel') End End @@ -1093,4 +1095,79 @@ Describe selection=exclusive End End +Describe g:clever_f_mark_direct + Before + new + let g:clever_f_mark_direct = 1 + call clever_f#reset() + highlight link CleverFDirect CleverFDefaultLabel + call AddLine('pOge huga Hiyo poyo') + let old_across_no_line = g:clever_f_across_no_line + let g:clever_f_across_no_line = 0 + End + + After + close! + let g:clever_f_mark_direct = 0 + let g:clever_f_across_no_line = old_across_no_line + End + + It should highlight target characters automatically + normal! gg0 + normal f + Assert Equals(len(filter(getmatches(), 'v:val.group==#"CleverFDirect"')), 11) + End + + It should remove target highlights + normal! gg0 + normal fh + Assert Equals(len(filter(getmatches(), 'v:val.group==#"CleverFDirect"')), 0) + End + + It should finish with no error + normal! gg$ + normal fp + Assert Equals(len(filter(getmatches(), 'v:val.group==#"CleverFDirect"')), 0) + End + + Describe + It should remove target highlights + normal! gg0 + execute 'normal' "f\" + Assert Equals(len(filter(getmatches(), 'v:val.group==#"CleverFDirect"')), 0) + End + End + + Describe g:clever_f_smart_case + Before + let g:clever_f_smart_case = 1 + End + + After + let g:clever_f_smart_case = 0 + End + + It should make less characters highlighted + normal! gg0 + normal f + Assert Equals(len(filter(getmatches(), 'v:val.group==#"CleverFDirect"')), 10) + End + End + + Describe g:clever_f_ignore_case + Before + let g:clever_f_ignore_case = 1 + End + + After + let g:clever_f_ignore_case = 0 + End + + It should make less characters highlighted + normal! gg0 + normal f + Assert Equals(len(filter(getmatches(), 'v:val.group==#"CleverFDirect"')), 9) + End + End +End " vim:foldmethod=marker From a01b6b93e7b68c1e61e2b40928c88111a69fc993 Mon Sep 17 00:00:00 2001 From: Yuto Tokunaga Date: Thu, 13 Jun 2019 07:58:30 +0000 Subject: [PATCH 04/11] fix `s:mark_direct` to pass test --- autoload/clever_f.vim | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/autoload/clever_f.vim b/autoload/clever_f.vim index 2ab2ff8..4bfb386 100644 --- a/autoload/clever_f.vim +++ b/autoload/clever_f.vim @@ -108,8 +108,8 @@ function! s:mark_direct(forward, count) abort let l = line('.') if (a:forward && c_start+1 > len(line)-1) || - \(!a:forward && c_end + 1 < 0) - return + \(!a:forward && c_end+1 < 0) + return [] endif if g:clever_f_ignore_case @@ -120,8 +120,8 @@ function! s:mark_direct(forward, count) abort \ : range(c_end, 0, -1) let d = {} let ms = [] - for c in r - let ch = line[c] + for i in r + let ch = line[i] let ch_lower = tolower(ch) " TODO: migemo suport if ch !~ '^\a$' | continue | endif @@ -132,7 +132,7 @@ function! s:mark_direct(forward, count) abort if d[ch] == a:count || (g:clever_f_smart_case && d[ch_lower] == a:count) " NOTE: should not use `matchaddpos(group, [...position])`, " because the maximum number of position is 8 - let m = matchaddpos('CleverFDirect', [[l, c+1]]) + let m = matchaddpos('CleverFDirect', [[l, i+1]]) call add(ms, m) endif endfor From 081b47674207c1b0bee9fce357a2eb17f510be46 Mon Sep 17 00:00:00 2001 From: Yuto Tokunaga Date: Thu, 13 Jun 2019 08:07:58 +0000 Subject: [PATCH 05/11] remove comment --- autoload/clever_f.vim | 1 - 1 file changed, 1 deletion(-) diff --git a/autoload/clever_f.vim b/autoload/clever_f.vim index 4bfb386..1fc86a3 100644 --- a/autoload/clever_f.vim +++ b/autoload/clever_f.vim @@ -123,7 +123,6 @@ function! s:mark_direct(forward, count) abort for i in r let ch = line[i] let ch_lower = tolower(ch) - " TODO: migemo suport if ch !~ '^\a$' | continue | endif let d[ch] = get(d, ch, 0)+1 if g:clever_f_smart_case && ch =~# '\L' From b0eea19cf3dd3c0193c98281c12f50f09211ee2c Mon Sep 17 00:00:00 2001 From: Yuto Tokunaga Date: Fri, 14 Jun 2019 05:20:03 +0000 Subject: [PATCH 06/11] simplify and improve readablility of `s:mark_direct()` --- autoload/clever_f.vim | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/autoload/clever_f.vim b/autoload/clever_f.vim index 1fc86a3..2caa6f6 100644 --- a/autoload/clever_f.vim +++ b/autoload/clever_f.vim @@ -101,14 +101,13 @@ function! s:is_timedout() abort return elapsed_ms > g:clever_f_timeout_ms endfunction +" highlight characters to which the cursor can be moved directly function! s:mark_direct(forward, count) abort let line = getline('.') - let c_start = col('.') - let c_end = col('.')-2 - let l = line('.') + let [_, l, c, _] = getpos('.') - if (a:forward && c_start+1 > len(line)-1) || - \(!a:forward && c_end+1 < 0) + if (a:forward && c == len(line)) || (!a:forward && c == 1) + " there is no matching characters return [] endif @@ -116,26 +115,30 @@ function! s:mark_direct(forward, count) abort let line = tolower(line) endif - let r = a:forward ? range(c_start, len(line)-1) - \ : range(c_end, 0, -1) - let d = {} - let ms = [] - for i in r + let [i_start, i_end, i_step] = a:forward ? [c, len(line) - 1, 1] + \ : [c - 2, 0, -1] + let char_count = {} + let matches = [] + for i in range(i_start, i_end, i_step) let ch = line[i] let ch_lower = tolower(ch) if ch !~ '^\a$' | continue | endif - let d[ch] = get(d, ch, 0)+1 + + let char_count[ch] = get(char_count, ch, 0) + 1 if g:clever_f_smart_case && ch =~# '\L' - let d[ch_lower] = get(d, ch_lower, 0)+1 + let char_count[ch_lower] = get(char_count, ch_lower, 0) + 1 endif - if d[ch] == a:count || (g:clever_f_smart_case && d[ch_lower] == a:count) + + if char_count[ch] == a:count || + \ (g:clever_f_smart_case && char_count[ch_lower] == a:count) " NOTE: should not use `matchaddpos(group, [...position])`, " because the maximum number of position is 8 - let m = matchaddpos('CleverFDirect', [[l, i+1]]) - call add(ms, m) + let m = matchaddpos('CleverFDirect', [[l, i + 1]]) + call add(matches, m) endif endfor - return ms + return matches +endfunction endfunction function! s:mark_char_in_current_line(map, char) abort From 080e3ee78a1ecc764672137dc8be2ab0442019f4 Mon Sep 17 00:00:00 2001 From: Yuto Tokunaga Date: Fri, 14 Jun 2019 05:28:22 +0000 Subject: [PATCH 07/11] add tests for `s:mark_direct()` introduce public function `clever_f#_mark_direct()` for test add test for multibyte string add comments to show highlighted characters add test for backward matching and one hop matching --- autoload/clever_f.vim | 4 ++ test/test.vimspec | 138 +++++++++++++++++++++++++++++++++--------- 2 files changed, 114 insertions(+), 28 deletions(-) diff --git a/autoload/clever_f.vim b/autoload/clever_f.vim index 2caa6f6..525d242 100644 --- a/autoload/clever_f.vim +++ b/autoload/clever_f.vim @@ -139,6 +139,10 @@ function! s:mark_direct(forward, count) abort endfor return matches endfunction + +" introduce public function for test +function! clever_f#_mark_direct(forward, count) abort + return s:mark_direct(a:forward, a:count) endfunction function! s:mark_char_in_current_line(map, char) abort diff --git a/test/test.vimspec b/test/test.vimspec index e69406f..ed4aea3 100644 --- a/test/test.vimspec +++ b/test/test.vimspec @@ -713,6 +713,23 @@ Describe normal Th Assert Equals(col('.'), 7) End + + Context with g:clever_f_mark_direct + Before + let g:clever_f_mark_direct = 1 + highlight link CleverFDirect CleverFDefaultLabel + End + + After + let g:clever_f_mark_direct = 0 + End + + It should remove target highlights + normal! gg0 + execute 'normal' "f\" + Assert Equals(len(filter(getmatches(), 'v:val.group==#"CleverFDirect"')), 0) + End + End End Describe g:clever_f_smart_case @@ -1095,13 +1112,13 @@ Describe selection=exclusive End End -Describe g:clever_f_mark_direct +Describe clever_f#_mark_direct() Before new - let g:clever_f_mark_direct = 1 call clever_f#reset() highlight link CleverFDirect CleverFDefaultLabel - call AddLine('pOge huga Hiyo poyo') + call AddLine('ビムかわいいよzビムx') + call AddLine('pOge huga Hiyo pOyo') let old_across_no_line = g:clever_f_across_no_line let g:clever_f_across_no_line = 0 End @@ -1112,33 +1129,37 @@ Describe g:clever_f_mark_direct let g:clever_f_across_no_line = old_across_no_line End - It should highlight target characters automatically + It should highlight characters to which the cursor can be moved directly normal! gg0 - normal f - Assert Equals(len(filter(getmatches(), 'v:val.group==#"CleverFDirect"')), 11) + " #: cursor position, _: highlighted char + " + " pOge huga Hiyo pOyo + " len(#______ _ ____ _ ) = 12 + Assert Equals(len(clever_f#_mark_direct(1, 1)), 12) End - It should remove target highlights - normal! gg0 - normal fh - Assert Equals(len(filter(getmatches(), 'v:val.group==#"CleverFDirect"')), 0) + It should highlight backward characters + normal! gg$ + " pOge huga Hiyo pOyo + " len( _ ____ __ _____#) = 12 + Assert Equals(len(clever_f#_mark_direct(0, 1)), 12) End - It should finish with no error - normal! gg$ - normal fp - Assert Equals(len(filter(getmatches(), 'v:val.group==#"CleverFDirect"')), 0) + It should highlight characters to which the cursor can be moved by one hop + normal! gg0 + " pOge huga Hiyo pOyo + " len(# _ _ ___) = 5 + Assert Equals(len(clever_f#_mark_direct(1, 2)), 5) End - Describe - It should remove target highlights - normal! gg0 - execute 'normal' "f\" - Assert Equals(len(filter(getmatches(), 'v:val.group==#"CleverFDirect"')), 0) - End + It should not highlight multibyte characters + normal! 2gg0 + " ビムかわいいよzビムx + " len(## _ _) = 2 + Assert Equals(len(clever_f#_mark_direct(1, 1)), 2) End - Describe g:clever_f_smart_case + Context with g:clever_f_smart_case Before let g:clever_f_smart_case = 1 End @@ -1147,14 +1168,29 @@ Describe g:clever_f_mark_direct let g:clever_f_smart_case = 0 End - It should make less characters highlighted + It should highlight characters to which the cursor can be moved directly normal! gg0 - normal f - Assert Equals(len(filter(getmatches(), 'v:val.group==#"CleverFDirect"')), 10) + " pOge huga Hiyo pOyo + " len(#______ _ ___ _ ) = 11 + Assert Equals(len(clever_f#_mark_direct(1, 1)), 11) + End + + It should highlight backward characters + normal! gg$ + " pOge huga Hiyo pOyo + " len( _ ___ __ ____#) = 10 + Assert Equals(len(clever_f#_mark_direct(0, 1)), 10) + End + + It should highlight characters to which the cursor can be moved by one hop + normal! gg0 + " pOge huga Hiyo pOyo + " len(# _ __ _ __ ) = 6 + Assert Equals(len(clever_f#_mark_direct(1, 2)), 6) End End - Describe g:clever_f_ignore_case + Context with g:clever_f_ignore_case Before let g:clever_f_ignore_case = 1 End @@ -1163,11 +1199,57 @@ Describe g:clever_f_mark_direct let g:clever_f_ignore_case = 0 End - It should make less characters highlighted + It should highlight characters to which the cursor can be moved directly normal! gg0 - normal f - Assert Equals(len(filter(getmatches(), 'v:val.group==#"CleverFDirect"')), 9) + " pOge huga Hiyo pOyo + " len(#______ _ __ _ ) = 10 + Assert Equals(len(clever_f#_mark_direct(1, 1)), 10) + End + + It should highlight backward characters + normal! gg$ + " pOge huga Hiyo pOyo + " len( _ ___ __ ____#) = 10 + Assert Equals(len(clever_f#_mark_direct(0, 1)), 10) + End + + It should highlight characters to which the cursor can be moved by one hop + normal! gg0 + " pOge huga Hiyo pOyo + " len(# _ __ _ _ ) = 5 + Assert Equals(len(clever_f#_mark_direct(1, 2)), 5) End End End + +Describe g:clever_f_mark_direct + Before + new + let g:clever_f_mark_direct = 1 + call clever_f#reset() + highlight link CleverFDirect CleverFDefaultLabel + call AddLine('ビムかわいいよzビムx') + call AddLine('pOge huga Hiyo poyo') + let old_across_no_line = g:clever_f_across_no_line + let g:clever_f_across_no_line = 0 + End + + After + close! + let g:clever_f_mark_direct = 0 + let g:clever_f_across_no_line = old_across_no_line + End + + It should remove target highlights + normal! gg0 + normal fh + Assert Equals(len(filter(getmatches(), 'v:val.group==#"CleverFDirect"')), 0) + End + + It should finish with no error + normal! gg$ + normal fp + Assert Equals(len(filter(getmatches(), 'v:val.group==#"CleverFDirect"')), 0) + End +End " vim:foldmethod=marker From 3adb0631e7a4665b984cb1ddb95bf9aaf937b73d Mon Sep 17 00:00:00 2001 From: Yuto Tokunaga Date: Fri, 14 Jun 2019 12:39:07 +0000 Subject: [PATCH 08/11] update tests to check columns of highlighted chars add helper function `GetHighlightedPositions()` --- test/test.vimspec | 91 ++++++++++++++++++++++++++++++----------------- 1 file changed, 58 insertions(+), 33 deletions(-) diff --git a/test/test.vimspec b/test/test.vimspec index ed4aea3..c19b2ed 100644 --- a/test/test.vimspec +++ b/test/test.vimspec @@ -1113,6 +1113,21 @@ Describe selection=exclusive End Describe clever_f#_mark_direct() + function! GetHighlightedPositions() + let cols = sort(map(getmatches(), {_, m -> m.pos1[1]}), 'n') + let chars = [] + for c in range(1, 19) + if len(cols) > 0 && cols[0] == c + let ch = '_' + call remove(cols, 0) + else + let ch = ' ' + endif + call add(chars, ch) + endfor + return join(chars, '') + endfunction + Before new call clever_f#reset() @@ -1133,30 +1148,35 @@ Describe clever_f#_mark_direct() normal! gg0 " #: cursor position, _: highlighted char " - " pOge huga Hiyo pOyo - " len(#______ _ ____ _ ) = 12 - Assert Equals(len(clever_f#_mark_direct(1, 1)), 12) + " #Oge huga Hiyo pOyo + let s = ' ______ _ ____ _ ' + call clever_f#_mark_direct(1, 1) + Assert Equals(GetHighlightedPositions(), s) End It should highlight backward characters normal! gg$ - " pOge huga Hiyo pOyo - " len( _ ____ __ _____#) = 12 - Assert Equals(len(clever_f#_mark_direct(0, 1)), 12) + " pOge huga Hiyo pOy# + let s = ' _ ____ __ _____ ' + call clever_f#_mark_direct(0, 1) + Assert Equals(GetHighlightedPositions(), s) End It should highlight characters to which the cursor can be moved by one hop normal! gg0 - " pOge huga Hiyo pOyo - " len(# _ _ ___) = 5 - Assert Equals(len(clever_f#_mark_direct(1, 2)), 5) + " #Oge huga Hiyo pOyo + let s = ' _ _ ___' + call clever_f#_mark_direct(1, 2) + Assert Equals(GetHighlightedPositions(), s) End It should not highlight multibyte characters normal! 2gg0 - " ビムかわいいよzビムx - " len(## _ _) = 2 - Assert Equals(len(clever_f#_mark_direct(1, 1)), 2) + " #ムかわいいよzビムx + " _ _ + call clever_f#_mark_direct(1, 1) + let cols = [22, 29] + Assert Equals(sort(map(getmatches(), {_, m -> m.pos1[1]}), 'n'), cols) End Context with g:clever_f_smart_case @@ -1170,23 +1190,26 @@ Describe clever_f#_mark_direct() It should highlight characters to which the cursor can be moved directly normal! gg0 - " pOge huga Hiyo pOyo - " len(#______ _ ___ _ ) = 11 - Assert Equals(len(clever_f#_mark_direct(1, 1)), 11) + " #Oge huga Hiyo pOyo + let s = ' ______ _ ___ _ ' + call clever_f#_mark_direct(1, 1) + Assert Equals(GetHighlightedPositions(), s) End It should highlight backward characters normal! gg$ - " pOge huga Hiyo pOyo - " len( _ ___ __ ____#) = 10 - Assert Equals(len(clever_f#_mark_direct(0, 1)), 10) + " pOge huga Hiyo pOy# + let s = ' _ ___ __ ____ ' + call clever_f#_mark_direct(0, 1) + Assert Equals(GetHighlightedPositions(), s) End It should highlight characters to which the cursor can be moved by one hop normal! gg0 - " pOge huga Hiyo pOyo - " len(# _ __ _ __ ) = 6 - Assert Equals(len(clever_f#_mark_direct(1, 2)), 6) + " #Oge huga Hiyo pOyo + let s = ' _ __ _ __ ' + call clever_f#_mark_direct(1, 2) + Assert Equals(GetHighlightedPositions(), s) End End @@ -1201,23 +1224,26 @@ Describe clever_f#_mark_direct() It should highlight characters to which the cursor can be moved directly normal! gg0 - " pOge huga Hiyo pOyo - " len(#______ _ __ _ ) = 10 - Assert Equals(len(clever_f#_mark_direct(1, 1)), 10) + " #Oge huga Hiyo pOyo + let s = ' ______ _ __ _ ' + call clever_f#_mark_direct(1, 1) + Assert Equals(GetHighlightedPositions(), s) End It should highlight backward characters normal! gg$ - " pOge huga Hiyo pOyo - " len( _ ___ __ ____#) = 10 - Assert Equals(len(clever_f#_mark_direct(0, 1)), 10) + " pOge huga Hiyo pOy# + let s = ' _ ___ __ ____ ' + call clever_f#_mark_direct(0, 1) + Assert Equals(GetHighlightedPositions(), s) End It should highlight characters to which the cursor can be moved by one hop normal! gg0 - " pOge huga Hiyo pOyo - " len(# _ __ _ _ ) = 5 - Assert Equals(len(clever_f#_mark_direct(1, 2)), 5) + " #Oge huga Hiyo pOyo + let s = ' _ __ _ _ ' + call clever_f#_mark_direct(1, 2) + Assert Equals(GetHighlightedPositions(), s) End End End @@ -1228,7 +1254,6 @@ Describe g:clever_f_mark_direct let g:clever_f_mark_direct = 1 call clever_f#reset() highlight link CleverFDirect CleverFDefaultLabel - call AddLine('ビムかわいいよzビムx') call AddLine('pOge huga Hiyo poyo') let old_across_no_line = g:clever_f_across_no_line let g:clever_f_across_no_line = 0 @@ -1243,13 +1268,13 @@ Describe g:clever_f_mark_direct It should remove target highlights normal! gg0 normal fh - Assert Equals(len(filter(getmatches(), 'v:val.group==#"CleverFDirect"')), 0) + Assert Equals(len(filter(getmatches(), {_, m -> m.group ==# 'CleverFDirect'})), 0) End It should finish with no error normal! gg$ normal fp - Assert Equals(len(filter(getmatches(), 'v:val.group==#"CleverFDirect"')), 0) + Assert Equals(len(filter(getmatches(), {_, m -> m.group ==# 'CleverFDirect'})), 0) End End " vim:foldmethod=marker From 5425dae3c32391a5aac9753407634287a4b847b4 Mon Sep 17 00:00:00 2001 From: Yuto Tokunaga Date: Fri, 14 Jun 2019 12:41:49 +0000 Subject: [PATCH 09/11] fix counting of chars --- autoload/clever_f.vim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/autoload/clever_f.vim b/autoload/clever_f.vim index 525d242..07d5860 100644 --- a/autoload/clever_f.vim +++ b/autoload/clever_f.vim @@ -121,11 +121,13 @@ function! s:mark_direct(forward, count) abort let matches = [] for i in range(i_start, i_end, i_step) let ch = line[i] + " only matches to ASCII + if ch !~ '^[\x00-\x7F]$' | continue | endif let ch_lower = tolower(ch) - if ch !~ '^\a$' | continue | endif let char_count[ch] = get(char_count, ch, 0) + 1 - if g:clever_f_smart_case && ch =~# '\L' + if g:clever_f_smart_case && ch =~# '\u' + " uppercase characters are doubly counted let char_count[ch_lower] = get(char_count, ch_lower, 0) + 1 endif From 8e43c242f0123350f3557e969a1a42551576adb4 Mon Sep 17 00:00:00 2001 From: Yuto Tokunaga Date: Fri, 14 Jun 2019 13:45:54 +0000 Subject: [PATCH 10/11] fix tests for vim < 8 remove lambdas --- test/test.vimspec | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test.vimspec b/test/test.vimspec index c19b2ed..42cb27f 100644 --- a/test/test.vimspec +++ b/test/test.vimspec @@ -1114,7 +1114,7 @@ End Describe clever_f#_mark_direct() function! GetHighlightedPositions() - let cols = sort(map(getmatches(), {_, m -> m.pos1[1]}), 'n') + let cols = sort(map(getmatches(), 'v:val.pos1[1]'), 'n') let chars = [] for c in range(1, 19) if len(cols) > 0 && cols[0] == c @@ -1176,7 +1176,7 @@ Describe clever_f#_mark_direct() " _ _ call clever_f#_mark_direct(1, 1) let cols = [22, 29] - Assert Equals(sort(map(getmatches(), {_, m -> m.pos1[1]}), 'n'), cols) + Assert Equals(sort(map(getmatches(), 'v:val.pos1[1]'), 'n'), cols) End Context with g:clever_f_smart_case @@ -1268,13 +1268,13 @@ Describe g:clever_f_mark_direct It should remove target highlights normal! gg0 normal fh - Assert Equals(len(filter(getmatches(), {_, m -> m.group ==# 'CleverFDirect'})), 0) + Assert Equals(len(filter(getmatches(), 'v:val.group ==# "CleverFDirect"')), 0) End It should finish with no error normal! gg$ normal fp - Assert Equals(len(filter(getmatches(), {_, m -> m.group ==# 'CleverFDirect'})), 0) + Assert Equals(len(filter(getmatches(), 'v:val.group ==# "CleverFDirect"')), 0) End End " vim:foldmethod=marker From e53d76bb5f93fa38910cafba7f68a5c0da2a3c43 Mon Sep 17 00:00:00 2001 From: Yuto Tokunaga Date: Tue, 25 Jun 2019 13:27:18 +0000 Subject: [PATCH 11/11] add document for variables add document for `g:clever_f_mark_direct` and `g:clever_f_mark_direct_color` --- doc/clever_f.txt | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/doc/clever_f.txt b/doc/clever_f.txt index 07d87f8..5d207cd 100644 --- a/doc/clever_f.txt +++ b/doc/clever_f.txt @@ -207,6 +207,27 @@ g:clever_f_repeat_last_char_inputs *g:clever_f_repeat_last_char_inputs* > let g:clever_f_repeat_last_char_inputs = ["\", "\"] < +g:clever_f_mark_direct *g:clever_f_mark_direct* + + If the value is equivalent to 1, characters to which the cursor can be + moved directly are highlighted until you input a character. Highlighting + is enabled in normal and visual mode. + The default value is 0. + +g:clever_f_mark_direct_color *g:clever_f_mark_direct_color* + + If |g:clever_f_mark_direct| is enabled, |clever-f| highlights characters + using the highlight group which |g:clever_f_mark_direct_color| specifies. + If you want to change the highlight group |clever-f| uses, set + your favorite highlight group to this variable. + The default value is "CleverFDefaultLabel", which makes characters red and + bold. If you want to make an original label highlight, define your own + highlight group.(See |:highlight|) + + Note: + |g:clever_f_mark_direct_color| must be set before |clever-f| is loaded. + (e.g. in your |vimrc|) + ============================================================================== SPECIAL THANKS *clever-f.vim-special-thanks*