add-spell-rule(2)add-spell-rule - Add a new spelling rule to the dictionary
n add-spell-rule [ "rule-letter" "base-ending" "remove" "derive-ending" "sub-rules" ]
add-spell-rule adds a new spelling rule to the spelling checker. The rules effectively define the prefix and suffix character replacements of words, which is given a single character identifier, rule-letter, used in conjunction with the language dictionary. The letter conventions are defined by the Free Software Foundation GNU ispell(1) and more recently myspell(1) and hunspell(1) package.
add-spell-rule is used in the MicroEmacs language spelling initialization macro files named lsr<language>.emf, e.g. lsrenus.erf, lsrelgr.erf supplied in the MicroEmacs spelling or macros directory.
The command uses the numeric argument n to control the addition of a rule to the speller, as follows:-
0 add-spell-rule
-1 add-spell-rule "rule-letter" "base-ending" "remove" "derive-ending" "sub-rules"
-2 add-spell-rule "rule-letter" "base-ending" "remove" "derive-ending" "sub-rules"
"rule-letter" is any character in the range 0x21 to 0xff, all rules of the given letter must be a prefix rule and of the same type (i.e. same argument n). The start of a base word must match the given "base-ending" regular expression string for the rule to be applied; the "remove" must be a fixed string if not empty and must explicitly match the start of the base-ending and is removed from the start of the base word before the prefix "deriv-ending" is prefixed to the word. Example, for the American language;-
-2 add-spell-rule "R" "[^e]" "" "re" "" ; As in label > relabel -2 add-spell-rule "R" "e" "" "re-" "" ; As in enter > re-enter
The prefix rule of type 'R' can be applied to any base word which has rule 'R' enabled, and it prefixes "re" or "re-" to the word. The "sub-rules" argument can be used to list additional rules that can be applied to the base word if this rule has been applied, as MicroEmacs only supports a single prefix these rules must be suffixes and no other base word suffix can also be applied.
1 add-spell-rule "rule-letter" "base-ending" "remove" "deriv-ending" "sub-rules"
2 add-spell-rule "rule-letter" "base-ending" "remove" "deriv-ending" "sub-rules"
"rule-letter" is any character in the range 0x21 to 0xff, all rules of the given letter must be a suffix rule and of the same type (i.e. same argument n). The end of a base word must match the given "base-ending" regular expression string for the rule to be applied, the "remove" string must be a fixed string if not empty and the must exactly match the end of the "base-ending". The "remove" string is removed first from the end of the base word before the "deriv-ending", which must also be a fixed string, is appended. Example, for the American language;-
2 add-spell-rule "N" "e" "e" "ion" "" ; As in create > creation 2 add-spell-rule "N" "y" "y" "ication" "" ; As in multiply > multiplication 2 add-spell-rule "N" "[^ey]" "" "en" "" ; As in fall > fallen
The suffix rule of type 'N' can then be applied to any base word which has rule 'N' enabled, and it can be used with prefixes, e.g. with rule R above to derive "recreation" from "create". A rule which cannot be used with prefixes, i.e.:
1 add-spell-rule "V" "e" "e" "ive" "" ; As in create > creative 1 add-spell-rule "V" "[^e]" "" "ive" "" ; As in prevent > collectpreventive
While some prefix words are legal, such as "recreative" but some are not, such as "prevent" where "preventive" is correct but "repreventive" is not. The "sub-rules" argument can be used to list additional rules that can be applied to the base word if this rule has been applied, MicroEmacs supports the addition up-to two suffixes and a single prefix. Sub-rules can be used to simply rules and reduces the number of rules required, for examle:-
2 add-spell-rule "G" "" "" "ing" "S" ; As in list > listing 2 add-spell-rule "S" "" "" "s" "" ; As in pen > pens
Would automatically derive a "ings" suffix whenever a base word allows a "ing" suffix. This can also be used to reduce the number of erroneous derived words, for example:
-2 add-spell-rule "U" "" "" "un" "" ; As in bend > unbend 2 add-spell-rule "A" "" "" "able" "US" ; As in loan > loanable 2 add-spell-rule "S" "" "" "s" "" ; As in pen > pens
These rules allow a base word of "drink" with flags "AS" to derive the correct words "drinks", "drinkable", "drinkables" "undrinkable" and "undrinkables" but not the erroneous words "undrink" or "undrinks".
Following are special forms of add-spell-rule used for tuning the spell support, note that an argument can not be given:-
add-spell-rule "-" "<y|n>"
Enables and disables the acceptance of hyphens joining correct words. By default the phrase "out-of-date" would be accepted in American even though the phrase does not exist in the American dictionary. This is because the three words making up the phrase are correct and by default hyphens joining words are allowed. Some Latin language such as Spanish do not use this concept so this feature can be disable.
add-spell-rule "#" "score"
Sets the maximum allowed error score when creating a spelling guess list. When comparing a dictionary word with the user supplied word, spell checks for differences, each difference or error is scored in the range of 20 to 27 points, once the maximum allowed score has been exceeded the word is ignored. The default guess error score is 60, allowing for 2 errors.
add-spell-rule "*" "regex"
Adds a correct word in the form of a regex if a word being spell checked is completely matched by the regex the word is deemed to be correct. For example, the following rule can be used to make the spell-checker allow all hex numbers:
add-spell-rule "*" "0[xX][[:xdigit:]]+"
This will completely match the words "0x0", "0xff" etc but not "0x00z" as the whole word is not matched, only the first 4 letters.
The ispell-convert macro in spellutl.emf can be used to convert ispell(1), myspell(1) and hunspell(1) compliant affix (.aff) and dictionary (.dic) files to MicroEmacs. The format of the dictionary is a list of base words with each word having a list of rules which can be applied to that word. Therefore the list of words and the rules used for them are linked e.g.
aback abaft abandon/DGRS abandonment/S abase/DGRS abasement/S abash/DGS abashed/U abate/DGRS achieve/GS achieve/RSfDG
where the "/..." is the valid list of rules for that word.
MicroEmacs uses a proprietary binary format for dictionaries which allows for rapid initialisation, this format only supports a single copy of a base word so a single word requires multiple entries to define different rule combinations, such as for achieve above, it separates the rule groups with the 0x01 character which is not a valid rule.
MicroEmacs does not support the full set of hunspell features, some are unlikely to be required, such as COMPLEXPREFIXES as MicroEmacs does not support right-to-left languages such as Arabic. Other features such as support for compounds may be added at some point in the future, see spell.c for the current list of unsupported futures.
add-dictionary(2), spell(2) spell-buffer(3), spell-word(3), ispell(1).
(c) Copyright JASSPA 2025
Last Modified: 2024/05/08
Generated On: 2025/09/29