[PATCH] Allow removing words from the personal dictionary, that weren't previously added

Isaac Oscar Gariano isaacoscar at live.com.au
Tue Apr 26 07:27:10 UTC 2022


I've made the "Remove from personal dictionary" function/context menu item work for words that haven't been previously added, but instead are in the system-wide dictionary.
I've modified the behaviour so that it will cause the word to be marked as incorrectly spelt, regardless of whether it is in the user's personal dictionary, or the system-wide dictionary.
I've attached two patches, one that can be applied on the latest release branch 2.3.6.1​, and the other works on the master​ branch)

Previously, this only worked for words not in the system-wide dictionary, e.g.:

  1.  write "ello", it will be red squiggly underlined
  2.  right click and go "Add to personal dictionary"
  3.  now the underline will disappear
  4.  right click it and go "Remove from personal dictionary"
  5.  it will now be red underlined again

Now you can also do:

  1.  write "hello"
  2.  right click on it, and click "Remove from personal dictionary"
  3.  there should now be a red squiggly underline under "hello", i.e. it is no longer considered a word

(The above also works with the corresponding lyx-functions spelling-add​ and spelling-remove​)
It might be better to change the text of the context menu button, e.g., "Add to personal bad words list" or something, but then it'd need to be translated


The main use cases I have for this feature are:

  1.  removing rare words that are common misspellings, e.g., if you often write "whet" instead of "wet", you can mark the former as invalid.
  2.  ensure you consistently use the same variant of a word , e.g., make "spelled" an error if you prefer "spelt" (the latter being a word in the en_GB dictionary)

This change is backwards compatible: any words you had previously added to the personal dictionary will still be recognised.

I have fully tested this on Linux (specifically OpenSUSE Tumbleweed, with Aspell v0.60.8, Enchant v2.2.15, and, Hunspell 1.7.0), and Windows 11 (using the included Hunspell v1.6.2), I don't have a Mac so I can't test the AppleSpeller/Native backend.

How it works:


  *
Enchant already supports this feature out of the box, so I didn't need to change the backend at all, all I needed to do was to make the "Remove from personal dictionary" context menu button show up for all correctly spelt words (and not just those in the personal dictionary).
Specifically, enchant uses two files ~/.config./enchant/<lang>.dic​ and ~/.config/enchant/<lang>.exc​ to store the personal dictionary. The former contains all words that you have clicked "Add to personal dictionary", and the latter uses all that you have clicked "Remove from personal dictionary" for.
Note that words are added to .dic​ and .exc​ even if unnecessary (because the word is in the system-wide dictionary, or not in it, respectively).
The ".exc" file appears to take precedence over .dic​, so if a word is in both, it is considered misspelt.
  *   Aspell and Hunspell currently uses a file $LYX_USERDIR/pwl_<lang>.dict​ to store words you have clicked "Add to personal dictionary" for. LyX now also uses the $LYX_USERDIR/pwl_<lang>.excl​ file for words you have "Remove from personal dictionary". For consistency, my code treats these files like the enchant .dic​ and .exc​ files above, specifically the .excl​ file takes precedence of the .dict​ file, and words may be added to these files even if redundant/unnecessary.
The Hunspell backend already natively supports removing words from the dictionary at runtime, however Aspell does not, so after spell checking a word, my code manually checks for it's presence in the .excl​ list, which I have not optimised at all, and so it is an O(n) operation, where n is the number of words in the .excl​ file.
AppleSpeller/Native: this may work out of the box like Enchant, or not. I have no idea, as I can't test it and the documentation is unhelpful (e.g. https://developer.apple.com/documentation/appkit/nsspellchecker/1525147-unlearnword)

Note: I have deleted LEARNED_WORD​ from the SpellChecker::Result​ enum, as the code no longer distinguishes between words in the personal dictionary and the base dictionary. I also removed the ROOT_FOUND​, COMPOUND_WORD​, and IGNORED_WORD​ variants as they were never used.

For the master branch, I haven't modified the "Remove from document dictionary" option to also work with words not in said dictionary; I'd have to modify the LyX file format to support a \spellchecker_reject​ or something like, but I can probably work out how to do that if you're happy with the idea.

— Isaac Oscar Gariano​
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lyx.org/pipermail/lyx-devel/attachments/20220426/de82da39/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 2.3.6.1.patch
Type: application/octet-stream
Size: 13249 bytes
Desc: 2.3.6.1.patch
URL: <http://lists.lyx.org/pipermail/lyx-devel/attachments/20220426/de82da39/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: master.patch
Type: application/octet-stream
Size: 12835 bytes
Desc: master.patch
URL: <http://lists.lyx.org/pipermail/lyx-devel/attachments/20220426/de82da39/attachment-0003.obj>


More information about the lyx-devel mailing list