Subject: Add atomic window support to Gnus

From: Eric Abrahamsen <[email-masked]>
Date: Thu, 23 May 2019 13:45:13 -0700

The attached patch adds atomic window support with a new customization
option, `gnus-use-atomic-windows', defaulting to nil. If t, a
multi-window Gnus layout will be treated as a single window when other
code pops up buffers. Ie, your completions buffer won't end up squished
between the summary and article buffers.

I'm pretty sure I've done the elisp manual cross reference incorrectly.

Thanks,
Eric

Gnus v5.13
GNU Emacs 27.0.50 (build 15, x86_64-pc-linux-gnu, GTK+ Version 3.24.8)
 of 2019-05-23
200 news.gmane.org InterNetNews NNRP server INN 2.6.1 ready (posting ok)
100 Legal commands
  ARTICLE [message-ID|number]
  AUTHINFO USER name|PASS password|SASL mechanism [initial-response]|GENERIC program [argument ...]
  BODY [message-ID|number]
  CAPABILITIES [keyword]
  COMPRESS DEFLATE
  DATE
  GROUP newsgroup
  HDR header [message-ID|range]
  HEAD [message-ID|number]
  HELP
  IHAVE message-ID
  LAST
  LIST [ACTIVE [wildmat]|ACTIVE.TIMES [wildmat]|COUNTS [wildmat]|DISTRIB.PATS|DISTRIBUTIONS|HEADERS [MSGID|RANGE]|MODERATORS|MOTD|NEWSGROUPS [wildmat]|OVERVIEW.FMT|SUBSCRIPTIONS [wildmat]]
  LISTGROUP [newsgroup [range]]
  MODE READER
  NEWGROUPS [yy]yymmdd hhmmss [GMT]
  NEWNEWS wildmat [yy]yymmdd hhmmss [GMT]
  NEXT
  OVER [range]
  POST
  QUIT
  STARTTLS
  STAT [message-ID|number]
  XGTITLE [wildmat]
  XHDR header [message-ID|range]
  XOVER [range]
  XPAT header message-ID|range pattern [pattern ...]
Report problems to <[email-masked]>.
.
382 Begin TLS negotiation now
100 Legal commands
  ARTICLE [message-ID|number]
  AUTHINFO USER name|PASS password|SASL mechanism [initial-response]|GENERIC program [argument ...]
  BODY [message-ID|number]
  CAPABILITIES [keyword]
  COMPRESS DEFLATE
  DATE
  GROUP newsgroup
  HDR header [message-ID|range]
  HEAD [message-ID|number]
  HELP
  IHAVE message-ID
  LAST
  LIST [ACTIVE [wildmat]|ACTIVE.TIMES [wildmat]|COUNTS [wildmat]|DISTRIB.PATS|DISTRIBUTIONS|HEADERS [MSGID|RANGE]|MODERATORS|MOTD|NEWSGROUPS [wildmat]|OVERVIEW.FMT|SUBSCRIPTIONS [wildmat]]
  LISTGROUP [newsgroup [range]]
  MODE READER
  NEWGROUPS [yy]yymmdd hhmmss [GMT]
  NEWNEWS wildmat [yy]yymmdd hhmmss [GMT]
  NEXT
  OVER [range]
  POST
  QUIT
  STARTTLS
  STAT [message-ID|number]
  XGTITLE [wildmat]
  XHDR header [message-ID|range]
  XOVER [range]
  XPAT header message-ID|range pattern [pattern ...]
Report problems to <[email-masked]>.
.
>From 48b94c157144230f9e955d4b94202ee152f3d820 Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <[email-masked]>
Date: Thu, 23 May 2019 13:41:47 -0700
Subject: [PATCH] Add atomic window support to Gnus

* lisp/gnus/gnus-win.el (gnus-use-atomic-windows): New option
  governing behavior, default to nil.
  (gnus-configure-windows): Add and remove 'atomic-window parameter
  when switching window configurations.
* doc/misc/gnus.texi (Window Layout): Document.
---
 doc/misc/gnus.texi    |  6 ++++++
 lisp/gnus/gnus-win.el | 18 ++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/doc/misc/gnus.texi b/doc/misc/gnus.texi
index b9c91a02a3..c09d9dc47f 100644
--- a/doc/misc/gnus.texi
+++ b/doc/misc/gnus.texi
@@ -22918,6 +22918,12 @@ Window Layout
 to fiddle with @code{gnus-tree-minimize-window} to avoid having the
 windows resized.
 
+@vindex gnus-use-atomic-windows
+Lastly, when you've got a multiple-window layout, Gnus can treat them
+as one ``atomic window'' with regards to help or completion pop-up
+windows (@pxref{Atomic Windows, , Atomic Windows, elisp}).  Set @code{gnus-use-atomic-windows}
+to a non-@code{nil} value to enable this.
+
 @subsection Window Configuration Names
 
 Here's a list of most of the currently known window configurations,
diff --git a/lisp/gnus/gnus-win.el b/lisp/gnus/gnus-win.el
index 40c5b42d45..04d9e40884 100644
--- a/lisp/gnus/gnus-win.el
+++ b/lisp/gnus/gnus-win.el
@@ -39,6 +39,10 @@ gnus-use-full-window
   :group 'gnus-windows
   :type 'boolean)
 
+(defcustom gnus-use-atomic-windows nil
+  "If non-nil, Gnus' window compositions will be atomic."
+  :type 'boolean)
+
 (defcustom gnus-window-min-width 2
   "Minimum width of Gnus buffers."
   :group 'gnus-windows
@@ -402,6 +406,15 @@ gnus-configure-windows
         (unless (gnus-buffer-live-p nntp-server-buffer)
           (nnheader-init-server-buffer))
 
+	;; Remove all 'window-atom parameters, as we're going to blast
+	;; and recreate the window layout.
+	(when (window-parameter nil 'window-atom)
+	  (let ((root (window-atom-root)))
+	    (walk-window-subtree
+	     (lambda (win)
+	       (set-window-parameter win 'window-atom nil))
+	     root t)))
+
         ;; Either remove all windows or just remove all Gnus windows.
         (let ((frame (selected-frame)))
           (unwind-protect
@@ -423,6 +436,11 @@ gnus-configure-windows
           (set-buffer nntp-server-buffer)
           (gnus-configure-frame split)
           (run-hooks 'gnus-configure-windows-hook)
+
+	  (when (and gnus-use-atomic-windows
+		     (window-parent (selected-window)))
+	    (window-make-atom (window-parent (selected-window))))
+
           (when gnus-window-frame-focus
             (select-frame-set-input-focus
              (window-frame gnus-window-frame-focus)))))))))
-- 
2.21.0