Spell suggestions (#399)

* feat: spell suggest picker

* set correct window title

* add entry to readme
This commit is contained in:
Senghan Bright
2021-01-06 14:57:14 +01:00
committed by GitHub
parent 402c2ea5fa
commit dda5b44b94
3 changed files with 25 additions and 0 deletions

View File

@@ -398,6 +398,7 @@ Built-in functions. Ready to be bound to any key you like. :smile:
| `builtin.vim_options` | Lists vim options and on enter edit the options value. | | `builtin.vim_options` | Lists vim options and on enter edit the options value. |
| `builtin.registers` | Lists vim registers and edit or paste selection. | | `builtin.registers` | Lists vim registers and edit or paste selection. |
| `builtin.autocommands` | Lists vim autocommands and go to their declaration. | | `builtin.autocommands` | Lists vim autocommands and go to their declaration. |
| `builtin.spell_suggest` | Lists spelling suggestions for <cword>.
| `builtin.keymaps` | Lists normal-mode mappings. | | `builtin.keymaps` | Lists normal-mode mappings. |
| `builtin.filetypes` | Lists all filetypes. | | `builtin.filetypes` | Lists all filetypes. |
| `builtin.highlights` | Lists all highlights. | | `builtin.highlights` | Lists all highlights. |

View File

@@ -54,6 +54,7 @@ builtin.keymaps = require('telescope.builtin.internal').keymaps
builtin.filetypes = require('telescope.builtin.internal').filetypes builtin.filetypes = require('telescope.builtin.internal').filetypes
builtin.highlights = require('telescope.builtin.internal').highlights builtin.highlights = require('telescope.builtin.internal').highlights
builtin.autocommands = require('telescope.builtin.internal').autocommands builtin.autocommands = require('telescope.builtin.internal').autocommands
builtin.spell_suggest = require('telescope.builtin.internal').spell_suggest
builtin.lsp_references = require('telescope.builtin.lsp').references builtin.lsp_references = require('telescope.builtin.lsp').references
builtin.lsp_document_symbols = require('telescope.builtin.lsp').document_symbols builtin.lsp_document_symbols = require('telescope.builtin.lsp').document_symbols

View File

@@ -771,6 +771,29 @@ internal.autocommands = function(opts)
}):find() }):find()
end end
internal.spell_suggest = function(opts)
if not vim.wo.spell then return false end
local cursor_word = vim.fn.expand("<cword>")
local suggestions = vim.fn.spellsuggest(cursor_word)
pickers.new(opts, {
prompt_title = 'Spelling Suggestions',
finder = finders.new_table {
results = suggestions,
},
sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr)
actions.goto_file_selection_edit:replace(function()
local selection = actions.get_selected_entry()
actions.close(prompt_bufnr)
vim.cmd('normal! "_ciw"' .. selection[1])
end)
return true
end
}):find()
end
local function apply_checks(mod) local function apply_checks(mod)
for k, v in pairs(mod) do for k, v in pairs(mod) do
mod[k] = function(opts) mod[k] = function(opts)