diff options
| author | Daniel Mendler <mail@daniel-mendler.de> | 2024-01-03 14:19:39 +0100 |
|---|---|---|
| committer | Daniel Mendler <mail@daniel-mendler.de> | 2024-01-03 14:19:39 +0100 |
| commit | 61a20a50369de2cae77d649269d3c047fbbc27ec (patch) | |
| tree | f8a4fdd47cc747f5dbc223d820e29ba53bc3535d | |
| parent | ad5153a87af6b0f399c8badee1a255679c88eacd (diff) | |
corfu--teardown: Handle dead buffer during teardown
| -rw-r--r-- | corfu.el | 19 | ||||
| -rw-r--r-- | extensions/corfu-echo.el | 2 | ||||
| -rw-r--r-- | extensions/corfu-popupinfo.el | 2 |
3 files changed, 12 insertions, 11 deletions
@@ -893,8 +893,7 @@ See `completion-in-region' for the arguments BEG, END, TABLE, PRED." ;; Ensure that the tear-down runs in the correct buffer, if still alive. (unless completion-in-region-mode (remove-hook 'completion-in-region-mode-hook sym) - (with-current-buffer (if (buffer-live-p buf) buf (current-buffer)) - (corfu--teardown))))) + (corfu--teardown buf)))) (add-hook 'completion-in-region-mode-hook sym))) (defun corfu--in-region (&rest args) @@ -1165,15 +1164,17 @@ AUTO is non-nil when initializing auto completion." ;; 4) No candidates & auto completing or initialized => Quit. ((or auto corfu--input) (corfu-quit))))) -(cl-defgeneric corfu--teardown () - "Tear-down Corfu." +(cl-defgeneric corfu--teardown (buffer) + "Tear-down Corfu in BUFFER, which might be dead at this point." (corfu--popup-hide) - (remove-hook 'window-selection-change-functions #'corfu--window-change 'local) - (remove-hook 'window-buffer-change-functions #'corfu--window-change 'local) - (remove-hook 'pre-command-hook #'corfu--prepare 'local) - (remove-hook 'post-command-hook #'corfu--post-command) (when corfu--preview-ov (delete-overlay corfu--preview-ov)) - (accept-change-group corfu--change-group) + (remove-hook 'post-command-hook #'corfu--post-command) + (when (buffer-live-p buffer) + (with-current-buffer buffer + (remove-hook 'window-selection-change-functions #'corfu--window-change 'local) + (remove-hook 'window-buffer-change-functions #'corfu--window-change 'local) + (remove-hook 'pre-command-hook #'corfu--prepare 'local) + (accept-change-group corfu--change-group))) (cl-loop for (k . v) in corfu--initial-state do (set k v))) (defun corfu-sort-length-alpha (list) diff --git a/extensions/corfu-echo.el b/extensions/corfu-echo.el index edc7f8f..d93d819 100644 --- a/extensions/corfu-echo.el +++ b/extensions/corfu-echo.el @@ -97,7 +97,7 @@ subsequent delay." (corfu-echo--show (funcall fun cand)))))) (corfu-echo--cancel))) -(cl-defmethod corfu--teardown :before (&context (corfu-echo-mode (eql t))) +(cl-defmethod corfu--teardown :before (_buf &context (corfu-echo-mode (eql t))) (corfu-echo--cancel)) (cl-defmethod corfu--prepare :before (&context (corfu-echo-mode (eql t))) diff --git a/extensions/corfu-popupinfo.el b/extensions/corfu-popupinfo.el index ea4ce66..2b8b2d6 100644 --- a/extensions/corfu-popupinfo.el +++ b/extensions/corfu-popupinfo.el @@ -505,7 +505,7 @@ not be displayed until this command is called again, even if (corfu-popupinfo--hide)))) (corfu-popupinfo--hide)))) -(cl-defmethod corfu--teardown :before (&context (corfu-popupinfo-mode (eql t))) +(cl-defmethod corfu--teardown :before (_buf &context (corfu-popupinfo-mode (eql t))) (corfu-popupinfo--hide) (cl-loop for (k . v) in corfu-popupinfo--initial-state do (set k v)) (cl-callf2 assq-delete-all #'corfu-popupinfo-mode minor-mode-overriding-map-alist)) |
