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

From: Juri Linkov <[email-masked]>
Date: Sat, 03 Aug 2019 23:58:13 +0300

>> Maybe it's possible to break out of the vicious cycle of ‘SPC M-/’
>> repetitions by making ‘SPC M-/’ look like a normal expansion, e.g.:
>
> This looks good to me. The only problem is it breaks the test for
> bug#1948. I think it no longer squashes all the spaces.

Sorry for breaking the test, I'll try to find a fix that will pass all tests.

Meanwhile, I started to rely heavily on consequent calls of M-/ and
today this feature reared its ugly head (so then could it be called
a misfeature).  Here's is the case that raises the error:

0. emacs -Q

1. Type these two lines:
str 1
str 2

(optionally set debug-on-error to t)

2. On the third line type:
 s			;; self-insert-command
 M-/			;; dabbrev-expand
 SPC			;; self-insert-command
 M-/			;; dabbrev-expand
 M-/			;; dabbrev-expand
 <backspace>		;; backward-delete-char-untabify
 <backspace>		;; backward-delete-char-untabify
 <backspace>		;; backward-delete-char-untabify
 <backspace>		;; backward-delete-char-untabify
 <backspace>		;; backward-delete-char-untabify

The amount of <backspace> keypresses depends on the length
of the random word expanded, so the intention is to delete
that word and the space character.

 SPC			;; self-insert-command
 M-/			;; dabbrev-expand

and the bug is revealed that signals this error:

Debugger entered--Lisp error: (search-failed "\\(?:\\sw\\|\\s_\\)+")
  re-search-forward("\\(?:\\sw\\|\\s_\\)+")
  dabbrev-expand(nil)
  funcall-interactively(dabbrev-expand nil)
  call-interactively(dabbrev-expand nil nil)
  command-execute(dabbrev-expand)