The abbrev facility described above operates automatically as you insert text, but all abbrevs must be defined explicitly. By contrast, dynamic abbrevs allow the meanings of abbrevs to be determined automatically from the contents of the buffer, but dynamic abbrev expansion happens only when you request it explicitly.
For example, if the buffer contains `does this follow ' and you type f o M-/, the effect is to insert `follow' because that is the last word in the buffer that starts with `fo'. A numeric argument to M-/ says to take the second, third, etc. distinct expansion found looking backward from point. Repeating M-/ searches for an alternative expansion by looking farther back. After considering the entire buffer before point, it searches the text after point. After searching all of the current buffer, M-/ searches other buffers.
A negative argument to M-/, as in C-u - M-/, says to search first for expansions after point, and second for expansions before point. If you repeat the M-/ to look for another expansion, do not specify an argument. This tries all the expansions after point and then the expansions before point.
After you have expanded a dynamic abbrev, you can copy additional words that follow the expansion in its original context. Simply type SPC M-/ for each word you want to copy. The spacing and punctuation between words is copied along with the words.
In shell scripts and makefiles, a variable name is sometimes prefixed
with `$' and sometimes not. Major modes for this kind of text can
customize dynamic abbreviation to handle optional prefixes by setting
dabbrev-abbrev-skip-leading-regexp. Its value
should be a regular expression that matches the optional prefix that
dynamic abbreviation should ignore.
The command C-M-/ (
completion of a dynamic abbreviation. Instead of trying the possible
expansions one by one, it finds all of them, then inserts the text that
they have in common. If they have nothing in common, C-M-/
displays a list of completions, from which you can select a choice in
the usual manner. See section Completion.
Dynamic abbrev expansion is completely independent of Abbrev mode; the expansion of a word with M-/ is completely independent of whether it has a definition as an ordinary abbrev.