From 8e9f64bc71be3317706dac62a6aade09ab223cb8 Mon Sep 17 00:00:00 2001 From: kamykn Date: Thu, 21 Nov 2019 02:03:53 +0900 Subject: [PATCH] Revert "Add buffer toggle function #21" --- autoload/spelunker.vim | 8 +- autoload/spelunker/matches.vim | 42 ++------- autoload/spelunker/test/test_match.vim | 34 +------ autoload/spelunker/test/test_toggle.vim | 114 +++--------------------- autoload/spelunker/toggle.vim | 68 ++------------ autoload/spelunker/words.vim | 2 +- plugin/spelunker.vim | 6 -- test/unit_test/match/clear_matches.txt | 3 - 8 files changed, 27 insertions(+), 250 deletions(-) delete mode 100644 test/unit_test/match/clear_matches.txt diff --git a/autoload/spelunker.vim b/autoload/spelunker.vim index 1e7c903..64bbadd 100644 --- a/autoload/spelunker.vim +++ b/autoload/spelunker.vim @@ -190,15 +190,9 @@ function! spelunker#toggle() return 1 endfunction -" bufferごとのspelunkerの機能のon/off -function! spelunker#toggle_buffer() - call spelunker#toggle#toggle_buffer() - return 1 -endfunction - " 実行可能な条件のチェック function s:is_runnable() - if spelunker#toggle#is_enabled() == 0 + if g:enable_spelunker_vim == 0 return 0 endif diff --git a/autoload/spelunker/matches.vim b/autoload/spelunker/matches.vim index 6937dad..f7c1560 100644 --- a/autoload/spelunker/matches.vim +++ b/autoload/spelunker/matches.vim @@ -57,29 +57,20 @@ function spelunker#matches#get_match_pattern(word) return l:pattern endfunction -function! spelunker#matches#delete_matches(word_list_for_delete, match_id_dict, window_id) +function! spelunker#matches#delete_matches(word_list_for_delete, match_id_dict) let l:match_id_dict = a:match_id_dict for l:word in a:word_list_for_delete let l:delete_match_id = get(l:match_id_dict, l:word, 0) if l:delete_match_id > 0 - let l:is_ok = 1 try - " recommend version is => 8.1.1739 - " https://github.com/vim/vim/issues/4720 - let l:is_ok = matchdelete(l:delete_match_id, a:window_id) - if l:is_ok == -1 && a:window_id == win_getid() - " 第2引数がある場合に上手く削除できない不具合があった時期があったため - let l:is_ok = matchdelete(l:delete_match_id) - endif + call matchdelete(l:delete_match_id) catch " エラー読み捨て finally - if l:is_ok == 0 - let l:del_index = index(values(l:match_id_dict), l:delete_match_id) - if l:del_index != 1 - call remove(l:match_id_dict, keys(l:match_id_dict)[l:del_index]) - endif + let l:del_index = index(values(l:match_id_dict), l:delete_match_id) + if l:del_index != 1 + call remove(l:match_id_dict, keys(l:match_id_dict)[l:del_index]) endif endtry endif @@ -88,28 +79,5 @@ function! spelunker#matches#delete_matches(word_list_for_delete, match_id_dict, return l:match_id_dict endfunction -function! spelunker#matches#clear_matches() - " matchからの削除処理を利用してハイライト削除 - if exists('b:match_id_dict') - for l:window_id in keys(b:match_id_dict) - let b:match_id_dict[l:window_id] = - \ spelunker#matches#delete_matches(keys(b:match_id_dict[l:window_id]), b:match_id_dict[l:window_id], l:window_id) - endfor - endif -endfunction - -function! spelunker#matches#clear_current_buffer_matches() - " matchからの削除処理を利用してハイライト削除 - if exists('b:match_id_dict') - let l:window_id = win_getid() - - if exists('b:match_id_dict[l:window_id]') - let b:match_id_dict[l:window_id] = - \ spelunker#matches#delete_matches(keys(b:match_id_dict[l:window_id]), b:match_id_dict[l:window_id], l:window_id) - endif - endif -endfunction - - let &cpo = s:save_cpo unlet s:save_cpo diff --git a/autoload/spelunker/test/test_match.vim b/autoload/spelunker/test/test_match.vim index 0af8752..a2818bc 100644 --- a/autoload/spelunker/test/test_match.vim +++ b/autoload/spelunker/test/test_match.vim @@ -12,9 +12,6 @@ function! spelunker#test#test_match#test() call s:test_get_match_pattern() let l:match_id_list = s:test_add_matches() call s:test_delete_matches(l:match_id_list) - - call s:test_clear_matches() - call s:test_clear_buffer_matches() endfunction function! s:test_get_match_pattern() @@ -59,42 +56,15 @@ function! s:test_add_matches() endfunction function! s:test_delete_matches(match_id_list) - let l:win_id = win_getid() call spelunker#test#open_unit_test_buffer('match', 'add_matches.txt') - let l:match_id_list_after_delete = spelunker#matches#delete_matches(a:match_id_list[0], a:match_id_list[1], l:win_id) + let l:match_id_list_after_delete = spelunker#matches#delete_matches(a:match_id_list[0], a:match_id_list[1]) " {'orange': 5, 'peach': 8, 'apple': 4, 'grape': 9} call assert_equal(['orange', 'peach', 'apple', 'grape'], keys(l:match_id_list_after_delete)) let l:all_ids = keys(l:match_id_list_after_delete) - let l:match_id_list_after_delete = spelunker#matches#delete_matches(l:all_ids, l:match_id_list_after_delete, l:win_id) + let l:match_id_list_after_delete = spelunker#matches#delete_matches(l:all_ids, l:match_id_list_after_delete) call assert_equal({}, l:match_id_list_after_delete) endfunction -function! s:test_clear_matches() - call spelunker#test#open_unit_test_buffer('match', 'clear_matches.txt') - - let l:win_id = win_getid() - let b:match_id_dict = {} - let [l:word_list_for_delete_match, b:match_id_dict[l:win_id]] - \ = spelunker#matches#add_matches(['appl', 'orangg', 'banna'], {}) - - call assert_notequal({}, b:match_id_dict[l:win_id]) - call spelunker#matches#clear_matches() - call assert_equal({l:win_id: {}}, b:match_id_dict) -endfunction - -function! s:test_clear_buffer_matches() - call spelunker#test#open_unit_test_buffer('match', 'clear_matches.txt') - - let l:win_id = win_getid() - let b:match_id_dict = {} - let [l:word_list_for_delete_match, b:match_id_dict[l:win_id]] - \ = spelunker#matches#add_matches(['appl', 'orangg', 'banna'], {}) - - call assert_notequal({}, b:match_id_dict[l:win_id]) - call spelunker#matches#clear_current_buffer_matches() - call assert_equal({l:win_id: {}}, b:match_id_dict) -endfunction - let &cpo = s:save_cpo unlet s:save_cpo diff --git a/autoload/spelunker/test/test_toggle.vim b/autoload/spelunker/test/test_toggle.vim index 377cf25..06c03bc 100644 --- a/autoload/spelunker/test/test_toggle.vim +++ b/autoload/spelunker/test/test_toggle.vim @@ -9,35 +9,23 @@ let s:save_cpo = &cpo set cpo&vim function! spelunker#test#test_toggle#test() - call s:test_toggle(1) " test global toggle - call s:test_toggle(2) " test local toggle - call s:test_is_enabled() - call s:test_is_enabled_global() - call s:test_is_enabled_buffer() - - call s:force_enable() + call s:test_toggle() endfunction -" toggle_mode -" 1: global mode -" 2: buffer mode -function! s:test_toggle(toggle_mode) - +function! s:test_toggle() " [case10-0] ===================================== call spelunker#test#open_unit_test_buffer('toggle', 'toggle1.txt') call spelunker#test#init() - - call s:force_enable() - call s:toggle(a:toggle_mode) + call spelunker#toggle#toggle() " highlightがなくなっていることを確認 - call s:toggle(a:toggle_mode) + call spelunker#toggle#toggle() let l:result = getmatches() call assert_equal(1, len(l:result)) call assert_equal('SpelunkerSpellBad', l:result[0]['group']) call assert_equal('\v[A-Za-z]@")) " [case11-1] ===================================== + call spelunker#toggle#toggle() + " spelunker#correct call spelunker#test#reload_buffer() call spelunker#test#init() - - call s:force_enable() - call cursor(1, 2) " call assert_equal(0, spelunker#correct()) " call assert_equal(0, spelunker#correct_all()) @@ -144,7 +126,6 @@ function! s:test_toggle(toggle_mode) call spelunker#test#reload_buffer() call spelunker#test#init() - call cursor(1, 2) call assert_equal(1, spelunker#correct_all_feeling_lucky()) call assert_equal('apple', expand("")) @@ -157,80 +138,5 @@ function! s:test_toggle(toggle_mode) call spelunker#test#reload_buffer() endfunction -" toggle_mode -" 1: global mode -" 2: buffer mode -function! s:toggle(toggle_mode) - if a:toggle_mode == 1 - silent! call spelunker#toggle#toggle() - elseif a:toggle_mode == 2 - silent! call spelunker#toggle#toggle_buffer() - endif -endfunction - -function! s:test_is_enabled() - call spelunker#test#open_unit_test_buffer('toggle', 'toggle1.txt') - call spelunker#test#init() - - call assert_equal(1, spelunker#toggle#is_enabled()) - - " disabled (global) - call spelunker#toggle#toggle() - call assert_equal(0, spelunker#toggle#is_enabled()) - - " enabled (global) - call spelunker#toggle#toggle() - call assert_equal(1, spelunker#toggle#is_enabled()) - - " disabled (global) - call spelunker#toggle#toggle_buffer() - call assert_equal(0, spelunker#toggle#is_enabled()) - - " enabled (global) - call spelunker#toggle#toggle_buffer() - call assert_equal(1, spelunker#toggle#is_enabled()) - - " enabled with global toggle - call spelunker#toggle#toggle() " disabled (global) - call spelunker#toggle#toggle_buffer() " disabled (buffer) - call spelunker#toggle#toggle() " disabled (global) - call assert_equal(1, spelunker#toggle#is_enabled()) -endfunction - -function! s:test_is_enabled_global() - call spelunker#test#open_unit_test_buffer('toggle', 'toggle1.txt') - call spelunker#test#init() - - call assert_equal(1, spelunker#toggle#is_enabled_global()) - - " disabled (global) - call spelunker#toggle#toggle() - call assert_equal(0, spelunker#toggle#is_enabled_global()) - - " enabled (global) - call spelunker#toggle#toggle() - call assert_equal(1, spelunker#toggle#is_enabled_global()) -endfunction - -function! s:test_is_enabled_buffer() - call spelunker#test#open_unit_test_buffer('toggle', 'toggle1.txt') - call spelunker#test#init() - - call assert_equal(1, spelunker#toggle#is_enabled_buffer()) - - " disabled (global) - call spelunker#toggle#toggle_buffer() - call assert_equal(0, spelunker#toggle#is_enabled_buffer()) - - " enabled (global) - call spelunker#toggle#toggle_buffer() - call assert_equal(1, spelunker#toggle#is_enabled_buffer()) -endfunction - -function! s:force_enable() - let g:enable_spelunker_vim = 1 - let b:enable_spelunker_vim = 1 -endfunction - let &cpo = s:save_cpo unlet s:save_cpo diff --git a/autoload/spelunker/toggle.vim b/autoload/spelunker/toggle.vim index 3b14225..b3985bb 100644 --- a/autoload/spelunker/toggle.vim +++ b/autoload/spelunker/toggle.vim @@ -11,43 +11,15 @@ set cpo&vim function! spelunker#toggle#toggle() let g:enable_spelunker_vim = g:enable_spelunker_vim == 1 ? 0 : 1 - " onにするときは今開いているbufferも連動させる - if g:enable_spelunker_vim == 1 - let b:enable_spelunker_vim = 1 - endif - - call spelunker#toggle#init_buffer(1, g:enable_spelunker_vim) - - if g:enable_spelunker_vim == 1 - echom 'Spelunker.vim is now enabled.' - else - echom 'Spelunker.vim has been disabled.' - endif -endfunction - -function! spelunker#toggle#toggle_buffer() - if !exists('b:enable_spelunker_vim') - let b:enable_spelunker_vim = 1 - endif - - let b:enable_spelunker_vim = b:enable_spelunker_vim == 1 ? 0 : 1 - call spelunker#toggle#init_buffer(2, b:enable_spelunker_vim) - - if b:enable_spelunker_vim == 1 - echom 'Spelunker.vim is now enabled in a buffer.' - else - echom 'Spelunker.vim has been disabled in a buffer.' - endif -endfunction - -function! spelunker#toggle#init_buffer(mode, is_enabled) - if a:is_enabled == 0 - if a:mode == 1 " for global - call spelunker#matches#clear_matches() - elseif a:mode == 2 " for buffer - call spelunker#matches#clear_current_buffer_matches() + if g:enable_spelunker_vim == 0 + " matchからの削除処理を利用してハイライト削除 + if exists('b:match_id_dict') + for l:window_id in keys(b:match_id_dict) + let b:match_id_dict[l:window_id] = + \ spelunker#matches#delete_matches(keys(b:match_id_dict[l:window_id]), b:match_id_dict[l:window_id]) + endfor endif - elseif a:is_enabled == 1 + else if g:spelunker_check_type == g:spelunker_check_type_buf_lead_write call spelunker#check() elseif g:spelunker_check_type == g:spelunker_check_type_cursor_hold @@ -56,29 +28,5 @@ function! spelunker#toggle#init_buffer(mode, is_enabled) endif endfunction -function! spelunker#toggle#is_enabled() - if spelunker#toggle#is_enabled_buffer() == 0 || spelunker#toggle#is_enabled_global() == 0 - return 0 - endif - - return 1 -endfunction - -function! spelunker#toggle#is_enabled_global() - if g:enable_spelunker_vim == 0 - return 0 - endif - return 1 -endfunction - - -function! spelunker#toggle#is_enabled_buffer() - if exists('b:enable_spelunker_vim') && b:enable_spelunker_vim == 0 - return 0 - endif - - return 1 -endfunction - let &cpo = s:save_cpo unlet s:save_cpo diff --git a/autoload/spelunker/words.vim b/autoload/spelunker/words.vim index ef7f355..2e486e1 100644 --- a/autoload/spelunker/words.vim +++ b/autoload/spelunker/words.vim @@ -206,7 +206,7 @@ function! spelunker#words#highlight(spell_bad_list) endif let b:match_id_dict[l:window_id] = - \ spelunker#matches#delete_matches(l:word_list_for_delete_match, b:match_id_dict[l:window_id], l:window_id) + \ spelunker#matches#delete_matches(l:word_list_for_delete_match, b:match_id_dict[l:window_id]) endfunction let &cpo = s:save_cpo diff --git a/plugin/spelunker.vim b/plugin/spelunker.vim index 44642b3..0c49398 100644 --- a/plugin/spelunker.vim +++ b/plugin/spelunker.vim @@ -242,12 +242,6 @@ if !hasmapto('(spelunker-toggle)') silent! nmap ZT (spelunker-toggle) endif -" [toggle in the buffer feature]=============================================================== -nnoremap (spelunker-toggle-buffer) :call spelunker#toggle_buffer() -if !hasmapto('(spelunker-toggle-buffer)') - silent! nmap Zt (spelunker-toggle-buffer) -endif - " [augroup] ================================================================== if g:spelunker_disable_auto_group == 0 augroup spelunker diff --git a/test/unit_test/match/clear_matches.txt b/test/unit_test/match/clear_matches.txt deleted file mode 100644 index 8b9580f..0000000 --- a/test/unit_test/match/clear_matches.txt +++ /dev/null @@ -1,3 +0,0 @@ -appl -orangg -banna