Subject: RE: bug#42872: [PATCH] Add all-frames as arg for count windows.

From: Drew Adams <[email-masked]>
Date: Sun, 16 Aug 2020 07:50:15 -0700 (PDT)

In addition, you might consider this improvement, for
the current-frame behavior (which should remain the
default behavior): use arg MINIBUF only if the current
frame has a minibuffer.

I've had that in my version of `count-windows' since
1996, if not before that.  This is the code I have:

(defun count-windows (&optional minibuf)
  "Return the number of visible windows in selected frame.
Optional arg MINIBUF is used only if selected frame has a minibuffer.

MINIBUF = t means count the minibuffer window even if *not* active.
MINIBUF = nil or omitted means count the minibuffer iff it is active.
If MINIBUF is neither t nor nil it means not to count the minibuffer
even if it is active.  (See function `walk-windows'.)"
  (let ((count 0))
    (walk-windows 
     (function (lambda (w) (setq count (+ count 1))))
     (and (memq (cdr (assoc 'minibuffer (frame-parameters)))
                '(only t))           ; If this frame has a minibuffer,
          minibuf))                  ; pass the arg.  (Else pass nil.)
    count))