diff options
| author | Stephen Berman | 2024-11-30 23:28:06 +0100 |
|---|---|---|
| committer | Stephen Berman | 2024-11-30 23:28:06 +0100 |
| commit | bd8a6f70fb947c4ea11c4772cff6e81180e5e35a (patch) | |
| tree | a0d6a27f15b32459ceaa0da4d6aa25acf3b3c7ea | |
| parent | 0a753603a53622d939661d796eb203908867bb9e (diff) | |
| download | emacs-bd8a6f70fb947c4ea11c4772cff6e81180e5e35a.tar.gz emacs-bd8a6f70fb947c4ea11c4772cff6e81180e5e35a.zip | |
Prevent "Selecting deleted buffer" error with dabbrev-expand
* lisp/dabbrev.el (dabbrev-expand): Use the buffer where the last
expansion was found only if it is still a live buffer (bug#74090).
* test/lisp/dabbrev-tests.el (dabbrev-expand-test-minibuffer-3):
Fix typo in doc string.
(dabbrev-expand-after-killing-buffer): New test.
| -rw-r--r-- | lisp/dabbrev.el | 6 | ||||
| -rw-r--r-- | test/lisp/dabbrev-tests.el | 34 |
2 files changed, 37 insertions, 3 deletions
diff --git a/lisp/dabbrev.el b/lisp/dabbrev.el index bbe6a64b626..84306fb3ae7 100644 --- a/lisp/dabbrev.el +++ b/lisp/dabbrev.el | |||
| @@ -472,8 +472,10 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]." | |||
| 472 | ;; minibuffer. | 472 | ;; minibuffer. |
| 473 | (window-buffer (get-mru-window))) | 473 | (window-buffer (get-mru-window))) |
| 474 | ;; Otherwise, if we found the expansion in another | 474 | ;; Otherwise, if we found the expansion in another |
| 475 | ;; buffer, use that buffer for further expansions. | 475 | ;; buffer and that buffer is still live, use that |
| 476 | (dabbrev--last-buffer-found dabbrev--last-buffer-found) | 476 | ;; buffer for further expansions. |
| 477 | ((buffer-live-p dabbrev--last-buffer-found) | ||
| 478 | dabbrev--last-buffer-found) | ||
| 477 | ;; Otherwise, use the buffer where we invoked | 479 | ;; Otherwise, use the buffer where we invoked |
| 478 | ;; dabbrev-expand. | 480 | ;; dabbrev-expand. |
| 479 | (t (current-buffer)))) | 481 | (t (current-buffer)))) |
diff --git a/test/lisp/dabbrev-tests.el b/test/lisp/dabbrev-tests.el index 987106aa5af..b5737373875 100644 --- a/test/lisp/dabbrev-tests.el +++ b/test/lisp/dabbrev-tests.el | |||
| @@ -238,7 +238,7 @@ entered." | |||
| 238 | ;; FIXME: Why is dabbrev--reset-global-variables needed here? | 238 | ;; FIXME: Why is dabbrev--reset-global-variables needed here? |
| 239 | (ert-deftest dabbrev-expand-test-minibuffer-3 () | 239 | (ert-deftest dabbrev-expand-test-minibuffer-3 () |
| 240 | "Test replacing an expansion in the minibuffer using two buffers. | 240 | "Test replacing an expansion in the minibuffer using two buffers. |
| 241 | The first expansion should befound in the buffer from which the | 241 | The first expansion should be found in the buffer from which the |
| 242 | minibuffer was entered, the replacement should found in another buffer." | 242 | minibuffer was entered, the replacement should found in another buffer." |
| 243 | (with-dabbrev-test | 243 | (with-dabbrev-test |
| 244 | (find-file (ert-resource-file "INSTALL_BEGIN")) | 244 | (find-file (ert-resource-file "INSTALL_BEGIN")) |
| @@ -275,4 +275,36 @@ minibuffer was entered, the replacement should found in another buffer." | |||
| 275 | (should (string= (minibuffer-contents) "Indic and")) | 275 | (should (string= (minibuffer-contents) "Indic and")) |
| 276 | (delete-minibuffer-contents)))) | 276 | (delete-minibuffer-contents)))) |
| 277 | 277 | ||
| 278 | (ert-deftest dabbrev-expand-after-killing-buffer () | ||
| 279 | "Test expansion after killing buffer containing first expansion. | ||
| 280 | Finding successive expansions in another live buffer should succeed, but | ||
| 281 | after killing the buffer, expansion should fail with a user-error." | ||
| 282 | ;; FIXME? The message shown by the user-error is in *Messages* but | ||
| 283 | ;; since the test finishes on hitting the user-error, we cannot test | ||
| 284 | ;; further, either for the content of the message or the content of | ||
| 285 | ;; the current buffer, so apparently cannot reproduce what a user | ||
| 286 | ;; entering these commands manually sees. | ||
| 287 | (with-dabbrev-test | ||
| 288 | (with-current-buffer (get-buffer-create "foo") | ||
| 289 | (insert "abc abd")) | ||
| 290 | (switch-to-buffer "*scratch*") | ||
| 291 | (erase-buffer) | ||
| 292 | (execute-kbd-macro (kbd "ab M-/")) | ||
| 293 | (should (string= (buffer-string) "abc")) | ||
| 294 | (execute-kbd-macro (kbd "SPC ab M-/")) | ||
| 295 | (should (string= (buffer-string) "abc abc")) | ||
| 296 | (erase-buffer) | ||
| 297 | (execute-kbd-macro (kbd "abc SPC ab M-/ M-/")) | ||
| 298 | (should (string= (buffer-string) "abc abd")) | ||
| 299 | (kill-buffer "foo") | ||
| 300 | (erase-buffer) | ||
| 301 | (should-error (execute-kbd-macro (kbd "abc SPC ab M-/ M-/")) | ||
| 302 | :type 'user-error) | ||
| 303 | ;; (should (string= (buffer-string) "abc abc")) | ||
| 304 | ;; (with-current-buffer "*Messages*" | ||
| 305 | ;; (goto-char (point-max)) | ||
| 306 | ;; (should (string= (buffer-substring (pos-bol) (pos-eol)) | ||
| 307 | ;; "No further dynamic expansion for ‘ab’ found"))) | ||
| 308 | )) | ||
| 309 | |||
| 278 | ;;; dabbrev-tests.el ends here | 310 | ;;; dabbrev-tests.el ends here |