From 3b4f215a16e629b4e780d17ac5beecf50b0a6323 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sun, 4 Apr 2021 12:59:21 -0700 Subject: avoid the Slime debugger grabbing keyboard focus --- .emacs.d/init-spw.el | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/.emacs.d/init-spw.el b/.emacs.d/init-spw.el index bf88f2dc..10751ceb 100644 --- a/.emacs.d/init-spw.el +++ b/.emacs.d/init-spw.el @@ -143,6 +143,16 @@ add places the library might be available to `load-path'." (setenv "DISPLAY" display-env)) wm)))) +(defmacro spw/add-once-hook (hook function &optional depth local) + "Add a hook which removes itself when called. For something +which should happen just once." + (let ((sym (cl-gensym))) + `(progn + (fset ',sym (lambda () + (remove-hook ,hook ',sym ,local) + (funcall ,function))) + (add-hook ,hook ',sym ,depth ,local)))) + ;;;; Startup & basic preferences @@ -2674,6 +2684,30 @@ mutt's review view, after exiting EDITOR." (global-set-key "\C-cgh" #'hyperspec-lookup) +(with-eval-after-load 'slime + (defvar spw/last-command-was-slime-async-eval nil) + + (defun spw/record-last-command-was-slime-async-eval (&rest ignore) + (spw/add-once-hook 'pre-command-hook + (lambda () + (setq spw/last-command-was-slime-async-eval nil))) + (setq spw/last-command-was-slime-async-eval t)) + (dolist (f '(slime-repl-return + slime-mrepl-return + slime-compile-region + slime-compile-file + sldb-eval-in-frame + slime-interactive-eval)) + (advice-add f :after #'spw/record-last-command-was-slime-async-eval)) + + (defun spw/sldb-setup-avoid-focus-grab (orig-fun &rest args) + "Don't allow the Slime debugger to grab keyboard focus unless we +are sure that the user is expecting that it might pop up." + (if spw/last-command-was-slime-async-eval + (apply orig-fun args) + (save-selected-window (apply orig-fun args)))) + (advice-add 'sldb-setup :around #'spw/sldb-setup-avoid-focus-grab)) + (with-eval-after-load 'slime-repl (defun spw/slime-clear-source-registry () (interactive) -- cgit v1.2.3