From 775fe52abb7575590a3a172e884e52566d4f6023 Mon Sep 17 00:00:00 2001 From: Randy Palamar Date: Wed, 19 Apr 2023 22:39:52 -0600 Subject: add keybind to add word to user dictionary --- Readme.md | 1 + spellcheck.lua | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/Readme.md b/Readme.md index 48d5f15..f0c2865 100644 --- a/Readme.md +++ b/Readme.md @@ -14,6 +14,7 @@ A spellchecking lua plugin for the [vis editor](https://github.com/martanne/vis) + To toggle highlighting press `` in normal mode. + To correct the word under the cursor press `w` in normal mode. + To ignore the word under the cursor press `i` in normal mode. ++ To add the word under the cursor to the user dictionary press 'a' in normal mode. ## Configuration diff --git a/spellcheck.lua b/spellcheck.lua index 1d0d6c7..ba87550 100644 --- a/spellcheck.lua +++ b/spellcheck.lua @@ -428,6 +428,23 @@ vis:map(vis.modes.NORMAL, 'i', function() return 0 end, 'Ignore misspelled word') +vis:map(vis.modes.NORMAL, 'a', function() + local file = vis.win.file + local pos = vis.win.selection.pos + if not pos then + return + end + + local range = file:text_object_word(pos); + if not range or range.start == range.finish then + return + end + + local cmd = string.format(':!echo "*%s\\n#" | %s', file:content(range), + spellcheck.cmd:format(spellcheck.get_lang())) + return vis:command(cmd) +end, 'Add word to user dictionary') + vis:option_register('spelllang', 'string', function(value) vis.win.file.spell_language = value vis:info('Spellchecking language is now ' .. value) -- cgit From fe56553ae62a96344fe8b71bcd81b87afab0b1b6 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Thu, 20 Apr 2023 12:14:27 +0200 Subject: ignore newly added word to prevent it from being highlighted --- spellcheck.lua | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/spellcheck.lua b/spellcheck.lua index ba87550..38d72b1 100644 --- a/spellcheck.lua +++ b/spellcheck.lua @@ -396,7 +396,7 @@ vis:map(vis.modes.NORMAL, 'w', function() return 0 end, 'Correct misspelled word') -vis:map(vis.modes.NORMAL, 'i', function() +local ignore = function() local win = vis.win local file = win.file local pos = win.selection.pos @@ -425,6 +425,10 @@ vis:map(vis.modes.NORMAL, 'i', function() end win:draw() +end + +vis:map(vis.modes.NORMAL, 'i', function() + ignore() return 0 end, 'Ignore misspelled word') @@ -442,7 +446,14 @@ vis:map(vis.modes.NORMAL, 'a', function() local cmd = string.format(':!echo "*%s\\n#" | %s', file:content(range), spellcheck.cmd:format(spellcheck.get_lang())) - return vis:command(cmd) + + if not vis:command(cmd) then + vis:info('executing vis command: "' .. cmd .. '" failed') + end + + -- ignore the added word to prevent it from being highlighted in this session + ignore() + return 0 end, 'Add word to user dictionary') vis:option_register('spelllang', 'string', function(value) -- cgit