Commit 3daeabbb authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Add more Vim spell file management functionality

parent 2c325623
Loading
Loading
Loading
Loading
+29 −3
Original line number Diff line number Diff line
@@ -8,14 +8,16 @@ let s:spellfiles += glob("~/.vim/spell/*.add", v:false, v:true)
let s:spellfiles += glob("~/.vim/spell/ft/*.add", v:false, v:true)
let &spellfile = join(s:spellfiles, ",")

function s:manage_spell_word(action, spellfile, word)
function s:manage_spell_word(action, spellfile, words)
	let s:spellfiles = uniq(sort(
		\ s:spellfiles +
		\ split(&spellfile, ',') +
		\ [a:spellfile]
		\ ))
	let &spellfile = a:spellfile
	execute a:action." ".expand(a:word)
	for word in a:words
		execute a:action." ".expand(word)
	endfor
	let &spellfile = join(s:spellfiles, ",")
endfunction

@@ -25,7 +27,26 @@ function s:manage_ft_word(action, word)
		return
	endif
	let spellfile = expand("~/.vim/spell/ft/".&filetype.".utf8.add")
	call s:manage_spell_word(a:action, spellfile, a:word)
	call s:manage_spell_word(a:action, spellfile, [a:word])
endfunction

function s:manage_classified_word(action, class, ...)
	let spellfile = expand("~/.vim/spell/".a:class.".utf8.add")
	let words = a:000
	if len(words) == 0
		let words = ["<cword>"]
	endif
	call s:manage_spell_word(a:action, spellfile, words)
endfunction

function s:complete(cur, cmd, pos)
	echom a:cmd[:a:pos]
	if a:cmd[:a:pos] =~ " [^ ]+ "
		" Not on the first argument, no suggestions
		return []
	endif
	return map(glob("~/.vim/spell/*.utf8.add", 0, 1),
				\ {key, val -> fnamemodify(val, ":t:r:r")})
endfunction


@@ -36,3 +57,8 @@ command -nargs=1 SpellFtUndo :call s:manage_ft_word("spellundo", <args>)
nnoremap <silent> zLg :SpellFtGood  "<cword>"<CR>
nnoremap <silent> zLw :SpellFtWrong "<cword>"<CR>
nnoremap <silent> zLu :SpellFtUndo  "<cword>"<CR>


command -nargs=+ -complete=customlist,s:complete SpellGood  :call s:manage_classified_word("spellgood", <f-args>)
command -nargs=+ -complete=customlist,s:complete SpellWrong :call s:manage_classified_word("spellgood", <f-args>)
command -nargs=+ -complete=customlist,s:complete SpellUndo  :call s:manage_classified_word("spellgood", <f-args>)