From 821cd3f496503cdb7654f3faf08e06445971cfd7 Mon Sep 17 00:00:00 2001 From: Mountain Man <43313373+MountainMan1312@users.noreply.github.com> Date: Sun, 9 Apr 2023 19:52:04 -0400 Subject: Fix ESC key behavior By default the ESC key has bizarre behavior. Sometimes it quits the thing you're doing, sometimes it completely removes your window layout. This fixes the issue by defining a new version of `keyboard-escape-quit` and removing the keybing for `ESC ESC`. --- init.el | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/init.el b/init.el index 302aad5..1b2ac9d 100644 --- a/init.el +++ b/init.el @@ -41,3 +41,54 @@ ;; --------------------------------- (setq create-lockfiles nil) + + + + +;; --------------------------------------------------------------------- +;;; Keybinds +;; --------- +;; For now, just a few simple changes. +;; In the future there will be whole custom keybind system. +;; --------------------------------------------------------------------- + +;; --------------------------------- +;; Fix ESC behavior +;; ---------------- +;; The default behavior of the ESC +;; key is atrocious. Why in God's +;; name would I want it to close all +;; my windows when I press it twice? +;; +;; This fixes the behavior to do +;; what ESC should do: "escape" the +;; current thing I'm doing, like the +;; minibuffer or a popup window. +;; --------------------------------- + +;; Define fixed version of `keyboard-escape-quit' which does not close +;; windows or change their layout. +(defun mm/keyboard-escape-quit-keep-windows () + "Alternative version of `keyboard-escape-quit' that does not change window layout." + (interactive) + (cond ((eq last-command 'mode-exited) nil) + ((region-active-p) + (deactivate-mark)) + ((> (minibuffer-depth) 0) + (abort-recursive-edit)) + (current-prefix-arg + nil) + ((> (recursion-depth) 0) + (exit-recursive-edit)) + (buffer-quit-function + (funcall buffer-quit-function)) + ;; The following lines are from `keyboard-escape-quit'. + ;; They have been commented to disable the unwanted behavior + ;; ((not (one-window-p t)) + ;; (delete-other-windows) + ((string-match "^ \\*" (buffer-name (current-buffer))) + bury-buffer))) + +;; Fix the keybinds for the ESC key +(global-set-key (kbd "") 'mm/keyboard-escape-quit-keep-windows) +(global-unset-key (kbd "C-x ESC ESC")) -- cgit v1.2.3