Given a buffer containing a abc with point immediately following the first a,

a abc

if I perform forward completion with (dabbrev-expand -1), it produces the result I would expect:

abc abc

But given a buffer containing aabc with point immediately following the first a,


I would expect forward completion to produce:


Instead, it produces:


Is this a bug, or a misunderstanding on my part?

1 Answer 1


This is on account of dabbrev--search. In your case, the pattern values are your "a" prefix followed by word/symbol-constituent characters, and reverse is nil.

        ;; Look for a distinct expansion, using dabbrev--last-table.
        (while (and (not found-string)
                    (if reverse
                        (re-search-backward pattern1 nil t)
                      (re-search-forward pattern1 nil t)))
          (goto-char (match-beginning 0))
          ;; In case we matched in the middle of a word,
          ;; back up to start of word and verify we still match.

          (if (not (looking-at pattern1))
            ;; We have a truly valid match.  Find the end.
            (re-search-forward pattern2)
            (setq found-string (match-string-no-properties 0))
            (setq result found-string)

So it finds a match for a, backs up to the start of the word, still matches a (now a different one), and grabs the word as the completion.

  • 1
    And this might arguably be a bug, although I've not checked the docs. Perhaps dabbrev--goto-start-of-abbrev should be bounded by the initial position of point in this scenario.
    – phils
    Aug 1 at 4:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.