1

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,

 ↓
aabc

I would expect forward completion to produce:

   ↓
abcabc

Instead, it produces:

    ↓
aabcabc

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

ivan
  • 1,928
  • 10
  • 20

1 Answers1

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.
          (dabbrev--goto-start-of-abbrev)

          (if (not (looking-at pattern1))
              nil
            ;; 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.

phils
  • 48,657
  • 3
  • 76
  • 115
  • 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 01 '22 at 04:12