From 655eb827e1631fd47fd9cedaed6939e1e52e1184 Mon Sep 17 00:00:00 2001 From: Alexander Rosenberg Date: Sun, 9 Feb 2025 03:43:36 -0800 Subject: [PATCH] Change to a different method for fixing kkp and map-y-or-n-p --- init.el | 37 ++++++++++++------------------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/init.el b/init.el index 2dde593..10f3a20 100644 --- a/init.el +++ b/init.el @@ -446,35 +446,22 @@ directory. Otherwise, run `find-file' on that file." (insert-and-inherit char) (setq arg (1- arg)))))) (keymap-global-set "C-q" #'my/quoted-insert) - (defun my/-kkp-fix-map-y-or-n-p (oldfun &rest args) - "Fix `map-y-or-n-p' when used in a terminal with kkp enabled." + (defun my/kkp-disable-around-advice (oldfun &rest args) + "Run OLDFUN with ARGS with kkp disabled." (let ((status (kkp--this-terminal-has-active-kkp-p))) - (condition-case err + (unwind-protect (progn (when status (kkp-disable-in-terminal)) (apply oldfun args)) - (quit - ;; We won't die in this case, so just re-enable kkp - (when (and status (not (kkp--this-terminal-has-active-kkp-p))) - (kkp-enable-in-terminal)) - (signal 'quit nil)) - (t - (when (and status (not (kkp--this-terminal-has-active-kkp-p))) - ;; this does async stuff that will make kitty send characters after - ;; Emacs exits. We prevent that by not re-enabling if this frame (or - ;; Emacs) is about to die - (let ((will-die)) - (mapbacktrace - (lambda (_evald func _args _flags) - (when (or (eq func 'save-buffers-kill-emacs) - (eq func 'server-save-buffers-kill-terminal)) - (setq will-die t)))) - (unless will-die - (kkp-enable-in-terminal)))) - (when err - (signal (car err) (cdr err))))))) - (advice-add #'map-y-or-n-p :around - #'my/-kkp-fix-map-y-or-n-p)) + (when status (kkp-enable-in-terminal)) + ;; consume the response from the terminal. If this is not here and this + ;; function is set as advice for `map-y-or-n-p' called from + ;; `save-buffers-kill-terminal', a bunch of extra characters will be + ;; printed for the shell after Emacs exits because Emacs will die before + ;; it can read the terminal's response to `kkp-enable-in-terminal' + (while-no-input + (sleep-for 0.1))))) + (advice-add #'map-y-or-n-p :around #'my/kkp-disable-around-advice)) ;; some eww (status bar) stuff (defun my/cmdline-for-pid (pid)