Next: Relationships Between Words, Previous: Learning from Buffers and Files, Up: Dictionary Learning
Predictive mode can automatically learn which words you use most often as you type, in order to make better predictions. This feature is especially useful when you first start using a dictionary, to adapt it to your writing style. Once a dictionary has been trained and is making good predictions, it can be turned off to fix the order in which completions are offered (see What is predictive completion?), though leaving it on usually doesn't cause the order to change that much.
The following variables control automatic learning:
t
, new words are automatically added to the active dictionary.
If set to a dictionary name, new words are automatically added to that
dictionary instead of the active one.
If predictive-dict-autosave is enabled and the buffer is
associated with a file, the buffer-local dictionary will automatically
be saved to the directory containing the file1. When you load the file in the future,
predictive mode will look for the buffer-local dictionary in the same
directory; there is no need to add the directory to your load path. If
the buffer is not associated with a file, the buffer-local dictionary
will be discarded when you end the Emacs session.
Note that if predictive-main-dict contains a list of dictionary
names (see Basic Dictionary Usage), an automatically learnt or
added word may not end up where you want it. The weight of a word is
incremented in the first dictionary it is found in, and words are added
to the first dictionary in the list (assuming
predictive-auto-add-to-dict is set to t
). It is best to
ensure that dictionaries in the list do not duplicate any words.
The predictive-auto-add-filter is not a customization option, so
it can only be set from Lisp code (e.g. a setup function, see Major Modes). One example of its use would be to filter out words that
contain non-letter characters (though it may be better to customize
completion-dynamic-syntax-alist and
completion-dynamic-override-syntax-alist instead,
see Syntax). The following will accomplish this:
(setq predictive-auto-add-filter (lambda (word dict) (string-match "^[[:alpha:]]$" word)))
Note that the function must accept both the word and dictionary arguments, even if it doesn't make use of the dictionary.
Another example would be to check that words are spelled correctly before auto-adding them to a dictionary, either using ispell or using the English dictionary that comes with predictive mode. This sounds tautological, but it does make sense: the dictionary you use for predictive completion will only contain words you've used at least once, but typos and spelling mistakes won't make it into the dictionary (see Getting the Most out of Dictionaries).
(setq predictive-auto-add-filter (lambda (word dict) (lookup-words word)))
Using the supplied predictive English dictionary will be faster than
ispell, since it is optimised for looking up words, though
this isn't such an issue if predictive-use-auto-learn-cache is
enabled (the following assumes dict-english
is already loaded,
see Loading and Saving Dictionaries).
(setq predictive-auto-add-filter (lambda (word) (dictree-member-p dict-english word)))
Other possible uses for predictive-auto-add-filter are limited only by your imagination!
[1] In fact, two dictionaries will be saved in the directory, since the buffer-local dictionary is composed of a meta-dictionary and a normal dictionary, see Creating Dictionaries.