Spell checking for Textadept.
Install this module by copying it into your ~/.textadept/modules/ directory or Textadept's modules/ directory, and then putting the following in your ~/.textadept/init.lua:
local spellcheck = require('spellcheck')
There will be a "Tools > Spelling" menu. Textadept automatically spell checks the buffer
each time it is saved, highlighting any misspelled words in plain text, comments, and
strings. These options can be configured via spellcheck.check_spelling_on_save
and
spellcheck.spellcheckable_styles
, respectively. Left-clicking (not right-clicking) on
misspelled words shows suggestions.
By default, Textadept attempts to load a preexisting Hunspell dictionary for the
detected locale. If none exists, or if the locale is not detected, Textadept falls back
on its own prepackaged US English dictionary. Textadept searches for dictionaries in
spellcheck.hunspell_paths
. User dictionaries are located in the ~/.textadept/dictionaries/
directory, and are loaded automatically.
Dictionary files are Hunspell dictionaries and follow the Hunspell format: the first line in a dictionary file contains the number of entries contained within, and each subsequent line contains a word.
Releases include binaries, so building this modules should not be necessary. If you want to build manually, use CMake. For example:
cmake -S . -B build_dir
cmake --build build_dir
cmake --install build_dir
Windows and Linux | macOS | Terminal | Command |
---|---|---|---|
Tools | |||
Ctrl+: | ⌘: | M-: | Check spelling interactively |
Ctrl+; | ⌘; | M-; | Mark misspelled words |
The spelling error indicator number.
Returns a Hunspell spellchecker.
This is a low-level function. You probably want to use the higher-level spellcheck.load()
.
Parameters:
- aff: String path to the Hunspell affix file to use.
- dic: String path to the Hunspell dictionary file to use.
- key: String key for encrypted dic.
Usage:
spellchecker = spell('/usr/share/hunspell/en_US.aff', '/usr/share/hunspell/en_US.dic')
spellchecker:spell('foo') --> false
Checks the buffer for any spelling errors and marks them.
Parameters:
- interactive: Display suggestions for the next misspelled word.
- wrapped: Utility flag that indicates whether or not the spellchecker has wrapped for displaying useful statusbar information. This flag is used and set internally, and should not be set otherwise.
Check spelling after saving files.
The default value is true
.
List of paths to search for Hunspell dictionaries in.
Loads a language into the spellchecker.
Parameters:
- lang: String Hunspell language name to load.
Usage:
spellcheck.load('en_US')
The name of the theme color used to mark misspelled words.
The default value is 'red'. If your theme does not define that color, set this field to your theme's equivalent.
Map of spellcheckable style names to true
.
Text with any of these styles is eligible for spellchecking.
The default styles are lexer.DEFAULT
, lexer.COMMENT
, and lexer.STRING
.
Usage:
spellcheck.spellcheckable_styles[lexer.HEADING] = true
The Hunspell spellchecker object.
Adds words from a dictionary file to the spellchecker.
Parameters:
- dic: String path to the Hunspell dictionary file to load.
Adds a word to the spellchecker.
Note: this is not a permanent addition. It only persists for the life of this spellchecker and applies only to this spellchecker.
Parameters:
- word: String word to add.
Returns the dictionary's string encoding.
Returns whether or not a word is spelled correctly.
Parameters:
- word: String word to check spelling of.
Returns a list of spelling suggestions for a word.
If that word is spelled correctly, the returned list will be empty.
Parameters:
- word: String word to get spelling suggestions for.