diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2021-04-04 12:59:21 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2021-04-05 16:51:55 -0700 |
commit | 3b4f215a16e629b4e780d17ac5beecf50b0a6323 (patch) | |
tree | ca14e101c33cd44827fa438f723aaa545b380912 | |
parent | 6516e1a501bd736141b9c2e321591a7bade57bbe (diff) | |
download | dotfiles-3b4f215a16e629b4e780d17ac5beecf50b0a6323.tar.gz |
avoid the Slime debugger grabbing keyboard focus
-rw-r--r-- | .emacs.d/init-spw.el | 34 |
1 files changed, 34 insertions, 0 deletions
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) |