Make C-g close mini-buffer

This has annoyed me for a while, and I'm stealing Prot's solution.
This commit is contained in:
Howard Abrams 2024-12-09 09:23:06 -08:00
parent 994c36c5a5
commit c11ab5d0ef

View file

@ -98,6 +98,39 @@ And some Mac-specific settings:
(add-to-list 'default-frame-alist '(ns-transparent-titlebar . t)) (add-to-list 'default-frame-alist '(ns-transparent-titlebar . t))
(add-to-list 'default-frame-alist '(ns-appearance . dark))) (add-to-list 'default-frame-alist '(ns-appearance . dark)))
#+end_src #+end_src
** Make C-g a little more useful
Protesilaos has a simple fix for [[https://protesilaos.com/codelog/2024-11-28-basic-emacs-configuration/#h:1e468b2a-9bee-4571-8454-e3f5462d9321][closing minibuffer with C-g]]. His explanation:
#+begin_quote
Do-What-I-Mean behaviour for a general keyboard-quit. The generic keyboard-quit does not do the expected thing when the minibuffer is open. Whereas we want it to close the minibuffer, even without explicitly focusing it. The DWIM behaviour of this command is as follows:
- When the region is active, disable it.
- When a minibuffer is open, but not focused, close the minibuffer.
- When the Completions buffer is selected, close it.
- In every other case use the regular keyboard-quit.
#+end_quote
And my copy of his code:
#+begin_src emacs-lisp
(defun keyboard-quit-dwim ()
"Cancel everything, even in the mini-buffer."
(interactive)
(cond
((region-active-p)
(keyboard-quit))
((derived-mode-p 'completion-list-mode)
(delete-completion-window))
((> (minibuffer-depth) 0)
(abort-recursive-edit))
(t
(keyboard-quit))))
(define-key global-map (kbd "C-g") #'keyboard-quit-dwim)
#+end_src
** Emacs Everywhere ** Emacs Everywhere
After reading [[https://irreal.org/blog/?p=12139][Jon Sanders essay]] as well as [[https://mbork.pl/2024-04-27_Emacs_everywhere][Marcin Borkowski's essay]], I decided to try out Tecosaurs [[https://github.com/tecosaur/emacs-everywhere][Emacs Everywhere]] approach: After reading [[https://irreal.org/blog/?p=12139][Jon Sanders essay]] as well as [[https://mbork.pl/2024-04-27_Emacs_everywhere][Marcin Borkowski's essay]], I decided to try out Tecosaurs [[https://github.com/tecosaur/emacs-everywhere][Emacs Everywhere]] approach: