- •What is predictive completion?
- •Obtaining and Installing
- •Quick-Start
- •Completing Words
- •Basic Completion Commands
- •Inserting Completions
- •Deleting Characters
- •Dynamic Completion
- •Completion Hotkeys
- •Displaying a List of Candidates
- •Completion Menu and Browser
- •Miscellaneous Options
- •Advanced Customisation
- •Character Syntax and Key Bindings
- •Keymaps and Key Bindings
- •Syntax
- •Working with Major Modes
- •Dictionaries
- •Creating Dictionaries
- •Loading and Saving Dictionaries
- •Basic Dictionary Usage
- •Dictionaries Local to a Region of Text
- •Dictionary Learning
- •Automatic Learning
- •Relationships Between Words
- •Bugs and Future Improvements
- •Known Bugs
- •Future Improvements
- •Credits
Chapter 5: Advanced Customisation |
11 |
The predictive package itself contains setup functions for LaTEX (predictive-setup- latex), HTML (predictive-setup-html), and Fortran 90/95 (predictive-setup-f90)4. More contributions are always welcome! You must ensure that the dictionaries these setup functions require (which are also included in the package, see Chapter 2 [Obtaining and Installing], page 2) can be found in your load-path.
Since many settings are down to personal preference, the setup functions may not do precisely what you want, but if nothing else they provide examples to base your own on.
5.2 Dictionaries
Predictive completion is only as good as the dictionary it uses. The dictionary doesn’t only list the words themselves, it also ranks them according to how likely they are, so that predictive mode can o er the most likely completions first.
As you type, predictive mode can learn which words you use more frequently, so that the predictions improve. It can automatically ensure certain words are always ranked higher than others (useful when one word is a prefix for another).
It is not restricted to using one dictionary at a time; it can use many dictionaries in parallel, and can automatically switch dictionaries in regions of text defined by regular expressions.
And it attempts to do all of that faster than you type, so that your typing is not slowed down even when using very large dictionaries. (As soon as Emacs becomes sentient – surely not far o – it will probably go on strike!)
5.2.1 Creating Dictionaries
Predictive mode dictionaries store words along with their associated weights, used to rank the words in order of likelihood. The weight is just an integer value, which can be thought of as the relative frequency of a word (relative to the other words in the dictionary). A dictionary can also store prefix relationships between words, See Section 5.2.5.3 [Relationships Between Words], page 17.
The following commands are used to manually create and update dictionaries:
predictive-create-dict
Create a new dictionary. The dictionary name is read from the mini-bu er. You can optionally supply a filename to associate with the dictionary. The dictionary will be saved to this file by default (just as a bu er is saved to its associated file). You may also supply a file containing a list of words with which to populate the new dictionary. The predictive-completion-speed and predictive-dict-autosave variables set the new dictionary’s completion speed and autosave flag (see below).
predictive-create-meta-dict
Create a new meta-dictionary. A meta-dictionary is a wrapper around two or more dictionaries that behaves as if it was a single, combined dictionary. The weight of a word is the sum of it’s weights in the constituent dictionaries,
4An eclectic mix, which reflects the things I use emacs for most often, and perhaps also the fact that predictive completion mode is somewhat better suited to markup languages than programming languages.
Chapter 5: Advanced Customisation |
12 |
and the prefix relationships from all constituent dictionaries are merged (see Section 5.2.5.3 [Relationships Between Words], page 17). Apart from supplying a list of constituent dictionaries, the other options are identical to those for predictive-create-dict.
predictive-add-to-dict
Insert a word into a dictionary. The dictionary name and word are read from the mini-bu er (defaults to the word at the point). An optional prefix argument specifies the weight. If the word is not already in the dictionary, it will be added to it with that initial weight (or 0 if none is supplied). If the word is already in the dictionary, its weight will be incremented by the weight value (or by 1 if none is supplied).
dictree-size
Display the number of words in a dictionary.
Note that there is currently no predictive-remove-from-dict command to remove a word from a dictionary. See Section 6.1 [Known Bugs], page 18.
The file containing the list of words used to populate a dictionary has to conform to a specific format. Each line contains one word, delimited by ‘""’, optionally followed by an integer separated by whitespace from the word itself, which specifies the word’s weight. Any characters before the first ‘"’ are ignored. Note that the ‘words’ in a dictionary do not have to be words in the usual sense. They can be arbitrary sequences of characters, including whitespace and punctuation characters. The quote character ‘"’ can be included by escaping it: ‘\"’. However, see Section 6.1 [Known Bugs], page 18.
To ensure it is as e ciently structured as possible, it is best to create a dictionary from a list of words using predictive-create-dict, rather than create a blank dictionary and add the words using predictive-add-to-dict. For small dictionaries it won’t make much di erence, but for larger ones it can be significant.
It is often more useful for words that are prefixes for others to have higher weights, especially when using dynamic completion and the predictive-scoot-ahead command (see Section 4.2 [Dynamic Completion], page 5). The predictive-boost-prefix-weight command manipulates word weights to ensure that this is the case.
The following variables set defaults for other dictionary properties:
predictive-completion-speed
Sets the default completion speed of dictionaries created with predictive- create-dict. This is the desired upper limit on the time it takes to find completions; there is no guarantee it will be achieved! If it takes longer than this to find a particular completion, the results are cached so that they can be retrieved faster next time. Thus lower values result in faster completion, at the expense of dictionaries taking up more memory. Note that individual dictionaries can override this value, if a completion-speed is specified when they are created.
predictive-dict-autosave
Sets the default autosave property for dictionaries created with predictive- create-dict. If non-nil, modified dictionaries will automatically be saved when it is unloaded (either with the predictive-dict-unload command, or when
Chapter 5: Advanced Customisation |
13 |
exiting emacs). If nil, any unsaved modifications will be lost. See Section 5.2.2 [Loading and Saving Dictionaries], page 13.
5.2.2 Loading and Saving Dictionaries
dictree-load
Load a dictionary from file. The name given to the loaded dictionary is the same as the file name, with the extension removed. This will not add it to the list of dictionaries used by the current bu er (see predictive-load-dict, below).
predictive-load-dict
Load a dictionary, and add it to the list of dictionaries used by the current bu er. The dictionary file must be in your load-path. The dictionary will be included when learning from the bu er, see Section 5.2.5.1 [Learning from Bu ers and Files], page 15.
dictree-unload
Unload a dictionary. If the dictionary’s autosave flag is set, this will also save it (see Section 5.2.1 [Creating Dictionaries], page 11), unless overridden by supplying a prefix argument.
dictree-save
Save a dictionary to its associated file. Prompt for a file name if there is none associated with the dictionary.
dictree-write
Write a dictionary to a file specified via the mini-bu er. This also associates the dictionary with that file. If a prefix argument is supplied, you will not be asked to confirm if over-writing an existing file.
dictree-save-modified
Save all modified dictionaries. If a prefix argument is supplied, confirm each dictionary before saving.
predictive-dump-dict-to-buffer
Dumps all words and weights in the dictionary to a bu er, in the same format as that used to populate dictionaries (see Section 5.2.1 [Creating Dictionaries], page 11).
predictive-dump-dict-to-file
Dumps words and weights to a text file rather than a bu er. If a prefix argument is supplied, you will not be asked to confirm if over-writing an existing file.
To use a dictionary, it must be loaded into memory. If the dictionary is in your load path, this can be done manually using the load-library or predictive-load-dict commands. The predictive-load-dict command additionally it to the list of dictionaries used by the current bu er. Alternatively, you can manually load a dictionary from file using the dictree-load command (you should avoid loading a dictionary using the loadfile command, as it will not ensure the dictionary is associated with the file it was loaded from).
If you want a dictionary to be loaded every time you run Emacs, you can add the following line to your ‘.emacs’ file:
