Subject: bug#36516: Wrong dynamic abbrev expansion after space

From: Juri Linkov <[email-masked]>
Date: Mon, 08 Jul 2019 01:13:13 +0300

>> 0. emacs -Q
>> 1. Type these two lines:
>> str 1
>> str 2
>> 2. On the third line type:
>>  s                      ;; self-insert-command
>>  M-/                    ;; dabbrev-expand
>>  SPC                    ;; self-insert-command
>>  M-/                    ;; dabbrev-expand
>>  M-/                    ;; dabbrev-expand
>> 3. The word after "str " is expanded to some random word.
>
> Why did you expect something different?  The first M-/ copies "2", but
> the next one after that replaces "2" with some alternative, which
> exactly depends on what other buffers you have.  I see no bug here,
> you are just expecting from M-/ something it cannot give you.  The
> "SPC M-/" trick is already reaching too far out, IMO.

The example in the first part of my bug report demonstrates that
this useful feature works as documented in the manual.  Also
using ‘C-M-/’ (‘dabbrev-completion’) confirms that it works
as expected by displaying correct completions for both cases.

BTW, while reading the manual, I noticed the documentation bug in
(info "(emacs) Dynamic Abbrevs") that could be fixed by this patch:

diff --git a/doc/emacs/abbrevs.texi b/doc/emacs/abbrevs.texi
index 9c8a280efb..708adbb8a6 100644
--- a/doc/emacs/abbrevs.texi
+++ b/doc/emacs/abbrevs.texi
@@ -465,7 +465,7 @@ Dabbrev Customization
 generally appropriate for expanding symbols in a program source and
 also for human-readable text in many languages, but may not be what
 you want in a text buffer that includes unusual punctuation characters;
-in that case, the value @code{"\\sw"} might produce better results.
+in that case, the value @code{\\sw} might produce better results.
 
 @vindex dabbrev-abbrev-skip-leading-regexp
   In shell scripts and makefiles, a variable name is sometimes prefixed

PS: Also I noticed that the documentation of ‘M-x dissociated-press’
has no references to https://www.gutenberg.org/files/829/829-h/829-h.htm
the text starting with “He then led me to the frame, about the sides,
whereof all his pupils stood in ranks.”  But maybe the device described
in Gulliver's Travels has a different text generation algorithm than
dissociated-press, I'm not sure.