Skip to content

orbitalquark/textadept-spellcheck

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spellcheck

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:

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.

Compiling

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

Key Bindings

Windows and Linux macOS Terminal Command
Tools
Ctrl+: ⌘: M-: Check spelling interactively
Ctrl+; ⌘; M-; Mark misspelled words

Fields defined by spellcheck

spellcheck.INDIC_SPELLING

The spelling error indicator number.

spellcheck.check_spelling_on_save

Check spelling after saving files. The default value is true.

spellcheck.hunspell_paths <table>

Paths to search for Hunspell dictionaries in.

Fields:

  • _USERHOME:
  • /usr/local/share/hunspell/:
  • /usr/share/hunspell/:
  • C:\\Program Files (x86)\\hunspell\\', :
  • _HOME:

spellcheck.misspelled_color_name

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.

spellcheck.spellcheckable_styles <table>

Table of spellcheckable style names. Text with either of these styles is eligible for spellchecking. The style name keys are assigned non-nil values. The default styles are default, comment, and string.

Fields:

  • default:
  • comment:
  • string:

spellcheck.spellchecker

The Hunspell spellchecker object.

Functions defined by spellcheck

_G.spell(aff, dic, key)

Returns a Hunspell spellchecker that utilizes affix file path aff and dictionary file path dic. This is a low-level function. You probably want to use the higher-level spellcheck.load().

Parameters:

  • aff: Path to the Hunspell affix file to use.
  • dic: Path to the Hunspell dictionary file to use.
  • key: Optional string key for encrypted dic.

Usage:

  • spellchecker = spell('/usr/share/hunspell/en_US.aff', '/usr/share/hunspell/en_US.dic')
  • spellchecker:spell('foo') --> false

Return:

  • spellchecker

spellcheck.check_spelling(interactive, wrapped)

Checks the buffer for spelling errors, marks misspelled words, and optionally shows suggestions for the next misspelled word if interactive is true.

Parameters:

  • interactive: Flag indicating whether or not to display suggestions for the next misspelled word. The default value is false.
  • wrapped: Utility flag indicating 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.

spellcheck.load(lang)

Loads string language lang into the spellchecker.

Parameters:

  • lang: The hunspell language to load.

Usage:

  • spellcheck.load('en_US')

spellchecker:add_dic(dic)

Adds words from dictionary file path dic to the spellchecker.

Parameters:

  • dic: Path to the Hunspell dictionary file to load.

spellchecker:add_word(word)

Adds string 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: The word to add.

spellchecker:get_dic_encoding()

Returns the dictionary's encoding.

Return:

  • string encoding

spellchecker:spell(word)

Returns true if string word is spelled correctly; false otherwise.

Parameters:

  • word: The word to check spelling of.

Return:

  • true or false

spellchecker:suggest(word)

Returns a list of spelling suggestions for string word. If word is spelled correctly, the returned list will be empty.

Parameters:

  • word: The word to get spelling suggestions for.

Return:

  • list of suggestions