mirror of
https://github.com/preservim/vim-wordy.git
synced 2025-11-12 11:53:48 -05:00
Add an 'off' position to the ring of wordy dictionaries #4
This commit is contained in:
@@ -24,43 +24,44 @@ function! wordy#init(...) abort
|
|||||||
" switch to usage dictionaries, building if needed
|
" switch to usage dictionaries, building if needed
|
||||||
let l:d = get(l:args, 'd', []) " may be string or list
|
let l:d = get(l:args, 'd', []) " may be string or list
|
||||||
let l:dicts = (type(l:d) == type([])) ? l:d : [l:d]
|
let l:dicts = (type(l:d) == type([])) ? l:d : [l:d]
|
||||||
if len(l:dicts)
|
let l:dst_paths = []
|
||||||
let l:dst_paths = []
|
" TODO &spelllang)
|
||||||
" TODO &spelllang)
|
let l:lang = get(l:args, 'lang', 'en')
|
||||||
let l:lang = get(l:args, 'lang', 'en')
|
" TODO &encoding)
|
||||||
" TODO &encoding)
|
let l:encoding = get(l:args, 'encoding', 'utf-8')
|
||||||
let l:encoding = get(l:args, 'encoding', 'utf-8')
|
for l:dict in l:dicts
|
||||||
for l:dict in l:dicts
|
let l:data_dir = g:wordy_dir . '/data'
|
||||||
let l:data_dir = g:wordy_dir . '/data'
|
let l:src_path = l:data_dir . '/' . l:lang . '/' . l:dict . '.dic'
|
||||||
let l:src_path = l:data_dir . '/' . l:lang . '/' . l:dict . '.dic'
|
if filereadable(l:src_path)
|
||||||
if filereadable(l:src_path)
|
let l:spell_dir = g:wordy_dir . '/spell'
|
||||||
let l:spell_dir = g:wordy_dir . '/spell'
|
if !isdirectory(l:spell_dir)
|
||||||
if !isdirectory(l:spell_dir)
|
call mkdir(expand(l:spell_dir), "p")
|
||||||
call mkdir(expand(l:spell_dir), "p")
|
|
||||||
endif
|
|
||||||
let l:dst_path = l:spell_dir . '/' . l:dict . '.' . l:lang . '.' . l:encoding . '.spl'
|
|
||||||
if get(l:args, 'force', 0) ||
|
|
||||||
\ !filereadable(l:dst_path) ||
|
|
||||||
\ getftime(l:dst_path) < getftime(l:src_path)
|
|
||||||
" attempt to (re)build the spell file
|
|
||||||
exe 'mkspell! ' . l:dst_path . ' ' . l:src_path
|
|
||||||
endif
|
|
||||||
if filereadable(l:dst_path)
|
|
||||||
call add(l:dst_paths, l:dst_path)
|
|
||||||
else
|
|
||||||
echohl WarningMsg | echo 'Unable to read target: ' . l:dst_path | echohl NONE
|
|
||||||
endif
|
|
||||||
else
|
|
||||||
echohl WarningMsg | echo 'Unable to read source: ' . l:src_path | echohl NONE
|
|
||||||
endif
|
endif
|
||||||
endfor
|
let l:dst_path = l:spell_dir . '/' . l:dict . '.' . l:lang . '.' . l:encoding . '.spl'
|
||||||
if len(l:dst_paths) > 0
|
if get(l:args, 'force', 0) ||
|
||||||
let b:original_spl = &spelllang
|
\ !filereadable(l:dst_path) ||
|
||||||
exe 'setlocal spelllang=' . l:lang . ',' . join(l:dst_paths, ',')
|
\ getftime(l:dst_path) < getftime(l:src_path)
|
||||||
setlocal spell
|
" attempt to (re)build the spell file
|
||||||
|
exe 'mkspell! ' . l:dst_path . ' ' . l:src_path
|
||||||
|
endif
|
||||||
|
if filereadable(l:dst_path)
|
||||||
|
call add(l:dst_paths, l:dst_path)
|
||||||
|
else
|
||||||
|
let l:msg = 'Unable to read target: ' . l:dst_path
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
let l:msg = 'Unable to read source: ' . l:src_path
|
||||||
endif
|
endif
|
||||||
echohl ModeMsg | echo 'wordy: ' . join(l:dicts, ', ') | echohl NONE
|
endfor
|
||||||
|
if len(l:dst_paths) > 0
|
||||||
|
let b:original_spl = &spelllang
|
||||||
|
exe 'setlocal spelllang=' . l:lang . ',' . join(l:dst_paths, ',')
|
||||||
|
setlocal spell
|
||||||
|
let l:msg = join(l:dicts, ', ')
|
||||||
|
else
|
||||||
|
let l:msg = 'off'
|
||||||
endif
|
endif
|
||||||
|
echohl ModeMsg | echo 'wordy: ' . l:msg | echohl NONE
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! wordy#jump(mode)
|
function! wordy#jump(mode)
|
||||||
@@ -68,16 +69,24 @@ function! wordy#jump(mode)
|
|||||||
" mode=-1 prev in ring
|
" mode=-1 prev in ring
|
||||||
let l:avail_count = len(g:wordy#ring)
|
let l:avail_count = len(g:wordy#ring)
|
||||||
if l:avail_count == 0 | return | endif
|
if l:avail_count == 0 | return | endif
|
||||||
if g:wordy_ring_index < 0
|
" if -1, ring navigation not initialized; start at begin or end
|
||||||
" ring navigation not initialized; start at begin or end
|
" Example with avail_count=3
|
||||||
let g:wordy_ring_index =
|
" ((-1 + 3 + 1 + 2) % 4) - 1 => 0
|
||||||
\ a:mode == 1
|
" (( 0 + 3 + 1 + 2) % 4) - 1 => 1
|
||||||
\ ? 0
|
" (( 1 + 3 + 1 + 2) % 4) - 1 => 2
|
||||||
\ : (l:avail_count - 1)
|
" (( 2 + 3 + 1 + 2) % 4) - 1 => -1 NoWordy
|
||||||
|
" ((-1 + 3 - 1 + 2) % 4) - 1 => 2
|
||||||
|
" (( 0 + 3 - 1 + 2) % 4) - 1 => -1 NoWordy
|
||||||
|
" (( 1 + 3 - 1 + 2) % 4) - 1 => 0
|
||||||
|
" (( 2 + 3 - 1 + 2) % 4) - 1 => 1
|
||||||
|
let g:wordy_ring_index =
|
||||||
|
\ ((g:wordy_ring_index + l:avail_count + a:mode + 2)
|
||||||
|
\ % (l:avail_count + 1)) - 1
|
||||||
|
if g:wordy_ring_index == -1
|
||||||
|
call wordy#init({}) " NoWordy
|
||||||
else
|
else
|
||||||
let g:wordy_ring_index = (g:wordy_ring_index + l:avail_count + a:mode) % l:avail_count
|
call wordy#init({ 'd': g:wordy#ring[ g:wordy_ring_index ]})
|
||||||
endif
|
endif
|
||||||
call wordy#init({ 'd': g:wordy#ring[ g:wordy_ring_index ]})
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" vim:ts=2:sw=2:sts=2
|
" vim:ts=2:sw=2:sts=2
|
||||||
|
|||||||
Reference in New Issue
Block a user