Function: gdb-save-window-configuration

gdb-save-window-configuration is an interactive and byte-compiled function defined in gdb-mi.el.gz.

Signature

(gdb-save-window-configuration FILE)

Documentation

Save current window configuration (layout) to FILE.

You can later restore this configuration from that file by gdb-load-window-configuration.

View in manual

Probably introduced at or before Emacs version 28.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/gdb-mi.el.gz
(defun gdb-save-window-configuration (file)
  "Save current window configuration (layout) to FILE.
You can later restore this configuration from that file by
`gdb-load-window-configuration'."
  (interactive (list (read-file-name
                      "Save window configuration to file: "
                      (or gdb-window-configuration-directory
                          default-directory))))
  ;; We replace the buffer in each window with a placeholder, store
  ;; the buffer type (register, breakpoint, etc) in window parameters,
  ;; and write the window configuration to the file.
  (save-window-excursion
    (let ((placeholder (get-buffer-create " *gdb-placeholder*"))
          (window-persistent-parameters
           (cons '(gdb-buffer-type . writable) window-persistent-parameters)))
      (unwind-protect
          (dolist (win (window-list nil 'no-minibuffer))
            (select-window win)
            (when (gdb-buffer-p (current-buffer))
              (set-window-parameter
               nil 'gdb-buffer-type
               (cond ((gdb-function-buffer-p (current-buffer))
                      ;; 1) If a user arranged the window
                      ;; configuration herself and saves it, windows
                      ;; are probably not dedicated.  2) We use the
                      ;; same dedication flag as in
                      ;; `gdb-display-buffer'.
                      (set-window-dedicated-p nil t)
                      ;; We save this gdb-buffer-type symbol so
                      ;; we can later pass it to `gdb-get-buffer-create';
                      ;; one example: `gdb-registers-buffer'.
                      (or (gdb--buffer-type (current-buffer))
                          (error "Unrecognized gdb buffer mode: %s" major-mode)))
                     ;; Command buffer.
                     ((derived-mode-p 'gud-mode) 'command)
                     ;; Consider everything else as source buffer.
                     (t 'source)))
              (with-window-non-dedicated nil
                (set-window-buffer nil placeholder)
                (set-window-prev-buffers (selected-window) nil)
                (set-window-next-buffers (selected-window) nil))))
        ;; Save the window configuration to FILE.
        (let ((window-config (window-state-get nil t)))
          (with-temp-buffer
            (prin1 window-config (current-buffer))
            (write-file file t)))
        (kill-buffer placeholder)))))