Predictive is a package for the GNU Emacs Editor that helps you write text faster. It does this by trying to predict what you are going to write by looking at the first few characters of each word you type, looking into a dictionary for matching words, and suggesting words from this dictionary.
(For are much more complete description check out the manual.)
For example, when typing "t" it suggests "the" on my system (with my dictionary, trained using my writing style). Typing an end-of-word-character (such as a space or a punctuation character) will accept the suggested word and insert it into the text.
If "the" was not the word you wanted, there is a list of the ten most frequently used words in a list at the bottom of the window, each word prefixed with a number. Typing this number will insert that particular completion instead.
Some screenshots are always nice.
Starting up predictive (see below for the definition of this command):
Predictive in action:
Everyone that needs to type large amounts of text should be able to benefit greatly by using predictive. Even if you normally don't use Emacs, you might want to use it just to be able to type more quickly (this will also be nicer on your hands, in the long run.)
To do its magic, predictive uses a dictionary. The dictionary is basically a list of words and a number telling how frequent that word is compared to the other words in the list.
The dictionary can be filled with words in a couple of different ways: using old texts that you have written, adding words manually (by calling the command `predictive-add-to-dict') or by learning and adding words as you type. In this tutorial I will demonstrate the latter because that is what I needed when I first started trying out predictive.
First you need to download predictive:
http://www.dr-qubit.org/download.php?file=predictive/predictive.tar.gz
Unpack it somewhere:
mydir $ tar xzvf predictive.tar.gz
Start Emacs and add the directory where you unpacked predictive to your `load-path'. Put the following in your .emacs:
(setq load-path (cons "mydir/predictive" load-path)) (autoload 'predictive-mode "predictive" "predictive" t)
Next, you should byte-compile the source files. I think it is easiest to do this using Dired:
C-x d mydir/predictive RET ;; Open the predictive directory in Dired.
% m \.el$ RET ;; Marks all .el files.
B ;; Byte compiles all marked files. Answer `y' at the prompt.
Restart Emacs.
Now you are ready to test it before we try to make our own dictionary. Predictive comes with a quite large dictionary that you can use if you want to.
Open an empty buffer:
C-x b some-buffer RET
Enable predictive-mode:
M-x predictive-mode RET
Start typing. As soon as you start typing you should get a word suggested right there in your text. If you type space you will accept the word and you can then continue typing. If the suggested word is not the one you wanted, check the list at the bottom of the screen. When you find the word you want there, type the number that is displayed in front of the word to insert it into the text. Pretty neat eh?
There are various ways to pick a completion. For example, you can get a small menu by typing M-down. From this menu you can select the correct completion. Check out the manual for more possibilities.
Try this out for a while to get a feel for how it works. You will surely get somewhat annoyed in some cases. For example, let's say you want to write the word "the" and assume for the moment that it is not in the dictionary. The word "there", on the other hand, is. This is tricky, there is no word "the" to pick from the list and if you type space you will accept "there". Type M-ESC. This will reject the suggested word and leave what you just typed ("the") in the text. Then you can continue typing again.
So, you want your own dictionary, trained to your own writing?
There are at least two ways of filling a dictionary with words, one is to feed a formatted buffer or file to predictive and another is to have predictive add words as you are typing. I will demonstrate how to do the latter.
In a way, having predictive automatically adding words is like using abbrevs but not needing to define the words yourself. Powerful indeed!
Ok, let's go:
First we need to create a new dictionary:
M-x predictive-create-dict RET my-dict RET my-dir/predictive/my-dict RET RET
You can save your dictionary wherever you want ask long ask it is in your load-path (you will see later on how to load your dictionary.)
Then we need to set the new dictionary as the main one:
M-x predictive-set-main-dict RET my-dict RET
We want to automatically add words and to learn word frequencies, so we need to set a couple of variables:
- `predictive-auto-add-to-dict' - When set to `t', words are automatically added to the active dictionary.
- `predictive-add-to-dict-ask' - When set to `nil', don't ask for confirmation before adding are new word. I guess it is are matter of taste, but when you start adding words this way, I find it annoying to confirm each addition. I suggest you have it set to `nil' first and when your dictionary is starting to build up you can change it.
- `predictive-auto-learn - Enables predictive mode's automatic word frequency learning. When non-nil, the frequency count for that word is incremented each time a completion is accepted, making the word more likely to be offered higher up the list of completions in the future.
It suggest you use M-x customize-option RET option-name RET (or M-x customize-group RET predictive RET) to set those variables.
At first it will seem like nothing happens, that words you have typed is never suggested. This is because the variable `predictive-use-auto-learn-cache' is set to `t'. When it is non-nil, auto-added words are not added to the dictionary until Emacs has been idle for a period of time. The reason to wait is that the actual adding to the dictionary can cause a small but noticeable delay when typing. You can change this delay if you want by customizing the variable `predictive-flush-auto-learn-delay', by default set to 10.
So, to see that words added to the active dictionary are actually used, just pause for 10 seconds or more before starting to type again.
Finally, if you manually want to add a word that is not in the dictionary, place the cursor after the word and do:
M-x predictive-add-to-dict RET my-dict RET RET
`word' will be the default choice (hence the RET RET above).
I have created a couple of utility functions that I use. Here is an example:
(defun my-predictive-chat-english () (interactive) (predictive-mode 1) (require 'mathias-chat-english) (predictive-set-main-dict "mathias-chat-english"))
I have the same function for Swedish chat.
When I chat with my colleagues (using jabber.el of course) I just execute the correct function depending on what language I want to use.
I hope this little tutorial will help you get started a little bit faster than I did when I first tried it out. It takes some reading in the manual to find all customizable variables and to understand what they mean.
The manual has a lot of information; you should read it to understand how to customize predictive to work exactly the way you want.
Happy predicting!
PS. I wrote this article using predictive and let me tell you, it did go faster towards the ends when words was starting to build up in the dictionary :). Also, if you see any typos in this article it is probably due to the dictionary not being as "smart" as it should be yet.