diff options
| author | Stefan Monnier | 2025-09-25 15:24:53 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2025-09-25 15:24:53 -0400 |
| commit | fa8e32f757198a3b883c8015c763572a2be2a707 (patch) | |
| tree | d338f4378eef288996e03d326f15f5c72b5dee25 | |
| parent | 06d87e44cb614b846f37eb25ccafce2065e2e9d2 (diff) | |
| download | emacs-fa8e32f757198a3b883c8015c763572a2be2a707.tar.gz emacs-fa8e32f757198a3b883c8015c763572a2be2a707.zip | |
(dabbrev-completion): Try and fix the test regressions
* lisp/dabbrev.el (dabbrev-completion): Revert this part of last
change, but additionally set `dabbrev--last-abbrev-location` so we know
what the vars were reset for.
(dabbrev-capf): Be more careful about when and how to reset the vars.
(dabbrev--abbrev-at-point): Don't set `dabbrev--last-abbrev-location`,
so it doesn't mess with the marker we set it to in
`dabbrev-capf` or `dabbrev-completion`.
| -rw-r--r-- | lisp/dabbrev.el | 56 |
1 files changed, 36 insertions, 20 deletions
diff --git a/lisp/dabbrev.el b/lisp/dabbrev.el index 8f8c691fe5d..4b471eb794c 100644 --- a/lisp/dabbrev.el +++ b/lisp/dabbrev.el | |||
| @@ -391,15 +391,32 @@ completions. | |||
| 391 | If the prefix argument is 16 (which comes from \\[universal-argument] \\[universal-argument]), | 391 | If the prefix argument is 16 (which comes from \\[universal-argument] \\[universal-argument]), |
| 392 | then it searches *all* buffers." | 392 | then it searches *all* buffers." |
| 393 | (interactive "*P") | 393 | (interactive "*P") |
| 394 | (dabbrev--reset-global-variables) | ||
| 394 | (setq dabbrev--check-other-buffers (and arg t)) | 395 | (setq dabbrev--check-other-buffers (and arg t)) |
| 395 | (setq dabbrev--check-all-buffers | 396 | (setq dabbrev--check-all-buffers |
| 396 | (and arg (= (prefix-numeric-value arg) 16))) | 397 | (and arg (= (prefix-numeric-value arg) 16))) |
| 398 | ;; Set it so `dabbrev-capf' won't reset the vars. | ||
| 399 | (setq dabbrev--last-abbrev-location (point-marker)) | ||
| 397 | (let ((completion-at-point-functions '(dabbrev-capf))) | 400 | (let ((completion-at-point-functions '(dabbrev-capf))) |
| 398 | (completion-at-point))) | 401 | (completion-at-point))) |
| 399 | 402 | ||
| 400 | (defun dabbrev-capf () | 403 | (defun dabbrev-capf () |
| 401 | "Dabbrev completion function for `completion-at-point-functions'." | 404 | "Dabbrev completion function for `completion-at-point-functions'." |
| 402 | (dabbrev--reset-global-variables) | 405 | ;; Don't reset the vars if we're in the "same" completion, especially since |
| 406 | ;; they may have been set to different values, e.g. if the user passes | ||
| 407 | ;; a non-nil ARG to `dabbrev-completion'. | ||
| 408 | (unless (and (markerp dabbrev--last-abbrev-location) | ||
| 409 | (eq (current-buffer) | ||
| 410 | (marker-buffer dabbrev--last-abbrev-location)) | ||
| 411 | (= (point) dabbrev--last-abbrev-location)) | ||
| 412 | (dabbrev--reset-global-variables) | ||
| 413 | ;; FIXME: Contrary to `dabbrev-completion', the CAPF protocol doesn't | ||
| 414 | ;; have a way to control the scope of the search. We just default | ||
| 415 | ;; to confine it to the current buffer. | ||
| 416 | (setq dabbrev--check-other-buffers nil) | ||
| 417 | (setq dabbrev--check-all-buffers nil) | ||
| 418 | (setq dabbrev--last-abbrev-location (point-marker))) | ||
| 419 | |||
| 403 | (let* ((abbrev (dabbrev--abbrev-at-point)) | 420 | (let* ((abbrev (dabbrev--abbrev-at-point)) |
| 404 | (beg (progn (search-backward abbrev) (point))) | 421 | (beg (progn (search-backward abbrev) (point))) |
| 405 | (end (progn (search-forward abbrev) (point))) | 422 | (end (progn (search-forward abbrev) (point))) |
| @@ -645,25 +662,24 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]." | |||
| 645 | ;; Return abbrev at point | 662 | ;; Return abbrev at point |
| 646 | (save-excursion | 663 | (save-excursion |
| 647 | ;; Record the end of the abbreviation. | 664 | ;; Record the end of the abbreviation. |
| 648 | (setq dabbrev--last-abbrev-location (point)) | 665 | (let ((end (point))) |
| 649 | ;; If we aren't right after an abbreviation, | 666 | ;; If we aren't right after an abbreviation, |
| 650 | ;; move point back to just after one. | 667 | ;; move point back to just after one. |
| 651 | ;; This is so the user can get successive words | 668 | ;; This is so the user can get successive words |
| 652 | ;; by typing the punctuation followed by M-/. | 669 | ;; by typing the punctuation followed by M-/. |
| 653 | (save-match-data | 670 | (save-match-data |
| 654 | (if (save-excursion | 671 | (if (save-excursion |
| 655 | (forward-char -1) | 672 | (forward-char -1) |
| 656 | (not (looking-at (or dabbrev-abbrev-char-regexp | 673 | (not (looking-at (or dabbrev-abbrev-char-regexp |
| 657 | "\\sw\\|\\s_")))) | 674 | "\\sw\\|\\s_")))) |
| 658 | (if (re-search-backward (or dabbrev-abbrev-char-regexp | 675 | (if (re-search-backward (or dabbrev-abbrev-char-regexp |
| 659 | "\\sw\\|\\s_") | 676 | "\\sw\\|\\s_") |
| 660 | nil t) | 677 | nil t) |
| 661 | (forward-char 1) | 678 | (forward-char 1) |
| 662 | (user-error "No possible abbreviation preceding point")))) | 679 | (user-error "No possible abbreviation preceding point")))) |
| 663 | ;; Now find the beginning of that one. | 680 | ;; Now find the beginning of that one. |
| 664 | (dabbrev--goto-start-of-abbrev) | 681 | (dabbrev--goto-start-of-abbrev) |
| 665 | (buffer-substring-no-properties | 682 | (buffer-substring-no-properties (point) end)))) |
| 666 | dabbrev--last-abbrev-location (point)))) | ||
| 667 | 683 | ||
| 668 | (defun dabbrev--reset-global-variables () | 684 | (defun dabbrev--reset-global-variables () |
| 669 | "Initialize all global variables." | 685 | "Initialize all global variables." |