diff options
author | fischerling <florian.fischer@muhq.space> | 2023-04-20 12:15:22 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-20 12:15:22 +0200 |
commit | 3f450198c5c47a65d238ff3d0c17cf9ae7ce744f (patch) | |
tree | c827cd30443150452e79754f0523e6ecf51efe09 | |
parent | 61a62fdc6ad246b309cb9df615016fb1506cbf21 (diff) | |
parent | fe56553ae62a96344fe8b71bcd81b87afab0b1b6 (diff) | |
download | vis-spellcheck-3f450198c5c47a65d238ff3d0c17cf9ae7ce744f.tar.gz |
Merge pull request #10 from rnpnr/add-words
add keybind to add word to user dictionary
-rw-r--r-- | Readme.md | 1 | ||||
-rw-r--r-- | spellcheck.lua | 30 |
2 files changed, 30 insertions, 1 deletions
@@ -14,6 +14,7 @@ A spellchecking lua plugin for the [vis editor](https://github.com/martanne/vis) + To toggle highlighting press `<F7>` in normal mode. + To correct the word under the cursor press `<Ctrl+w>w` in normal mode. + To ignore the word under the cursor press `<Ctrl+w>i` in normal mode. ++ To add the word under the cursor to the user dictionary press '<Ctrl+w>a' in normal mode. ## Configuration diff --git a/spellcheck.lua b/spellcheck.lua index 45d519a..1272e32 100644 --- a/spellcheck.lua +++ b/spellcheck.lua @@ -396,7 +396,7 @@ vis:map(vis.modes.NORMAL, '<C-w>w', function() return 0 end, 'Correct misspelled word') -vis:map(vis.modes.NORMAL, '<C-w>i', function() +local ignore = function() local win = vis.win local file = win.file local pos = win.selection.pos @@ -425,9 +425,37 @@ vis:map(vis.modes.NORMAL, '<C-w>i', function() end win:draw() +end + +vis:map(vis.modes.NORMAL, '<C-w>i', function() + ignore() return 0 end, 'Ignore misspelled word') +vis:map(vis.modes.NORMAL, '<C-w>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())) + + 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) vis.win.file.spell_language = value vis:info('Spellchecking language is now ' .. value) |