Skip to content

Add optional spellchecking via libspelling - #442

Open
pvitt72 wants to merge 1 commit into
cvfosammmm:masterfrom
pvitt72:spellchecking
Open

Add optional spellchecking via libspelling#442
pvitt72 wants to merge 1 commit into
cvfosammmm:masterfrom
pvitt72:spellchecking

Conversation

@pvitt72

@pvitt72 pvitt72 commented Aug 3, 2026

Copy link
Copy Markdown

Adds inline spellchecking backed by libspelling, with the dependency kept optional.

How it works

  • Each document attaches a Spelling.TextBufferAdapter to its GtkSource.Buffer, which does the inline highlighting on its own.
  • The Spelling.Provider and Spelling.Checker are module level singletons shared by every document, so adding or ignoring a word applies everywhere. invalidate_all_documents() then re-checks the open buffers.
  • No LaTeX or BibTeX syntax is filtered in Python. libspelling skips whatever carries the GtkSourceView no-spell-check context class, so what gets checked is decided entirely in data/resources/language-specs/. This PR extends bibtex.lang to mark entry types, field names, citation keys and identifier fields such as url/doi/isbn.

Optional dependency

Document.init_spellchecker() catches ImportError/ValueError and leaves document.spellchecker as None, so Setzer runs unchanged when libspelling or the hunspell dictionaries are missing. Every caller — actions, context menu, preferences page — checks for None.

The README gets the extra packages needed to enable it (gir1.2-spelling-1, libspelling-1-1 and at least one hunspell dictionary).

User interface

  • Preferences → Editor gains a Spellchecking section with an on/off toggle and a language chooser, backed by two new preferences in Settings.set_defaults(): inline_spellchecking and spellchecking_language_code (None meaning the system default).
  • The right-click menu offers the suggestions plus Add to Dictionary and Ignore. The target word is taken from the pointer position rather than from the cursor, because right-clicking does not move the cursor in Setzer.

Note on po/POTFILES

No change was needed: it already lists setzer/document/spellchecker/*. Unrelated to this PR, that file is otherwise quite stale — running po/generate-potfiles.sh on current master changes about 60 lines. I left it alone to keep this PR focused, but you may want to regenerate it separately.

Each document attaches a Spelling.TextBufferAdapter to its buffer; the
provider and checker are module level singletons, so adding or ignoring
a word applies to every open document.

The dependency is optional: init_spellchecker() returns None when
libspelling or the dictionaries are missing, and every caller checks
for it.

Which text gets checked is decided in the language specs, not in
Python: latex.lang and bibtex.lang mark commands, math, urls, entry
types and identifier fields with the no-spell-check context class.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant