Mercurial > hg > xemacs-beta
annotate lisp/window-xemacs.el @ 4506:bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
lisp/ChangeLog addition:
2008-08-31 Aidan Kehoe <kehoea@parhasard.net>
* window.el (only-window-p): New.
Check if WINDOW is the only window in some context, normally its
frame.
(one-window-p):
Implemented this in terms of #'only-window-p, calling it on the
selected window.
(window-buffer-height): Uncomment this, make it work.
(count-screen-lines): Support a BUFFER argument.
(fit-window-to-buffer): Uncomment this, correct its implementation
to work with XEmacs.
* help.el (temp-buffer-resize-mode): New. Name taken from GNU,
implementation our own.
* (resize-temp-buffer-window): New. GNU-compatible alias for
#'shrink-window-if-larger-than-buffer.
* dumped-lisp.el (preloaded-file-list): Move easy-mmode before
help, now that the latter uses #'define-minor-mode.
* frame.el: Point to #'temp-buffer-resize-mode in a comment.
Some of this code is from GNU; help.el CVS version 1.327 of
2007-03-21, window.el CVS version 1.122, of 2007-06-24. Both these
are GPLV2 or later.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Sun, 31 Aug 2008 12:26:46 +0200 |
parents | 1d41b9bcf74f |
children | 11d71be1c232 |
rev | line source |
---|---|
428 | 1 ;;; window-xemacs.el --- XEmacs window commands aside from those written in C. |
2 | |
3 ;; Copyright (C) 1985, 1989, 1993-94, 1997 Free Software Foundation, Inc. | |
4 ;; Copyright (C) 1995, 1996 Ben Wing. | |
5 | |
6 ;; Maintainer: XEmacs Development Team | |
7 ;; Keywords: frames, extensions, dumped | |
8 | |
9 ;; This file is part of XEmacs. | |
10 | |
11 ;; XEmacs is free software; you can redistribute it and/or modify it | |
12 ;; under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
15 | |
16 ;; XEmacs is distributed in the hope that it will be useful, but | |
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
19 ;; General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with XEmacs; see the file COPYING. If not, write to the | |
23 ;; Free Software Foundation, 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
25 | |
26 ;;; Synched up with: Not synched. | |
27 | |
28 ;;; Commentary: | |
29 | |
30 ;; This file is dumped with XEmacs. | |
31 | |
32 ;; slb - 5/29/97 | |
33 ;; Split apart from window.el in order to keep that file better in synch | |
34 ;; with Emacs. | |
35 | |
36 ;;; Code: | |
37 | |
38 (defgroup windows nil | |
39 "Windows within a frame." | |
40 :group 'environment) | |
41 | |
42 (defun recenter (&optional n window) | |
43 "Center point in WINDOW and redisplay frame. With N, put point on line N. | |
44 The desired position of point is always relative to the window. | |
45 Just C-u as prefix means put point in the center of the window. | |
46 No N (i.e., it is nil) erases the entire frame and then | |
47 redraws with point in the center of the window. | |
48 If WINDOW is nil, the selected window is used." | |
49 (interactive "_P") | |
50 (center-to-window-line (if (consp n) nil n) window) | |
51 (when (null n) | |
52 (redraw-frame (window-frame window) t))) | |
53 | |
444 | 54 (defun backward-other-window (count &optional which-frames which-devices) |
55 "Select the COUNT'th different window on this frame, going backwards. | |
56 This is just like calling `other-window' with COUNT negated." | |
428 | 57 (interactive "p") |
444 | 58 (other-window (- count) which-frames which-devices)) |
428 | 59 |
60 (defalias 'windows-of-buffer 'get-buffer-window-list) | |
61 | |
62 (defun buffer-in-multiple-windows-p (&optional buffer) | |
63 "Return t if BUFFER is in multiple windows. | |
64 If BUFFER is not specified, the current buffer will be used." | |
65 (setq buffer (or buffer | |
66 (get-buffer buffer) | |
67 (get-file-buffer buffer) | |
68 (current-buffer))) | |
69 (> (length (windows-of-buffer buffer)) 1)) | |
70 | |
71 (defun window-list (&optional frame minibuf window) | |
72 "Return a list of windows on FRAME, beginning with WINDOW. | |
73 FRAME and WINDOW default to the selected ones. | |
74 Optional second arg MINIBUF t means count the minibuffer window | |
75 even if not active. If MINIBUF is neither t nor nil it means | |
76 not to count the minibuffer even if it is active." | |
1261 | 77 (setq frame (or frame (selected-frame)) |
78 window (or window (selected-window frame))) | |
428 | 79 (if (not (eq (window-frame window) frame)) |
80 (error "Window must be on frame.")) | |
81 (let ((current-frame (selected-frame)) | |
82 list) | |
83 (unwind-protect | |
84 (save-window-excursion | |
85 (select-frame frame) | |
86 (walk-windows | |
87 (function (lambda (cur-window) | |
88 (if (not (eq window cur-window)) | |
89 (setq list (cons cur-window list))))) | |
90 minibuf) | |
91 (setq list (cons window list))) | |
92 (select-frame current-frame)))) | |
93 | |
94 ;; We used to have set-window-dedicated-p as an obsolete version | |
95 ;; of set-window-buffer-dedicated, but it really makes more sense | |
96 ;; this way. | |
97 | |
98 (make-obsolete 'set-window-buffer-dedicated 'set-window-dedicated-p) | |
99 (defun set-window-buffer-dedicated (window buffer) | |
100 "Make WINDOW display BUFFER and be dedicated to that buffer. | |
101 Then Emacs will not automatically change which buffer appears in WINDOW. | |
102 If BUFFER is nil, make WINDOW not be dedicated (but don't change which | |
103 buffer appears in it currently)." | |
104 (if (bufferp buffer) | |
105 (set-window-buffer window (get-buffer-create buffer))) | |
106 (set-window-dedicated-p window (not (null buffer)))) | |
1149 | 107 |
108 ;; Window configurations | |
428 | 109 |
3646 | 110 (defcustom window-configuration-includes-position nil |
111 "*Whether restoring window configurations will restore positions too. | |
112 If nil, only the size of windows will be restored. | |
113 | |
114 Note that setting this value to t may have counterintuitive consequences, | |
115 if a window manager employing virtual desktops is in use." | |
116 :type 'boolean | |
117 :group 'windows) | |
118 | |
1149 | 119 (defstruct saved-window |
120 currentp minibufferp minibuffer-scrollp | |
121 buffer mark-marker | |
122 start-marker | |
123 point-marker | |
124 pixel-left pixel-top pixel-right pixel-bottom | |
125 hscroll modeline-hscroll | |
126 dedicatedp | |
4445
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
127 first-hchild first-vchild next-child |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
128 window) |
1149 | 129 |
130 (defstruct window-configuration | |
131 frame | |
2872 | 132 frame-top frame-left |
1149 | 133 frame-pixel-width frame-pixel-height |
134 current-buffer | |
135 minibuffer-pixel-height | |
136 min-width min-height | |
137 saved-root-window) | |
138 | |
4444
715c3ced8fa8
Use `real-split-window', `real-delete-window' in window-config code.
Mike Sperber <sperber@deinprogramm.de>
parents:
4438
diff
changeset
|
139 ; make sure we don't get affected by harmful advice |
715c3ced8fa8
Use `real-split-window', `real-delete-window' in window-config code.
Mike Sperber <sperber@deinprogramm.de>
parents:
4438
diff
changeset
|
140 (fset 'real-split-window (symbol-function 'split-window)) |
715c3ced8fa8
Use `real-split-window', `real-delete-window' in window-config code.
Mike Sperber <sperber@deinprogramm.de>
parents:
4438
diff
changeset
|
141 (fset 'real-delete-window (symbol-function 'delete-window)) |
715c3ced8fa8
Use `real-split-window', `real-delete-window' in window-config code.
Mike Sperber <sperber@deinprogramm.de>
parents:
4438
diff
changeset
|
142 |
1149 | 143 (defun window-configuration-equal (conf-1 conf-2) |
144 "Returns a boolean indicating whether the two given configurations | |
3646 | 145 are identical. |
146 | |
147 Window configurations containing windows with different window | |
148 positions are not identical iff `window-configuration-includes-position' | |
149 is t." | |
1149 | 150 (or (eq conf-1 conf-2) |
151 (and (eq (window-configuration-frame conf-1) | |
152 (window-configuration-frame conf-2)) | |
153 (= (window-configuration-frame-pixel-width conf-1) | |
154 (window-configuration-frame-pixel-width conf-2)) | |
155 (= (window-configuration-frame-pixel-height conf-1) | |
156 (window-configuration-frame-pixel-height conf-2)) | |
3646 | 157 (if window-configuration-includes-position |
158 (and (equal (window-configuration-frame-top conf-1) | |
159 (window-configuration-frame-top conf-2)) | |
160 (equal (window-configuration-frame-left conf-1) | |
161 (window-configuration-frame-left conf-2))) | |
162 t) | |
1149 | 163 (eq (window-configuration-current-buffer conf-1) |
164 (window-configuration-current-buffer conf-2)) | |
165 (saved-window-equal (window-configuration-saved-root-window conf-1) | |
166 (window-configuration-saved-root-window conf-2))))) | |
167 | |
168 (defun saved-window-equal (saved-1 saved-2) | |
169 "Returns a boolean indicating whether the two given saved windows | |
170 are identical." | |
171 (or (eq saved-1 saved-2) | |
172 (and (eq (saved-window-currentp saved-1) | |
173 (saved-window-currentp saved-2)) | |
174 (eq (saved-window-minibuffer-scrollp saved-1) | |
175 (saved-window-minibuffer-scrollp saved-2)) | |
176 (eq (saved-window-buffer saved-1) | |
177 (saved-window-buffer saved-2)) | |
178 (equal (saved-window-mark-marker saved-1) | |
179 (saved-window-mark-marker saved-2)) | |
180 (or (and (saved-window-currentp saved-1) | |
181 (saved-window-currentp saved-2)) | |
182 (equal (saved-window-start-marker saved-1) | |
183 (saved-window-start-marker saved-2))) | |
184 (or (and (saved-window-currentp saved-1) | |
185 (saved-window-currentp saved-2)) | |
186 (equal (saved-window-point-marker saved-1) | |
187 (saved-window-point-marker saved-2))) | |
188 (= (saved-window-pixel-left saved-1) | |
189 (saved-window-pixel-left saved-2)) | |
190 (= (saved-window-pixel-top saved-1) | |
191 (saved-window-pixel-top saved-2)) | |
192 (= (saved-window-pixel-right saved-1) | |
193 (saved-window-pixel-right saved-2)) | |
194 (= (saved-window-pixel-bottom saved-1) | |
195 (saved-window-pixel-bottom saved-2)) | |
196 (= (saved-window-hscroll saved-1) | |
197 (saved-window-hscroll saved-2)) | |
1387 | 198 (equal (saved-window-modeline-hscroll saved-1) |
199 (saved-window-modeline-hscroll saved-2)) | |
1149 | 200 (eq (saved-window-dedicatedp saved-1) |
201 (saved-window-dedicatedp saved-2)) | |
202 (maybe-saved-window-equal (saved-window-first-hchild saved-1) | |
203 (saved-window-first-hchild saved-2)) | |
204 (maybe-saved-window-equal (saved-window-first-vchild saved-1) | |
205 (saved-window-first-vchild saved-2)) | |
206 (maybe-saved-window-equal (saved-window-next-child saved-1) | |
207 (saved-window-next-child saved-2))))) | |
208 | |
209 (defun maybe-saved-window-equal (maybe-saved-1 maybe-saved-2) | |
210 "Returns a boolean indicating whether the two given saved windows | |
211 or NILs are identical." | |
212 (cond | |
213 ((and (not maybe-saved-1) (not maybe-saved-2)) t) | |
214 ((not maybe-saved-1) (not maybe-saved-2)) | |
215 ((not maybe-saved-2) (not maybe-saved-1)) | |
216 (t (saved-window-equal maybe-saved-1 maybe-saved-2)))) | |
217 | |
218 (defun current-window-configuration (&optional frame) | |
219 "Return an object representing the current window configuration of FRAME. | |
220 If FRAME is nil or omitted, use the selected frame. | |
221 This describes the number of windows, their sizes and current buffers, | |
222 and for each window on FRAME the displayed buffer, where display | |
223 starts, and the positions of point and mark. | |
224 An exception is made for point in the current buffer: | |
225 its value is -not- saved." | |
226 (let ((frame (or frame (selected-frame)))) | |
227 ;; The original C code used complicated but still incomplete logic | |
228 ;; to decide if and how to restore the size of the minibuffer. It | |
229 ;; goes something like this: | |
230 ; (let ((real-font-height | |
231 ; (font-height (face-font 'default) frame)) | |
232 ; (minibuffer-height | |
233 ; (if (and (minibuffer-window frame) | |
234 ; (not (frame-minibuffer-only-p frame))) | |
235 ; (window-pixel-height (minibuffer-window frame)) | |
236 ; 0))) | |
237 ; ...) | |
238 | |
239 (make-window-configuration | |
240 :frame frame | |
2885 | 241 :frame-top (frame-property frame 'top) |
242 :frame-left (frame-property frame 'left) | |
1149 | 243 :frame-pixel-width (frame-pixel-width frame) |
244 :frame-pixel-height (frame-pixel-height frame) | |
245 :current-buffer (current-buffer) | |
246 :min-width window-min-width :min-height window-min-height | |
247 :minibuffer-pixel-height (window-pixel-height (minibuffer-window frame)) | |
248 ;; this tries to do what the old code did: | |
249 ; :minibuffer-height (if (zerop (% minibuffer-height real-font-height)) | |
250 ; (- (/ minibuffer-height real-font-height)) ; lines | |
251 ; minibuffer-height) ; pixels | |
252 :saved-root-window (root-window->saved-window (frame-root-window frame))))) | |
253 | |
254 (defun root-window->saved-window (window) | |
255 "Converts a root window into a tree of saved-window structures." | |
256 (let ((buffer (window-buffer window)) | |
257 (edges (window-pixel-edges window))) | |
258 (let ((left (nth 0 edges)) | |
259 (top (nth 1 edges)) | |
260 (right (nth 2 edges)) | |
261 (bottom (nth 3 edges))) | |
262 (let ((saved-window | |
263 (make-saved-window | |
4445
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
264 :window window |
1149 | 265 :currentp (eq window (selected-window (window-frame window))) |
266 :minibufferp (eq window (minibuffer-window (window-frame window))) | |
267 :minibuffer-scrollp (eq window minibuffer-scroll-window) | |
268 :buffer buffer | |
269 :pixel-left left :pixel-top top :pixel-right right :pixel-bottom bottom | |
270 :hscroll (window-hscroll window) | |
271 :modeline-hscroll (modeline-hscroll window) | |
272 :dedicatedp (window-dedicated-p window) | |
273 :first-hchild (if (window-first-hchild window) | |
274 (root-window->saved-window (window-first-hchild window)) | |
275 nil) | |
276 :first-vchild (if (window-first-vchild window) | |
277 (root-window->saved-window (window-first-vchild window)) | |
278 nil) | |
279 :next-child (if (window-next-child window) | |
280 (root-window->saved-window (window-next-child window)) | |
281 nil)))) | |
282 (if buffer | |
283 (progn | |
284 (let ((marker (make-marker))) | |
285 (set-marker marker (window-start window) buffer) | |
286 (setf (saved-window-start-marker saved-window) marker)) | |
4136 | 287 (if (not (eq buffer (current-buffer))) |
288 (let ((marker (make-marker))) | |
289 (set-marker marker (window-point window) buffer) | |
290 (setf (saved-window-point-marker saved-window) marker))) | |
1149 | 291 (setf (saved-window-mark-marker saved-window) |
292 (copy-marker (mark-marker t buffer))))) | |
293 saved-window)))) | |
294 | |
4445
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
295 (defmacro save-window-excursion/mapping (&rest body) |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
296 "Execute body, preserving window sizes and contents. |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
297 Restores which buffer appears in which window, where display starts, |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
298 as well as the current buffer. |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
299 Return alist mapping old windows to new windows. |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
300 This alist maps the originally captured windows to the windows that correspond |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
301 to them in the restored configuration. It does not include entries for |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
302 windows that have not changed identity. |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
303 Does not restore the value of point in current buffer." |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
304 (let ((window-config (gensym 'window-config)) |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
305 (mapping (gensym 'mapping))) |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
306 `(let ((,window-config (current-window-configuration)) |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
307 (,mapping)) |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
308 (unwind-protect |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
309 (progn ,@body) |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
310 (setq ,mapping (set-window-configuration/mapping ,window-config))) |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
311 ,mapping))) |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
312 |
1149 | 313 (defun set-window-configuration (configuration) |
314 "Set the configuration of windows and buffers as specified by CONFIGURATION. | |
315 CONFIGURATION must be a value previously returned | |
316 by `current-window-configuration'." | |
4445
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
317 (set-window-configuration/mapping configuration) |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
318 nil) ; make sure nobody relies on mapping return value |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
319 |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
320 (defun set-window-configuration/mapping (configuration) |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
321 "Set the configuration of windows and buffers as specified by CONFIGURATION. |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
322 CONFIGURATION must be a value previously returned |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
323 by `current-window-configuration'. |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
324 Return alist mapping old windows to new windows. |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
325 This alist maps the originally captured windows to the windows that correspond |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
326 to them in the restored configuration. It does not include entries for |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
327 windows that have not changed identity." |
1149 | 328 (let ((frame (window-configuration-frame configuration))) |
329 (if (and (frame-live-p frame) | |
330 (not (window-configuration-equal configuration | |
331 (current-window-configuration)))) | |
332 (really-set-window-configuration frame configuration)))) | |
333 | |
334 (defun really-set-window-configuration (frame configuration) | |
4445
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
335 "Set the window configuration CONFIGURATION on live frame FRAME. |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
336 Return alist mapping old windows to new windows." |
1149 | 337 ;; avoid potential temporary problems |
338 (setq window-min-width 0) | |
339 (setq window-min-height 0) | |
340 (setq minibuffer-scroll-window nil) | |
341 | |
342 (frame-reduce-to-one-window frame) | |
343 (set-window-configuration-frame-size configuration) | |
2888 | 344 |
345 ; avoid setting these if they're already up-to-date | |
346 ; This also avoids potential inaccuracies in these settings --Mike | |
3646 | 347 (when window-configuration-includes-position |
348 (let ((left (window-configuration-frame-left configuration)) | |
349 (top (window-configuration-frame-top configuration))) | |
350 (if (not (equal left (frame-property frame 'left))) | |
351 (set-frame-property frame 'left left)) | |
352 (if (not (equal top (frame-property frame 'top))) | |
353 (set-frame-property frame 'top top)))) | |
1149 | 354 |
355 ;; these may have changed because of the delete | |
356 (let ((root-window (frame-root-window frame))) | |
357 (enlarge-window-pixels | |
358 (- (window-configuration-minibuffer-pixel-height configuration) | |
359 (window-pixel-height (minibuffer-window frame))) | |
360 nil | |
361 (minibuffer-window frame)) | |
362 | |
363 ;; avoid that `set-window-point' will set the buffer's point for | |
364 ;; the selected window | |
365 (select-window (minibuffer-window frame)) | |
366 | |
4445
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
367 (let ((window-configuration-current-window nil) |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
368 (mapping (list nil))) ; poor man's box |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
369 |
1261 | 370 (declare (special window-configuration-current-window)) |
1149 | 371 (restore-saved-window configuration |
372 root-window | |
373 (window-configuration-saved-root-window configuration) | |
4445
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
374 'vertical |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
375 mapping) |
1149 | 376 (if window-configuration-current-window |
4445
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
377 (select-window window-configuration-current-window)) |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
378 |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
379 (setq window-min-width (window-configuration-min-width configuration)) |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
380 (setq window-min-height (window-configuration-min-height configuration)) |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
381 |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
382 (let ((buffer (window-configuration-current-buffer configuration))) |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
383 (if (buffer-live-p buffer) |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
384 (set-buffer buffer) |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
385 (set-buffer (car (buffer-list))))) |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
386 (car mapping)))) |
1149 | 387 |
388 (defun set-window-configuration-frame-size (configuration) | |
389 "Restore the frame size of a window configuration." | |
390 (set-frame-pixel-size | |
391 (window-configuration-frame configuration) | |
392 (window-configuration-frame-pixel-width configuration) | |
393 (window-configuration-frame-pixel-height configuration))) | |
394 | |
395 (defun frame-reduce-to-one-window (frame) | |
396 "Delete all windows except the minibuffer and one other in FRAME." | |
397 (let* ((root-window (frame-root-window frame)) | |
398 (combination-start (or (window-first-hchild root-window) | |
399 (window-first-vchild root-window)))) | |
400 (if combination-start | |
401 (window-reduce-to-one combination-start)))) | |
402 | |
1230 | 403 ;; Note that simply using `delete-other-windows' causes obscure |
404 ;; breakage. --Mike | |
405 | |
1149 | 406 (defun window-reduce-to-one (window) |
407 "Make sure only one subwindow of WINDOW is left." | |
1230 | 408 (let ((window (window-next-child window))) |
409 (while window | |
410 (if (window-live-p window) | |
411 (let ((next (window-next-child window))) | |
4444
715c3ced8fa8
Use `real-split-window', `real-delete-window' in window-config code.
Mike Sperber <sperber@deinprogramm.de>
parents:
4438
diff
changeset
|
412 (real-delete-window window) |
1230 | 413 (setq window next))))) |
414 (cond | |
415 ((window-first-hchild window) | |
416 (window-reduce-to-one (window-first-hchild window))) | |
417 ((window-first-vchild window) | |
418 (window-reduce-to-one (window-first-vchild window))))) | |
1149 | 419 |
4445
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
420 (defun restore-saved-window (configuration window saved-window direction mapping) |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
421 "Within CONFIGURATION, restore WINDOW to the state of SAVED-WINDOW. |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
422 MAPPING is a one-element list whose element is an old-window-to-new-window |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
423 mapping, which this function will extend." |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
424 (if (not (eq (saved-window-window saved-window) window)) |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
425 (rplaca mapping |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
426 (cons (cons (saved-window-window saved-window) window) |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
427 (car mapping)))) |
4438
2785829fe37c
Fix window-configuration problem.
Mike Sperber <sperber@deinprogramm.de>
parents:
4136
diff
changeset
|
428 (cond |
2785829fe37c
Fix window-configuration problem.
Mike Sperber <sperber@deinprogramm.de>
parents:
4136
diff
changeset
|
429 ((and (saved-window-next-child saved-window) |
2785829fe37c
Fix window-configuration problem.
Mike Sperber <sperber@deinprogramm.de>
parents:
4136
diff
changeset
|
430 (not (saved-window-minibufferp (saved-window-next-child saved-window)))) |
2785829fe37c
Fix window-configuration problem.
Mike Sperber <sperber@deinprogramm.de>
parents:
4136
diff
changeset
|
431 (cond ((eq direction 'vertical) |
4444
715c3ced8fa8
Use `real-split-window', `real-delete-window' in window-config code.
Mike Sperber <sperber@deinprogramm.de>
parents:
4438
diff
changeset
|
432 (real-split-window window nil nil)) |
4438
2785829fe37c
Fix window-configuration problem.
Mike Sperber <sperber@deinprogramm.de>
parents:
4136
diff
changeset
|
433 ((eq direction 'horizontal) |
4444
715c3ced8fa8
Use `real-split-window', `real-delete-window' in window-config code.
Mike Sperber <sperber@deinprogramm.de>
parents:
4438
diff
changeset
|
434 (real-split-window window nil t))) |
4438
2785829fe37c
Fix window-configuration problem.
Mike Sperber <sperber@deinprogramm.de>
parents:
4136
diff
changeset
|
435 (if (not (saved-window-minibufferp saved-window)) |
2785829fe37c
Fix window-configuration problem.
Mike Sperber <sperber@deinprogramm.de>
parents:
4136
diff
changeset
|
436 (restore-saved-window-parameters configuration window saved-window)) |
2785829fe37c
Fix window-configuration problem.
Mike Sperber <sperber@deinprogramm.de>
parents:
4136
diff
changeset
|
437 (restore-saved-window configuration |
2785829fe37c
Fix window-configuration problem.
Mike Sperber <sperber@deinprogramm.de>
parents:
4136
diff
changeset
|
438 (window-next-child window) |
2785829fe37c
Fix window-configuration problem.
Mike Sperber <sperber@deinprogramm.de>
parents:
4136
diff
changeset
|
439 (saved-window-next-child saved-window) |
4445
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
440 direction |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
441 mapping)) |
4438
2785829fe37c
Fix window-configuration problem.
Mike Sperber <sperber@deinprogramm.de>
parents:
4136
diff
changeset
|
442 ((not (saved-window-minibufferp saved-window)) |
2785829fe37c
Fix window-configuration problem.
Mike Sperber <sperber@deinprogramm.de>
parents:
4136
diff
changeset
|
443 (restore-saved-window-parameters configuration window saved-window))) |
1149 | 444 |
1576 | 445 (if (saved-window-first-hchild saved-window) |
446 (restore-saved-window configuration | |
447 window | |
448 (saved-window-first-hchild saved-window) | |
4445
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
449 'horizontal |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
450 mapping)) |
1576 | 451 (if (saved-window-first-vchild saved-window) |
452 (restore-saved-window configuration | |
453 window | |
454 (saved-window-first-vchild saved-window) | |
4445
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
455 'vertical |
1d41b9bcf74f
Add `set-window-configuration/mapping' and `save-window-excursion/mapping'.
Mike Sperber <sperber@deinprogramm.de>
parents:
4444
diff
changeset
|
456 mapping))) |
1149 | 457 |
458 (defun restore-saved-window-parameters (configuration window saved-window) | |
459 "Restore the window parameters stored in SAVED-WINDOW on WINDOW." | |
1261 | 460 (declare (special window-configuration-current-window)) |
1149 | 461 (let ((buffer (saved-window-buffer saved-window))) |
462 (if (and buffer (buffer-live-p buffer)) | |
463 (progn | |
464 (set-window-buffer window | |
465 (saved-window-buffer saved-window)) | |
466 (set-window-start window | |
1161 | 467 (marker-position (saved-window-start-marker saved-window)) |
468 t) | |
4136 | 469 (if (markerp (saved-window-point-marker saved-window)) |
470 (set-window-point window | |
471 (marker-position (saved-window-point-marker saved-window)))) | |
1149 | 472 (set-marker (mark-marker t buffer) |
473 (marker-position (saved-window-mark-marker saved-window)) | |
474 buffer) | |
475 (if (not (eq buffer (window-configuration-current-buffer configuration))) | |
476 (goto-char (window-point window) buffer))))) | |
477 | |
478 (if (and (not (saved-window-first-hchild saved-window)) | |
479 (not (saved-window-first-vchild saved-window))) | |
480 ;; only set size for non-container windows | |
481 (progn | |
482 ;; If this is the root window, it may be the only window. | |
483 ;; Because of mismatches between actual and reported frame | |
484 ;; size, it may not let us actually set the size of the root | |
485 ;; window to what we want. --Mike | |
486 (if (not (eq window (frame-root-window (window-frame window)))) | |
487 (progn | |
488 (enlarge-window-pixels (- (saved-window-pixel-width saved-window) | |
489 (window-pixel-width window)) | |
490 t | |
491 window) | |
492 (enlarge-window-pixels (- (saved-window-pixel-height saved-window) | |
493 (window-pixel-height window)) | |
494 nil | |
495 window))) | |
496 (set-window-hscroll window (saved-window-hscroll saved-window)) | |
497 (set-modeline-hscroll window | |
498 (saved-window-modeline-hscroll saved-window)) | |
499 (set-window-dedicated-p window (saved-window-dedicatedp saved-window)))) | |
500 | |
501 (if (saved-window-currentp saved-window) | |
502 (setq window-configuration-current-window window)) | |
503 (if (saved-window-minibuffer-scrollp saved-window) | |
504 (setq minibuffer-scroll-window window))) | |
505 | |
506 (defun saved-window-pixel-width (saved-window) | |
507 "Compute the pixel width of SAVED-WINDOW." | |
508 (- (saved-window-pixel-right saved-window) | |
509 (saved-window-pixel-left saved-window))) | |
510 | |
511 (defun saved-window-pixel-height (saved-window) | |
512 "Compute the pixel height of SAVED-WINDOW." | |
513 (- (saved-window-pixel-bottom saved-window) | |
514 (saved-window-pixel-top saved-window))) | |
428 | 515 |
516 ;; The window-config stack is stored as a list in frame property | |
517 ;; 'window-config-stack, with the most recent element at the front. | |
518 ;; When you pop off an element, the popped off element gets put at the | |
519 ;; front of frame property 'window-config-unpop-stack, so you can | |
520 ;; retrieve it using unpop-window-configuration. | |
521 | |
522 (defcustom window-config-stack-max 16 | |
523 "*Maximum size of window configuration stack. | |
524 Start discarding off end if it gets this big." | |
525 :type 'integer | |
526 :group 'windows) | |
527 | |
528 (defun window-config-stack (&optional frame) | |
529 (or frame (setq frame (selected-frame))) | |
530 (let ((stack (frame-property frame 'window-config-stack))) | |
531 (if stack | |
532 (set-undoable-stack-max stack window-config-stack-max) | |
533 (progn | |
534 (setq stack (make-undoable-stack window-config-stack-max)) | |
535 (set-frame-property frame 'window-config-stack stack))) | |
536 stack)) | |
537 | |
538 (defun push-window-configuration (&optional config) | |
539 "Push the current window configuration onto the window-config stack. | |
540 If CONFIG is specified, push it instead of the current window configuration. | |
541 Each frame has its own window-config stack." | |
542 (interactive) | |
543 (let ((wc (or config (current-window-configuration))) | |
544 (stack (window-config-stack))) | |
545 (if (or (= 0 (undoable-stack-a-length stack)) | |
546 (not (equal (undoable-stack-a-top stack) wc))) | |
547 (undoable-stack-push stack wc)))) | |
548 | |
549 (defun pop-window-configuration () | |
550 "Pop the top window configuration off the window-config stack and set it. | |
551 Before setting the new window configuration, the current window configuration | |
552 is pushed onto the \"unpop\" stack. | |
553 `unpop-window-configuration' undoes what this function does. | |
554 Each frame has its own window-config and \"unpop\" stack." | |
555 (interactive) | |
556 (let ((stack (window-config-stack)) | |
557 (wc (current-window-configuration)) | |
558 popped) | |
559 (condition-case nil | |
560 (progn | |
561 (setq popped (undoable-stack-pop stack)) | |
562 (while (equal popped wc) | |
563 (setq popped (undoable-stack-pop stack))) | |
564 (undoable-stack-push stack wc) | |
565 (undoable-stack-undo stack) | |
566 (set-window-configuration popped) | |
567 popped) | |
568 (trunc-stack-bottom | |
569 (error "Bottom of window config stack"))))) | |
570 | |
571 (defun unpop-window-configuration () | |
572 "Undo the effect of the most recent `pop-window-configuration'. | |
573 This does exactly the inverse of what `pop-window-configuration' does: | |
574 i.e. it pops a window configuration off of the \"unpop\" stack and | |
575 pushes the current window configuration onto the window-config stack. | |
576 Each frame has its own window-config and \"unpop\" stack." | |
577 (interactive) | |
578 (let ((stack (window-config-stack)) | |
579 (wc (current-window-configuration)) | |
580 popped) | |
581 (condition-case nil | |
582 (progn | |
583 (setq popped | |
584 (progn | |
585 (undoable-stack-redo stack) | |
586 (undoable-stack-pop stack))) | |
587 (while (equal popped wc) | |
588 (setq popped | |
589 (progn | |
590 (undoable-stack-redo stack) | |
591 (undoable-stack-pop stack)))) | |
592 (undoable-stack-push stack wc) | |
593 (set-window-configuration popped) | |
594 popped) | |
595 (trunc-stack-bottom | |
596 (error "Top of window config stack"))))) | |
597 | |
598 | |
599 ;;;;;;;;;;;;; display-buffer, moved here from C. Hallelujah. | |
600 | |
442 | 601 (make-variable-buffer-local '__buffer-dedicated-frame) |
602 | |
603 (defun buffer-dedicated-frame (&optional buffer) | |
604 "Return the frame dedicated to this BUFFER, or nil if there is none. | |
605 No argument or nil as argument means use current buffer as BUFFER." | |
606 (let ((buffer (decode-buffer buffer))) | |
607 (let ((frame (symbol-value-in-buffer '__buffer-dedicated-frame buffer))) | |
608 ;; XEmacs addition: if the frame is dead, silently make it go away. | |
609 (when (and (framep frame) (not (frame-live-p frame))) | |
610 (with-current-buffer buffer | |
611 (setq __buffer-dedicated-frame nil)) | |
612 (setq frame nil)) | |
613 frame))) | |
614 | |
615 (defun set-buffer-dedicated-frame (buffer frame) | |
616 "For this BUFFER, set the FRAME dedicated to it. | |
617 FRAME must be a frame or nil." | |
618 (let ((buffer (decode-buffer buffer))) | |
619 (and frame | |
620 (check-argument-type #'frame-live-p frame)) | |
621 (with-current-buffer buffer | |
622 (setq __buffer-dedicated-frame frame)))) | |
623 | |
428 | 624 (defvar display-buffer-function nil |
625 "If non-nil, function to call to handle `display-buffer'. | |
903 | 626 It will receive four args: the same as those to `display-buffer'.") |
428 | 627 |
628 (defvar pre-display-buffer-function nil | |
629 "If non-nil, function that will be called from `display-buffer' | |
903 | 630 as the first action. It will receive four args: the same as those |
428 | 631 to `display-buffer'. |
632 This function may be used to select an appropriate frame for the buffer, | |
633 for example. See also the variable `display-buffer-function', which may | |
634 be used to completely replace the `display-buffer' function. | |
635 If the return value of this function is non-nil, it should be a frame, | |
636 and that frame will be used to display the buffer.") | |
637 | |
638 (defcustom pop-up-frames nil | |
639 "*Non-nil means `display-buffer' should make a separate frame." | |
640 :type 'boolean | |
641 :group 'frames) | |
642 | |
643 (defvar pop-up-frame-function nil | |
644 "Function to call to handle automatic new frame creation. | |
645 It is called with no arguments and should return a newly created frame. | |
646 | |
647 A typical value might be `(lambda () (new-frame pop-up-frame-alist))' | |
648 where `pop-up-frame-alist' would hold the default frame parameters.") | |
649 | |
650 (defcustom special-display-buffer-names nil | |
651 "*List of buffer names that should have their own special frames. | |
652 Displaying a buffer whose name is in this list makes a special frame for it | |
653 using `special-display-function'. | |
654 | |
655 An element of the list can be a cons cell instead of just a string. | |
656 Then the car should be a buffer name, and the cdr specifies frame | |
657 parameters for creating the frame for that buffer. | |
658 More precisely, the cdr is passed as the second argument to | |
659 the function found in `special-display-function', when making that frame. | |
660 See also `special-display-regexps'." | |
661 :type '(repeat (choice :value "" | |
662 (string :tag "Name") | |
663 (cons :menu-tag "Properties" | |
664 :value ("" . nil) | |
665 (string :tag "Name") | |
666 (repeat :tag "Properties" | |
667 (group :inline t | |
668 (symbol :tag "Property") | |
669 (sexp :tag "Value")))))) | |
670 :group 'frames) | |
671 | |
672 (defcustom special-display-regexps nil | |
673 "*List of regexps saying which buffers should have their own special frames. | |
674 If a buffer name matches one of these regexps, it gets its own frame. | |
675 Displaying a buffer whose name is in this list makes a special frame for it | |
676 using `special-display-function'. | |
677 | |
678 An element of the list can be a cons cell instead of just a string. | |
679 Then the car should be the regexp, and the cdr specifies frame | |
680 parameters for creating the frame for buffers that match. | |
681 More precisely, the cdr is passed as the second argument to | |
682 the function found in `special-display-function', when making that frame. | |
683 See also `special-display-buffer-names'." | |
684 :type '(repeat (choice :value "" | |
685 regexp | |
686 (cons :menu-tag "Properties" | |
687 :value ("" . nil) | |
688 regexp | |
689 (repeat :tag "Properties" | |
690 (group :inline t | |
691 (symbol :tag "Property") | |
692 (sexp :tag "Value")))))) | |
693 :group 'frames) | |
694 | |
695 (defvar special-display-function nil | |
696 "Function to call to make a new frame for a special buffer. | |
697 It is called with two arguments, the buffer and optional buffer specific | |
698 data, and should return a window displaying that buffer. | |
699 The default value makes a separate frame for the buffer, | |
700 using `special-display-frame-alist' to specify the frame parameters. | |
701 | |
702 A buffer is special if its is listed in `special-display-buffer-names' | |
703 or matches a regexp in `special-display-regexps'.") | |
704 | |
705 (defcustom same-window-buffer-names nil | |
706 "*List of buffer names that should appear in the selected window. | |
707 Displaying one of these buffers using `display-buffer' or `pop-to-buffer' | |
708 switches to it in the selected window, rather than making it appear | |
709 in some other window. | |
710 | |
711 An element of the list can be a cons cell instead of just a string. | |
712 Then the car must be a string, which specifies the buffer name. | |
713 This is for compatibility with `special-display-buffer-names'; | |
714 the cdr of the cons cell is ignored. | |
715 | |
716 See also `same-window-regexps'." | |
717 :type '(repeat (string :tag "Name")) | |
718 :group 'windows) | |
719 | |
720 (defcustom same-window-regexps nil | |
721 "*List of regexps saying which buffers should appear in the selected window. | |
722 If a buffer name matches one of these regexps, then displaying it | |
723 using `display-buffer' or `pop-to-buffer' switches to it | |
724 in the selected window, rather than making it appear in some other window. | |
725 | |
726 An element of the list can be a cons cell instead of just a string. | |
727 Then the car must be a string, which specifies the buffer name. | |
728 This is for compatibility with `special-display-buffer-names'; | |
729 the cdr of the cons cell is ignored. | |
730 | |
731 See also `same-window-buffer-names'." | |
732 :type '(repeat regexp) | |
733 :group 'windows) | |
734 | |
735 (defcustom pop-up-windows t | |
736 "*Non-nil means display-buffer should make new windows." | |
737 :type 'boolean | |
738 :group 'windows) | |
739 | |
740 (defcustom split-height-threshold 500 | |
741 "*display-buffer would prefer to split the largest window if this large. | |
742 If there is only one window, it is split regardless of this value." | |
743 :type 'integer | |
744 :group 'windows) | |
745 | |
746 (defcustom split-width-threshold 500 | |
747 "*display-buffer would prefer to split the largest window if this large. | |
748 If there is only one window, it is split regardless of this value." | |
749 :type 'integer | |
750 :group 'windows) | |
751 | |
752 ;; Deiconify the frame containing the window WINDOW, then return WINDOW. | |
753 | |
754 (defun display-buffer-1 (window) | |
755 (if (frame-iconified-p (window-frame window)) | |
756 (make-frame-visible (window-frame window))) | |
757 window) | |
758 | |
759 ;; Can you believe that all of this crap was formerly in C? | |
760 ;; Praise Jesus that it's not there any more. | |
761 | |
903 | 762 (defun display-buffer (buffer &optional not-this-window-p override-frame |
763 shrink-to-fit) | |
428 | 764 "Make BUFFER appear in some window on the current frame, but don't select it. |
765 BUFFER can be a buffer or a buffer name. | |
766 If BUFFER is shown already in some window in the current frame, | |
767 just uses that one, unless the window is the selected window and | |
768 NOT-THIS-WINDOW-P is non-nil (interactively, with prefix arg). | |
769 | |
770 If BUFFER has a dedicated frame, display on that frame instead of | |
771 the current frame, unless OVERRIDE-FRAME is non-nil. | |
772 | |
773 If OVERRIDE-FRAME is non-nil, display on that frame instead of | |
774 the current frame (or the dedicated frame). | |
775 | |
903 | 776 If SHRINK-TO-FIT is non-nil and splitting the window is appropriate, give |
777 the new buffer less than half the space if it is small enough to fit. | |
778 | |
428 | 779 If `pop-up-windows' is non-nil, always use the |
780 current frame and create a new window regardless of whether the | |
781 buffer has a dedicated frame, and regardless of whether | |
782 OVERRIDE-FRAME was specified. | |
783 | |
784 If `pop-up-frames' is non-nil, make a new frame if no window shows BUFFER. | |
785 | |
2590 | 786 If the buffer name is a member of the `same-window-buffer-names' list, |
787 or matches one of the `same-window-regexps' expressions, display the | |
788 buffer in the currently selected window. | |
789 | |
428 | 790 Returns the window displaying BUFFER." |
791 (interactive "BDisplay buffer:\nP") | |
792 | |
793 (let ((wconfig (current-window-configuration)) | |
794 (result | |
795 ;; We just simulate a `return' in C. This function is way ugly | |
796 ;; and does `returns' all over the place and there's no sense | |
797 ;; in trying to rewrite it to be more Lispy. | |
798 (catch 'done | |
1669 | 799 (let (window old-frame target-frame explicit-frame shrink-it) |
428 | 800 (setq old-frame (or (last-nonminibuf-frame) (selected-frame))) |
801 (setq buffer (get-buffer buffer)) | |
802 (check-argument-type 'bufferp buffer) | |
803 | |
804 (setq explicit-frame | |
805 (if pre-display-buffer-function | |
806 (funcall pre-display-buffer-function buffer | |
807 not-this-window-p | |
903 | 808 override-frame |
809 shrink-to-fit))) | |
428 | 810 |
811 ;; Give the user the ability to completely reimplement | |
812 ;; this function via the `display-buffer-function'. | |
813 (if display-buffer-function | |
814 (throw 'done | |
815 (funcall display-buffer-function buffer | |
816 not-this-window-p | |
903 | 817 override-frame |
818 shrink-to-fit))) | |
428 | 819 |
820 ;; If the buffer has a dedicated frame, that takes | |
821 ;; precedence over the current frame, and over what the | |
822 ;; pre-display-buffer-function did. | |
823 (let ((dedi (buffer-dedicated-frame buffer))) | |
824 (if (frame-live-p dedi) (setq explicit-frame dedi))) | |
825 | |
826 ;; if override-frame is supplied, that takes precedence over | |
827 ;; everything. This is gonna look bad if the | |
828 ;; pre-display-buffer-function raised some other frame | |
829 ;; already. | |
830 (if override-frame | |
831 (progn | |
832 (check-argument-type 'frame-live-p override-frame) | |
833 (setq explicit-frame override-frame))) | |
834 | |
835 (setq target-frame | |
836 (or explicit-frame | |
837 (last-nonminibuf-frame) | |
838 (selected-frame))) | |
839 | |
840 ;; If we have switched frames, then set not-this-window-p | |
841 ;; to false. Switching frames means that selected-window | |
842 ;; is no longer the same as it was on entry -- it's the | |
843 ;; selected-window of target_frame instead of old_frame, | |
844 ;; so it's a fine candidate for display. | |
845 (if (not (eq old-frame target-frame)) | |
846 (setq not-this-window-p nil)) | |
847 | |
848 ;; if it's in the selected window, and that's ok, then we're done. | |
849 (if (and (not not-this-window-p) | |
850 (eq buffer (window-buffer (selected-window)))) | |
851 (throw 'done (display-buffer-1 (selected-window)))) | |
852 | |
853 ;; See if the user has specified this buffer should appear | |
854 ;; in the selected window. | |
855 | |
856 (if not-this-window-p | |
857 nil | |
858 | |
859 (if (or (member (buffer-name buffer) same-window-buffer-names) | |
860 (assoc (buffer-name buffer) same-window-buffer-names)) | |
861 (progn | |
862 (switch-to-buffer buffer) | |
863 (throw 'done (display-buffer-1 (selected-window))))) | |
864 | |
865 (let ((tem same-window-regexps)) | |
866 (while tem | |
867 (let ((car (car tem))) | |
868 (if (or | |
869 (and (stringp car) | |
870 (string-match car (buffer-name buffer))) | |
871 (and (consp car) (stringp (car car)) | |
872 (string-match (car car) (buffer-name buffer)))) | |
873 (progn | |
874 (switch-to-buffer buffer) | |
875 (throw 'done (display-buffer-1 | |
876 (selected-window)))))) | |
877 (setq tem (cdr tem))))) | |
878 | |
879 ;; If pop-up-frames, look for a window showing BUFFER on | |
880 ;; any visible or iconified frame. Otherwise search only | |
881 ;; the current frame. | |
882 (if (and (not explicit-frame) | |
883 (or pop-up-frames (not (last-nonminibuf-frame)))) | |
884 (setq target-frame 0)) | |
885 | |
886 ;; Otherwise, find some window that it's already in, and | |
887 ;; return that, unless that window is the selected window | |
888 ;; and that isn't ok. What a contorted mess! | |
889 (setq window (or (if (not explicit-frame) | |
890 ;; search the selected frame | |
891 ;; first if the user didn't | |
892 ;; specify an explicit frame. | |
893 (get-buffer-window buffer nil)) | |
894 (get-buffer-window buffer target-frame))) | |
895 (if (and window | |
896 (or (not not-this-window-p) | |
897 (not (eq window (selected-window))))) | |
898 (throw 'done (display-buffer-1 window))) | |
899 | |
900 ;; Certain buffer names get special handling. | |
901 (if special-display-function | |
902 (progn | |
903 (if (member (buffer-name buffer) | |
904 special-display-buffer-names) | |
905 (throw 'done (funcall special-display-function buffer))) | |
906 | |
907 (let ((tem (assoc (buffer-name buffer) | |
908 special-display-buffer-names))) | |
909 (if tem | |
910 (throw 'done (funcall special-display-function | |
911 buffer (cdr tem))))) | |
912 | |
913 (let ((tem special-display-regexps)) | |
914 (while tem | |
915 (let ((car (car tem))) | |
916 (if (and (stringp car) | |
917 (string-match car (buffer-name buffer))) | |
918 (throw 'done | |
919 (funcall special-display-function buffer))) | |
920 (if (and (consp car) | |
921 (stringp (car car)) | |
922 (string-match (car car) | |
923 (buffer-name buffer))) | |
924 (throw 'done (funcall | |
925 special-display-function buffer | |
926 (cdr car))))) | |
927 (setq tem (cdr tem)))))) | |
928 | |
929 ;; If there are no frames open that have more than a minibuffer, | |
930 ;; we need to create a new frame. | |
931 (if (or pop-up-frames | |
932 (null (last-nonminibuf-frame))) | |
933 (progn | |
934 (setq window (frame-selected-window | |
935 (funcall pop-up-frame-function))) | |
936 (set-window-buffer window buffer) | |
937 (throw 'done (display-buffer-1 window)))) | |
938 | |
939 ;; Otherwise, make it be in some window, splitting if | |
940 ;; appropriate/possible. Do not split a window if we are | |
941 ;; displaying the buffer in a different frame than that which | |
942 ;; was current when we were called. (It is already in a | |
943 ;; different window by virtue of being in another frame.) | |
944 (if (or (and pop-up-windows (eq target-frame old-frame)) | |
945 (eq 'only (frame-property (selected-frame) 'minibuffer)) | |
946 ;; If the current frame is a special display frame, | |
947 ;; don't try to reuse its windows. | |
948 (window-dedicated-p (frame-root-window (selected-frame)))) | |
949 (progn | |
950 (if (eq 'only (frame-property (selected-frame) 'minibuffer)) | |
951 (setq target-frame (last-nonminibuf-frame))) | |
952 | |
953 ;; Don't try to create a window if would get an error with | |
954 ;; height. | |
955 (if (< split-height-threshold (* 2 window-min-height)) | |
956 (setq split-height-threshold (* 2 window-min-height))) | |
957 | |
958 ;; Same with width. | |
959 (if (< split-width-threshold (* 2 window-min-width)) | |
960 (setq split-width-threshold (* 2 window-min-width))) | |
961 | |
962 ;; If the frame we would try to split cannot be split, | |
963 ;; try other frames. | |
964 (if (frame-property (if (null target-frame) | |
965 (selected-frame) | |
966 (last-nonminibuf-frame)) | |
967 'unsplittable) | |
968 (setq window | |
969 ;; Try visible frames first. | |
970 (or (get-largest-window 'visible) | |
971 ;; If that didn't work, try iconified frames. | |
972 (get-largest-window 0) | |
973 (get-largest-window t))) | |
974 (setq window (get-largest-window target-frame))) | |
975 | |
976 ;; If we got a tall enough full-width window that | |
977 ;; can be split, split it. | |
978 (if (and window | |
979 (not (frame-property (window-frame window) | |
980 'unsplittable)) | |
981 (>= (window-height window) split-height-threshold) | |
982 (or (>= (window-width window) | |
983 split-width-threshold) | |
984 (and (window-leftmost-p window) | |
985 (window-rightmost-p window)))) | |
986 (setq window (split-window window)) | |
1669 | 987 (let (upper other) |
428 | 988 (setq window (get-lru-window target-frame)) |
989 ;; If the LRU window is selected, and big enough, | |
990 ;; and can be split, split it. | |
991 (if (and window | |
992 (not (frame-property (window-frame window) | |
993 'unsplittable)) | |
994 (or (eq window (selected-window)) | |
995 (not (window-parent window))) | |
996 (>= (window-height window) | |
997 (* 2 window-min-height))) | |
998 (setq window (split-window window))) | |
999 ;; If get-lru-window returned nil, try other approaches. | |
1000 ;; Try visible frames first. | |
1001 (or window | |
1002 (setq window (or (get-largest-window 'visible) | |
1003 ;; If that didn't work, try | |
1004 ;; iconified frames. | |
1005 (get-largest-window 0) | |
1006 ;; Try invisible frames. | |
1007 (get-largest-window t) | |
1008 ;; As a last resort, make | |
1009 ;; a new frame. | |
1010 (frame-selected-window | |
1011 (funcall | |
1012 pop-up-frame-function))))) | |
1013 ;; If window appears above or below another, | |
1014 ;; even out their heights. | |
1015 (if (window-previous-child window) | |
1016 (setq other (window-previous-child window) | |
1017 upper other)) | |
1018 (if (window-next-child window) | |
1019 (setq other (window-next-child window) | |
1020 upper window)) | |
1021 ;; Check that OTHER and WINDOW are vertically arrayed. | |
1022 (if (and other | |
1023 (not (= (nth 1 (window-pixel-edges other)) | |
1024 (nth 1 (window-pixel-edges window)))) | |
1025 (> (window-pixel-height other) | |
1026 (window-pixel-height window))) | |
1027 (enlarge-window (- (/ (+ (window-height other) | |
1028 (window-height window)) | |
1029 2) | |
1030 (window-height upper)) | |
903 | 1031 nil upper)) |
1669 | 1032 ;; Klaus Berndl <klaus.berndl@sdm.de>: Only in |
1033 ;; this situation we shrink-to-fit but we can do | |
1034 ;; this first after we have displayed buffer in | |
1035 ;; window (s.b. (set-window-buffer window buffer)) | |
1036 (setq shrink-it shrink-to-fit)))) | |
428 | 1037 |
1038 (setq window (get-lru-window target-frame))) | |
1039 | |
1040 ;; Bring the window's previous buffer to the top of the MRU chain. | |
1041 (if (window-buffer window) | |
1042 (save-excursion | |
1043 (save-selected-window | |
1044 (select-window window) | |
1045 (record-buffer (window-buffer window))))) | |
1046 | |
1047 (set-window-buffer window buffer) | |
1048 | |
1669 | 1049 ;; Now window's previous buffer has been brought to the top |
1050 ;; of the MRU chain and window displays buffer - now we can | |
1051 ;; shrink-to-fit if necessary | |
1052 (if shrink-it | |
1053 (shrink-window-if-larger-than-buffer window)) | |
1054 | |
428 | 1055 (display-buffer-1 window))))) |
1056 (or (equal wconfig (current-window-configuration)) | |
1057 (push-window-configuration wconfig)) | |
1058 result)) | |
1059 | |
1060 ;;; window-xemacs.el ends here |