1 ;;; window configuration code
6 "A structure that stores the vital data needed to restore a window."
7 x y w h seperator top bpoint buffer
)
13 (defun current-window-configuration (&optional
(frame (selected-frame)))
14 "Return the vital components of the window configuration of FRAME."
17 (labels ((bk-window (window)
18 (with-slots (x y w h seperator top bpoint buffer
) window
19 (let ((bk (make-window-bk :x x
24 :top
(copy-marker top
)
25 :bpoint
(copy-marker bpoint
)
27 ;; record the current window
28 (when (eq window
(frame-current-window frame
))
32 (cond ((typep tree
'window
)
34 (t (list (dup-tree (first tree
))
35 (dup-tree (second tree
)))))))
36 (make-frame-bk :window-tree
(dup-tree (first (frame-window-tree frame
)))
37 :current-window cw
))))
39 (defun set-window-configuration (configuration &optional
(frame (selected-frame)))
40 "CONFIGURATION must have been generated from FRAME. Otherwise, Bad Things could happen."
43 (labels ((restore-window (bk)
44 (let ((w (make-window :frame frame
47 :cols
(window-bk-w bk
)
48 :rows
(window-bk-h bk
)
49 :buffer
(window-bk-buffer bk
)
50 :top
(window-bk-top bk
)
51 :bpoint
(window-bk-bpoint bk
))))
52 (unless (get-buffer (window-bk-buffer bk
))
53 ;; default to scratch for deleted buffers
54 (let ((scratch (get-buffer-create "*scratch*")))
55 (setf (window-buffer w
) scratch
56 (window-top w
) (make-marker 0 scratch
)
57 (window-bpoint w
) (make-marker 0 scratch
))))
58 (setf (window-seperator w
) (window-bk-seperator bk
))
59 (when (eq bk
(frame-bk-current-window configuration
))
63 (cond ((typep tree
'window-bk
)
64 (restore-window tree
))
65 (t (list (restore-tree (first tree
))
66 (restore-tree (second tree
)))))))
67 (setf (frame-window-tree frame
) (cons (restore-tree (frame-bk-window-tree configuration
))
68 (cdr (frame-window-tree frame
)))
69 (frame-current-window frame
) cw
))))
71 (defmacro save-window-excursion
(&body body
)
72 "Execute body, preserving window sizes and contents.
73 Restore which buffer appears in which window, where display starts,
74 and the value of point and mark for each window.
75 Also restore the choice of selected window.
76 Also restore which buffer is current.
77 **Does not restore the value of point in current buffer."
78 (let ((wc (gensym "WINDOW-CONFIGURATION")))
79 `(let ((,wc
(current-window-configuration)))
83 (set-window-configuration ,wc
)))))
85 (provide :lice-0.1
/wm
)