Add optional spellchecking via libspelling - #442
Open
pvitt72 wants to merge 1 commit into
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds inline spellchecking backed by libspelling, with the dependency kept optional.
How it works
Spelling.TextBufferAdapterto itsGtkSource.Buffer, which does the inline highlighting on its own.Spelling.ProviderandSpelling.Checkerare 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-spell-checkcontext class, so what gets checked is decided entirely indata/resources/language-specs/. This PR extendsbibtex.langto mark entry types, field names, citation keys and identifier fields such as url/doi/isbn.Optional dependency
Document.init_spellchecker()catchesImportError/ValueErrorand leavesdocument.spellcheckerasNone, so Setzer runs unchanged when libspelling or the hunspell dictionaries are missing. Every caller — actions, context menu, preferences page — checks forNone.The README gets the extra packages needed to enable it (
gir1.2-spelling-1,libspelling-1-1and at least one hunspell dictionary).User interface
Settings.set_defaults():inline_spellcheckingandspellchecking_language_code(Nonemeaning the system default).Note on po/POTFILES
No change was needed: it already lists
setzer/document/spellchecker/*. Unrelated to this PR, that file is otherwise quite stale — runningpo/generate-potfiles.shon current master changes about 60 lines. I left it alone to keep this PR focused, but you may want to regenerate it separately.