> The command is called "dabbrev-expand".
>
> I assigned it to my insert key with the following lines in .emacs:
If you want to be even more warped, try the following enhancements to your
tab key. My only warning is that you tend to wear out the tab key on your
keyboards...
(defun my-tab (&optional pre-arg)
" If preceeding character is part of a word then dabbrev-expand,
else if right of non whitespace on line then tab-to-tab-stop,
else if last command was a tab or return then dedent one step,
else indent 'correctly'
First, it determines the context around the point (current cursor
location).
If the preceeding character is part of a word, it tried to dynamically
expand that word. It uses the dabbrev package to do that. Dabbrev
looks backwards in the buffer to match that word. Each successive TAB
press will use a preceeding match. It will search backwards through the
buffer to the beginning, then from the point to the end of the buffer,
then all other buffers of the same mode (java in this case) and then
buffers of other modes. Just keep hitting TAB.
If the preceeding character is whitespace, it will move to the next tab
stop, if that is defined, or it will look at the previous line, and move
over to the next non-whitespace following whitespace column. Nice way
to align things. This is the indent-relative method.
Otherwise, if it's at the beginning of a line, it indent the whole line
according to the current mode's indentation method. This latter is the
usual binding for TAB within emacs.
"
(interactive "*P")
(cond ((= (char-syntax (preceding-char)) ?w)
(let ((case-fold-search t)) (dabbrev-expand pre-arg)))
((> (current-column) (current-indentation))
(indent-relative))
(t (indent-according-to-mode)))
(setq this-command 'my-tab))