Subject: [PATCH] keyboard-escape-quit should give option not to delete windows

From: Alex Branham <[email-masked]>
Date: Wed, 31 Jan 2018 20:59:48 -0600

I've always found it a bit odd that ESC-ESC-ESC deletes windows, since I
think of it as telling Emacs to "stop doing whatever it is you're
doing". I guess there's a case to be made that splitting the frame is
doing something, but it's behavior I'm not a huge fan of.

The attached patch introduces a new defcustom that allows the user to
stop ESC-ESC-ESC from deleting windows. I'm not sure if this should be
documented in the manual or not. If so, please let me know (and where?).

Thanks for all your work!
Alex

--------------------

>From 30351ba514094b2364298b7723ae7c33685bf53e Mon Sep 17 00:00:00 2001
From: Alex Branham <[email-masked]>
Date: Wed, 31 Jan 2018 20:44:55 -0600
Subject: [PATCH] New defcustom `keyboard-escape-quit-deletes-windows'

* lisp/simple.el (`keyboard-escape-quit-deletes-windows'): New
  defcustom to control whether keyboard-escape-quit calls
  delete-other-windows
(keyboard-escape-quit): Use it

* etc/NEWS: Mention `keyboard-escape-quit-deletes-windows'.
---
 etc/NEWS       |  5 +++++
 lisp/simple.el | 11 +++++++++--
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index b28f284116..d6ba6f28b8 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -80,6 +80,11 @@ indirectly, e.g., by checking that functions like
 It blocks line breaking after a one-letter word, also in the case when
 this word is preceded by a non-space, but non-alphanumeric character.

+** New option 'keyboard-escape-quit-deletes-windows'.
+This determines whether 'keyboard-escape-quit' eventually calls
+'delete-other-windows'.  The default (t) preserves behavior from
+previous Emacs.
+
 +++
 ** The limit on repetitions in regexps has been raised to 2^16-1.
 It was previously limited to 2^15-1.  For example, the following
diff --git a/lisp/simple.el b/lisp/simple.el
index 375ee31e9c..695bb12ac1 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -7706,6 +7706,11 @@ At top-level, as an editor command, this simply beeps."
   (let ((debug-on-quit nil))
     (signal 'quit nil)))

+(defcustom keyboard-escape-quit-deletes-windows t
+  "If non-nil, `keyboard-escape-quit' eventually calls `delete-other-windows'."
+  :group 'windows
+  :type 'boolean)
+
 (defvar buffer-quit-function nil
   "Function to call to \"quit\" the current buffer, or nil if none.
 \\[keyboard-escape-quit] calls this function when its more local actions
@@ -7717,7 +7722,8 @@ This command can exit an interactive command such as `query-replace',
 can clear out a prefix argument or a region,
 can get out of the minibuffer or other recursive edit,
 cancel the use of the current buffer (for special-purpose buffers),
-or go back to just one window (by deleting all but the selected window)."
+or go back to just one window (by deleting all but the selected window, but
+see `keyboard-escape-quit-deletes-windows')."
   (interactive)
   (cond ((eq last-command 'mode-exited) nil)
 	((region-active-p)
@@ -7730,7 +7736,8 @@ or go back to just one window (by deleting all but the selected window)."
 	 (exit-recursive-edit))
 	(buffer-quit-function
 	 (funcall buffer-quit-function))
-	((not (one-window-p t))
+	((and (not (one-window-p t))
+              keyboard-escape-quit-deletes-windows)
 	 (delete-other-windows))
 	((string-match "^ \\*" (buffer-name (current-buffer)))
 	 (bury-buffer))))
--
2.16.1
>From 30351ba514094b2364298b7723ae7c33685bf53e Mon Sep 17 00:00:00 2001
From: Alex Branham <[email-masked]>
Date: Wed, 31 Jan 2018 20:44:55 -0600
Subject: [PATCH 1/1] New defcustom `keyboard-escape-quit-deletes-windows'

* lisp/simple.el (`keyboard-escape-quit-deletes-windows'): New
  defcustom to control whether keyboard-escape-quit calls
  delete-other-windows
(keyboard-escape-quit): Use it

* etc/NEWS: Mention `keyboard-escape-quit-deletes-windows'.
---
 etc/NEWS       |  5 +++++
 lisp/simple.el | 11 +++++++++--
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index b28f284116..d6ba6f28b8 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -80,6 +80,11 @@ indirectly, e.g., by checking that functions like
 It blocks line breaking after a one-letter word, also in the case when
 this word is preceded by a non-space, but non-alphanumeric character.
 
+** New option 'keyboard-escape-quit-deletes-windows'.
+This determines whether 'keyboard-escape-quit' eventually calls
+'delete-other-windows'.  The default (t) preserves behavior from
+previous Emacs.
+
 +++
 ** The limit on repetitions in regexps has been raised to 2^16-1.
 It was previously limited to 2^15-1.  For example, the following
diff --git a/lisp/simple.el b/lisp/simple.el
index 375ee31e9c..695bb12ac1 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -7706,6 +7706,11 @@ At top-level, as an editor command, this simply beeps."
   (let ((debug-on-quit nil))
     (signal 'quit nil)))
 
+(defcustom keyboard-escape-quit-deletes-windows t
+  "If non-nil, `keyboard-escape-quit' eventually calls `delete-other-windows'."
+  :group 'windows
+  :type 'boolean)
+
 (defvar buffer-quit-function nil
   "Function to call to \"quit\" the current buffer, or nil if none.
 \\[keyboard-escape-quit] calls this function when its more local actions
@@ -7717,7 +7722,8 @@ This command can exit an interactive command such as `query-replace',
 can clear out a prefix argument or a region,
 can get out of the minibuffer or other recursive edit,
 cancel the use of the current buffer (for special-purpose buffers),
-or go back to just one window (by deleting all but the selected window)."
+or go back to just one window (by deleting all but the selected window, but
+see `keyboard-escape-quit-deletes-windows')."
   (interactive)
   (cond ((eq last-command 'mode-exited) nil)
 	((region-active-p)
@@ -7730,7 +7736,8 @@ or go back to just one window (by deleting all but the selected window)."
 	 (exit-recursive-edit))
 	(buffer-quit-function
 	 (funcall buffer-quit-function))
-	((not (one-window-p t))
+	((and (not (one-window-p t))
+              keyboard-escape-quit-deletes-windows)
 	 (delete-other-windows))
 	((string-match "^ \\*" (buffer-name (current-buffer)))
 	 (bury-buffer))))
-- 
2.16.1