Function: gdb-display-source-buffer

gdb-display-source-buffer is a byte-compiled function defined in gdb-mi.el.gz.

Signature

(gdb-display-source-buffer BUFFER)

Documentation

Find a window to display BUFFER.

Always find a window to display buffer, and return it.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/gdb-mi.el.gz
;; GUD displays the selected GDB frame.  This might might not be the current
;; GDB frame (after up, down etc).  If no GDB frame is visible but the last
;; visited breakpoint is, use that window.
(defun gdb-display-source-buffer (buffer)
  "Find a window to display BUFFER.
Always find a window to display buffer, and return it."
  ;; This function doesn't take care of setting up source window(s) at startup,
  ;; that's handled by `gdb-setup-windows' (if `gdb-many-windows' is non-nil).
  ;; If `buffer' is already shown in a window, use that window.
  (or (get-buffer-window buffer)
      (progn
        ;; First, update the window list.
        (setq gdb-source-window-list
              (cl-remove-duplicates
               (cl-remove-if-not
                (lambda (win)
                  (and (window-live-p win)
                       (eq (window-frame win)
                           (selected-frame))))
                gdb-source-window-list)))
        ;; Should we create a new window or reuse one?
        (if (> gdb-max-source-window-count
               (length gdb-source-window-list))
            ;; Create a new window, push it to window list and return it.
            (car (push (display-buffer buffer gdb-display-source-buffer-action)
                       gdb-source-window-list))
          ;; Reuse a window, we use the oldest window and put that to
          ;; the front of the window list.
          (let ((last-win (car (last gdb-source-window-list)))
                (rest (butlast gdb-source-window-list)))
            (set-window-buffer last-win buffer)
            (setq gdb-source-window-list
                  (cons last-win rest))
            last-win)))))