Function: magit-get-mode-buffer

magit-get-mode-buffer is a byte-compiled function defined in magit-mode.el.

Signature

(magit-get-mode-buffer MODE &optional VALUE FRAME)

Documentation

Return buffer belonging to the current repository whose major-mode is MODE.

If no such buffer exists then return nil. Multiple buffers with the same major-mode may exist for a repository but only one can exist that hasn't been locked to its value. Return that buffer
(or nil if there is no such buffer) unless VALUE is non-nil, in
which case return the buffer that has been locked to that value.

If FRAME is nil or omitted, then consider all buffers. Otherwise
  only consider buffers that are displayed in some live window
  on some frame.
If all, then consider all buffers on all frames. If visible, then only consider buffers on all visible frames. If selected or t, then only consider buffers on the selected
  frame.
If a frame, then only consider buffers on that frame.

Source Code

;; Defined in ~/.emacs.d/elpa/magit-20260411.1452/magit-mode.el
(defun magit-get-mode-buffer (mode &optional value frame)
  "Return buffer belonging to the current repository whose major-mode is MODE.

If no such buffer exists then return nil.  Multiple buffers with
the same major-mode may exist for a repository but only one can
exist that hasn't been locked to its value.  Return that buffer
\(or nil if there is no such buffer) unless VALUE is non-nil, in
which case return the buffer that has been locked to that value.

If FRAME is nil or omitted, then consider all buffers.  Otherwise
  only consider buffers that are displayed in some live window
  on some frame.
If `all', then consider all buffers on all frames.
If `visible', then only consider buffers on all visible frames.
If `selected' or t, then only consider buffers on the selected
  frame.
If a frame, then only consider buffers on that frame."
  (let ((topdir (magit--toplevel-safe)))
    (cl-flet* ((b (buffer)
                 (with-current-buffer buffer
                   (and (eq major-mode mode)
                        (equal magit--default-directory topdir)
                        (if value
                            (and magit-buffer-locked-p
                                 (equal (magit-buffer-value) value))
                          (not magit-buffer-locked-p))
                        buffer)))
               (w (window)
                 (b (window-buffer window)))
               (f (frame)
                 (seq-some #'w (window-list frame 'no-minibuf))))
      (pcase-exhaustive frame
        ('nil                   (seq-some #'b (buffer-list)))
        ('all                   (seq-some #'f (frame-list)))
        ('visible               (seq-some #'f (visible-frame-list)))
        ((or 'selected 't)      (seq-some #'w (window-list (selected-frame))))
        ((guard (framep frame)) (seq-some #'w (window-list frame)))))))