annotate lisp/prim/window.el @ 7:c153ca296910

Added tag r19-15b4 for changeset 27bc7f280385
author cvs
date Mon, 13 Aug 2007 08:47:16 +0200
parents 376386a54a3c
children 0293115a14e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; window.el --- XEmacs window commands aside from those written in C.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;; Keywords: extensions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Copyright (C) 1985, 1989, 1993, 1994 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Copyright (C) 1995, 1996 Ben Wing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; along with XEmacs; see the file COPYING. If not, write to the Free
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;; Synched up with: FSF 19.30.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;;; Window tree functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 (defun one-window-p (&optional nomini all-frames device)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 "Returns non-nil if the selected window is the only window (in its frame).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 Optional arg NOMINI non-nil means don't count the minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 even if it is active.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 The optional arg ALL-FRAMES t means count windows on all frames.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 If it is `visible', count windows on all visible frames.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ALL-FRAMES nil or omitted means count only the selected frame,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 plus the minibuffer it uses (which may be on another frame).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ALL-FRAMES = 0 means count windows on all visible and iconified frames.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 If ALL-FRAMES is any other value, count only the selected frame.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 If optional third argument DEVICE is nil or omitted, count frames
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 on all devices.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 If a device, count frames only on that device.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 If a device type, count frames only on devices of that type.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 Otherwise, count frames only on the selected device."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (let ((base-window (selected-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (if (and nomini (eq base-window (minibuffer-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (setq base-window (next-window base-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (eq base-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (next-window base-window (if nomini 'arg) all-frames device))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (defun walk-windows (proc &optional minibuf all-frames device)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 "Cycle through all visible windows, calling PROC for each one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 PROC is called with a window as argument.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 Optional second arg MINIBUF t means count the minibuffer window even
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 if not active. MINIBUF nil or omitted means count the minibuffer iff
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 it is active. MINIBUF neither t nor nil means not to count the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 minibuffer even if it is active.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 Several frames may share a single minibuffer; if the minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 counts, all windows on all frames that share that minibuffer count
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 too. Therefore, when a separate minibuffer frame is active,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 `walk-windows' includes the windows in the frame from which you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 entered the minibuffer, as well as the minibuffer window. But if the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 minibuffer does not count, only windows from WINDOW's frame count.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ALL-FRAMES is the optional third argument.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ALL-FRAMES nil or omitted means cycle within the frames as specified above.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ALL-FRAMES = `visible' means include windows on all visible frames.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ALL-FRAMES = 0 means include windows on all visible and iconified frames.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ALL-FRAMES = t means include windows on all frames including invisible frames.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 Anything else means restrict to WINDOW's frame.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 If optional fourth argument DEVICE is nil or omitted, include frames
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 on all devices.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 If a device, include frames only on that device.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 If a device type, include frames only on devices of that type.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 Otherwise, include frames only on the selected device."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ;; If we start from the minibuffer window, don't fail to come back to it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (if (window-minibuffer-p (selected-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (setq minibuf t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;; Note that, like next-window & previous-window, this behaves a little
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 ;; strangely if the selected window is on an invisible frame: it hits
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;; some of the windows on that frame, and all windows on visible frames.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (let* ((walk-windows-start (selected-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (walk-windows-current walk-windows-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (while (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (setq walk-windows-current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (next-window walk-windows-current minibuf all-frames
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 device))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (funcall proc walk-windows-current)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (not (eq walk-windows-current walk-windows-start))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 ;; The old XEmacs definition of the above clause. It's more correct in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ;; that it will never hit a window that's already been hit even if you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 ;; do something odd like `delete-other-windows', but has the problem
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 ;; that it conses. (This may be called repeatedly, from lazy-lock
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 ;; for example.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 ; (let* ((walk-windows-history nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 ; (walk-windows-current (selected-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 ; (while (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 ; (setq walk-windows-current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 ; (next-window walk-windows-current minibuf all-frames
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 ; device))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 ; (not (memq walk-windows-current walk-windows-history)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 ; (setq walk-windows-history (cons walk-windows-current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 ; walk-windows-history))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 ; (funcall proc walk-windows-current))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (defun minibuffer-window-active-p (window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 "Return t if WINDOW (a minibuffer window) is now active."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (eq window (active-minibuffer-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (defmacro save-selected-window (&rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 "Execute BODY, then select the window that was selected before BODY."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (list 'let
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 '((save-selected-window-window (selected-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (list 'unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (cons 'progn body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (list 'and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (list 'window-live-p 'save-selected-window-window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (list 'select-window 'save-selected-window-window)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (defun count-windows (&optional minibuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 "Returns the number of visible windows.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 Optional arg NO-MINI non-nil means don't count the minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 even if it is active."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (let ((count 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (walk-windows (function (lambda (w)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (setq count (+ count 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 minibuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (defun balance-windows ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 "Makes all visible windows the same height (approximately)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (let ((count -1) levels newsizes size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 ;FSFmacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 ;;; Don't count the lines that are above the uppermost windows.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 ;;; (These are the menu bar lines, if any.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 ;(mbl (nth 1 (window-edges (frame-first-window (selected-frame))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 ;; Find all the different vpos's at which windows start,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 ;; then count them. But ignore levels that differ by only 1.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (save-window-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (let (tops (prev-top -2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (walk-windows (function (lambda (w)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (setq tops (cons (nth 1 (window-pixel-edges w))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 tops))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 'nomini)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (setq tops (sort tops '<))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (while tops
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (if (> (car tops) (1+ prev-top))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (setq prev-top (car tops)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 count (1+ count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (setq levels (cons (cons (car tops) count) levels))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (setq tops (cdr tops)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (setq count (1+ count))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 ;; Subdivide the frame into that many vertical levels.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 ;FSFmacs (setq size (/ (- (frame-height) mbl) count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (setq size (/ (window-pixel-height (frame-root-window)) count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (walk-windows (function (lambda (w)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (select-window w)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (let ((newtop (cdr (assq (nth 1 (window-pixel-edges))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 levels)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (newbot (or (cdr (assq
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (+ (window-pixel-height)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (nth 1 (window-pixel-edges)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 levels))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (setq newsizes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (cons (cons w (* size (- newbot newtop)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 newsizes)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 'nomini)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (walk-windows (function (lambda (w)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (select-window w)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (let ((newsize (cdr (assq w newsizes))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (enlarge-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (/ (- newsize (window-pixel-height))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (face-height 'default))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 'nomini)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 ;;; I think this should be the default; I think people will prefer it--rms.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (defvar split-window-keep-point t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 "*If non-nil, split windows keeps the original point in both children.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 This is often more convenient for editing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 If nil, adjust point in each of the two windows to minimize redisplay.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 This is convenient on slow terminals, but point can move strangely.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (defun split-window-vertically (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 "Split current window into two windows, one above the other.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 The uppermost window gets ARG lines and the other gets the rest.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 Negative arg means select the size of the lowermost window instead.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 With no argument, split equally or close to it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 Both windows display the same buffer now current.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 If the variable split-window-keep-point is non-nil, both new windows
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 will get the same value of point as the current window. This is often
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 more convenient for editing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 Otherwise, we chose window starts so as to minimize the amount of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 redisplay; this is convenient on slow terminals. The new selected
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 window is the one that the current value of point appears in. The
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 value of point can change if the text around point is hidden by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 new modeline.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 Programs should probably use split-window instead of this."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (let ((old-w (selected-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (old-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (size (and arg (prefix-numeric-value arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 new-w bottom)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (and size (< size 0) (setq size (+ (window-height) size)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (setq new-w (split-window nil size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (or split-window-keep-point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (set-buffer (window-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (goto-char (window-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (vertical-motion (window-height))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (set-window-start new-w (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (if (> (point) (window-point new-w))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (set-window-point new-w (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (vertical-motion -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (setq bottom (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (if (<= bottom (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (set-window-point old-w (1- bottom)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (if (< (window-start new-w) old-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (set-window-point new-w old-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (select-window new-w)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 new-w))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (defun split-window-horizontally (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 "Split current window into two windows side by side.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 This window becomes the leftmost of the two, and gets ARG columns.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 Negative arg means select the size of the rightmost window instead.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 No arg means split equally."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (let ((size (and arg (prefix-numeric-value arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (and size (< size 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (setq size (+ (window-width) size)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (split-window nil size t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (defun enlarge-window-horizontally (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 "Make current window ARG columns wider."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (enlarge-window arg t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (defun shrink-window-horizontally (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 "Make current window ARG columns narrower."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (shrink-window arg t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (defun shrink-window-if-larger-than-buffer (&optional window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 "Shrink the WINDOW to be as small as possible to display its contents.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 Do not shrink to less than `window-min-height' lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 Do nothing if the buffer contains more lines than the present window height,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 or if some of the window's contents are scrolled out of view,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 or if the window is not the full width of the frame,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 or if the window is the only window of its frame."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (or window (setq window (selected-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (set-buffer (window-buffer window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (let* ((w (selected-window)) ;save-window-excursion can't win
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (buffer-file-name buffer-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (p (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (n 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (ignore-final-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 ;; If buffer ends with a newline, ignore it when counting height
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 ;; unless point is after it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (and (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (eq ?\n (char-after (1- (point-max))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (buffer-read-only nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (modified (buffer-modified-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (buffer (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (mini (frame-property (window-frame window) 'minibuffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (edges (window-pixel-edges (selected-window))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (if (and (< 1 (let ((frame (selected-frame)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (select-frame (window-frame window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (count-windows)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (select-frame frame))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 ;; check to make sure that we don't have horizontally
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 ;; split windows
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (eq (frame-highest-window (window-frame window) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (frame-highest-window (window-frame window) -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (pos-visible-in-window-p (point-min) window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (not (eq mini 'only))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (or (not mini) (eq mini t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (< (nth 3 edges)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (nth 1 (window-pixel-edges mini)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (> (nth 1 edges)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 ;FSFmacs (frame-property (window-frame window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 ; 'menu-bar-lines params)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (select-window (or window w))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (while (pos-visible-in-window-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (- (point-max)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (if ignore-final-newline 1 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 ;; defeat file locking... don't try this at home, kids!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (setq buffer-file-name nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (insert ?\n) (setq n (1+ n)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (if (> n 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (shrink-window (min (1- n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (- (window-height)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 window-min-height)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (delete-region (point-min) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (set-buffer-modified-p modified)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (goto-char p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (select-window w)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 ;; Make sure we unbind buffer-read-only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 ;; with the proper current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (set-buffer buffer))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (defun backward-other-window (arg &optional all-frames device)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 "Select the ARG'th different window on this frame, going backwards.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 This is just like calling `other-window' with the arg negated."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (other-window (- arg) all-frames device))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (defun windows-of-buffer (&optional buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 "Returns a list of windows that have BUFFER in them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 If BUFFER is not specified, the current buffer will be used."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (or (bufferp buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (if (stringp buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (setq buffer (or (get-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (get-file-buffer buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (setq buffer (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (let* ((firstwin (next-window nil nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (wind firstwin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (done nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 window-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (while (not done)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (if (eq (window-buffer wind) buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (setq window-list (append window-list (list wind))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (setq wind (next-window wind nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (setq done (eq wind firstwin)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 window-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (defun buffer-in-multiple-windows-p (&optional buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 "Returns t if BUFFER is in multiple windows.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 If BUFFER is not specified, the current buffer will be used."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (setq buffer (or buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (get-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (get-file-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (> (length (windows-of-buffer buffer)) 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (defun window-list (&optional frame minibuf window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 "Return a list of windows on FRAME, beginning with WINDOW.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 FRAME and WINDOW default to the selected ones.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 Optional second arg MINIBUF t means count the minibuffer window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 even if not active. If MINIBUF is neither t nor nil it means
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 not to count the minibuffer even if it is active."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (setq window (or window (selected-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 frame (or frame (selected-frame)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (if (not (eq (window-frame window) frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (error "Window must be on frame."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (let ((current-frame (selected-frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (save-window-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (select-frame frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (walk-windows
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (function (lambda (cur-window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (if (not (eq window cur-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (setq list (cons cur-window list)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 minibuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 (setq list (cons window list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (select-frame current-frame))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 ;; We used to have set-window-dedicated-p as an obsolete version
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 ;; of set-window-buffer-dedicated, but it really makes more sense
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 ;; this way.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (make-obsolete 'set-window-buffer-dedicated 'set-window-dedicated-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (defun set-window-buffer-dedicated (window buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 "Make WINDOW display BUFFER and be dedicated to that buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 Then Emacs will not automatically change which buffer appears in WINDOW.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 If BUFFER is nil, make WINDOW not be dedicated (but don't change which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 buffer appears in it currently)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 (if (bufferp buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (set-window-buffer window (get-buffer-create buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (set-window-dedicated-p window (not (null buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 ;; The window-config stack is stored as a list in frame property
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 ;; 'window-config-stack, with the most recent element at the front.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 ;; When you pop off an element, the popped off element gets put at the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 ;; front of frame property 'window-config-unpop-stack, so you can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 ;; retrieve it using unpop-window-configuration.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (defvar window-config-stack-max 16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 "*Maximum size of window configuration stack.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 Start discarding off end if it gets this big.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 (defun window-config-stack (&optional frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (or frame (setq frame (selected-frame)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (let ((stack (frame-property frame 'window-config-stack)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (if stack
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (set-undoable-stack-max stack window-config-stack-max)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (setq stack (make-undoable-stack window-config-stack-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (set-frame-property frame 'window-config-stack stack)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 stack))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (defun push-window-configuration (&optional config)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 "Push the current window configuration onto the window-config stack.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 If CONFIG is specified, push it instead of the current window configuration.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 Each frame has its own window-config stack."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (let ((wc (or config (current-window-configuration)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (stack (window-config-stack)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (if (or (= 0 (undoable-stack-a-length stack))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (not (equal (undoable-stack-a-top stack) wc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (undoable-stack-push stack wc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 ;; kludge.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (if (featurep 'toolbar)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (set-specifier-dirty-flag default-toolbar))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (defun pop-window-configuration ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 "Pop the top window configuration off the window-config stack and set it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 Before setting the new window configuration, the current window configuration
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 is pushed onto the \"unpop\" stack.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 `unpop-window-configuration' undoes what this function does.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 Each frame has its own window-config and \"unpop\" stack."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (let ((stack (window-config-stack))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (wc (current-window-configuration))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 popped)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (setq popped (undoable-stack-pop stack))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (while (equal popped wc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (setq popped (undoable-stack-pop stack)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (undoable-stack-push stack wc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (undoable-stack-undo stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (set-window-configuration popped)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 ;; probably not necessary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (if (featurep 'toolbar)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (set-specifier-dirty-flag default-toolbar))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 popped)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (trunc-stack-bottom
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 (error "Bottom of window config stack")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (defun unpop-window-configuration ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 "Undo the effect of the most recent `pop-window-configuration'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 This does exactly the inverse of what `pop-window-configuration' does:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 i.e. it pops a window configuration off of the \"unpop\" stack and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 pushes the current window configuration onto the window-config stack.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 Each frame has its own window-config and \"unpop\" stack."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (let ((stack (window-config-stack))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (wc (current-window-configuration))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 popped)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (setq popped
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (undoable-stack-redo stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (undoable-stack-pop stack)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 (while (equal popped wc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (setq popped
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 (undoable-stack-redo stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (undoable-stack-pop stack))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (undoable-stack-push stack wc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (set-window-configuration popped)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 ;; probably not necessary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (if (featurep 'toolbar)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (set-specifier-dirty-flag default-toolbar))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 popped)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (trunc-stack-bottom
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (error "Top of window config stack")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 ;;;;;;;;;;;;; display-buffer, moved here from C. Hallelujah.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (defvar display-buffer-function nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 "If non-nil, function to call to handle `display-buffer'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 It will receive three args: the same as those to `display-buffer'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (defvar pre-display-buffer-function nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 "If non-nil, function that will be called from `display-buffer'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 as the first action. It will receive three args: the same as those
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 to `display-buffer'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 This function may be used to select an appropriate frame for the buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 for example. See also the variable `display-buffer-function', which may
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 be used to completely replace the `display-buffer' function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 If the return value of this function is non-nil, it should be a frame,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 and that frame will be used to display the buffer.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (defvar pop-up-frames nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 "*Non-nil means `display-buffer' should make a separate frame.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (defvar pop-up-frame-function nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 "Function to call to handle automatic new frame creation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 It is called with no arguments and should return a newly created frame.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 A typical value might be `(lambda () (new-frame pop-up-frame-alist))'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 where `pop-up-frame-alist' would hold the default frame parameters.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (defvar special-display-buffer-names nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 "*List of buffer names that should have their own special frames.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 Displaying a buffer whose name is in this list makes a special frame for it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 using `special-display-function'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 An element of the list can be a cons cell instead of just a string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 Then the car should be a buffer name, and the cdr specifies frame
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 parameters for creating the frame for that buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 More precisely, the cdr is passed as the second argument to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 the function found in `special-display-function', when making that frame.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 See also `special-display-regexps'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (defvar special-display-regexps nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 "*List of regexps saying which buffers should have their own special frames.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 If a buffer name matches one of these regexps, it gets its own frame.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 Displaying a buffer whose name is in this list makes a special frame for it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 using `special-display-function'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 An element of the list can be a cons cell instead of just a string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 Then the car should be the regexp, and the cdr specifies frame
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 parameters for creating the frame for buffers that match.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 More precisely, the cdr is passed as the second argument to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 the function found in `special-display-function', when making that frame.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 See also `special-display-buffer-names'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 (defvar special-display-function nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 "Function to call to make a new frame for a special buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 It is called with two arguments, the buffer and optional buffer specific
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 data, and should return a window displaying that buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 The default value makes a separate frame for the buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 using `special-display-frame-alist' to specify the frame parameters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 A buffer is special if its is listed in `special-display-buffer-names'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 or matches a regexp in `special-display-regexps'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (defvar same-window-buffer-names nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 "*List of buffer names that should appear in the selected window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 Displaying one of these buffers using `display-buffer' or `pop-to-buffer'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 switches to it in the selected window, rather than making it appear
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 in some other window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 An element of the list can be a cons cell instead of just a string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 Then the car must be a string, which specifies the buffer name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 This is for compatibility with `special-display-buffer-names';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 the cdr of the cons cell is ignored.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 See also `same-window-regexps'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (defvar same-window-regexps nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 "*List of regexps saying which buffers should appear in the selected window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 If a buffer name matches one of these regexps, then displaying it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 using `display-buffer' or `pop-to-buffer' switches to it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 in the selected window, rather than making it appear in some other window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 An element of the list can be a cons cell instead of just a string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 Then the car must be a string, which specifies the buffer name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 This is for compatibility with `special-display-buffer-names';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 the cdr of the cons cell is ignored.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 See also `same-window-buffer-names'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 (defvar pop-up-windows t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 "*Non-nil means display-buffer should make new windows.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 (defvar split-height-threshold 500
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 "*display-buffer would prefer to split the largest window if this large.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 If there is only one window, it is split regardless of this value.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 (defvar split-width-threshold 500
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 "*display-buffer would prefer to split the largest window if this large.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 If there is only one window, it is split regardless of this value.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 ;; Deiconify the frame containing the window WINDOW, then return WINDOW.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 (defun display-buffer-1 (window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 (if (frame-iconified-p (window-frame window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 (make-frame-visible (window-frame window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 ;; Can you believe that all of this crap was formerly in C?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 ;; Praise Jesus that it's not there any more.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 (defun display-buffer (buffer &optional not-this-window-p override-frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 "Make BUFFER appear in some window on the current frame, but don't select it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 BUFFER can be a buffer or a buffer name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 If BUFFER is shown already in some window in the current frame,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 just uses that one, unless the window is the selected window and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 NOT-THIS-WINDOW-P is non-nil (interactively, with prefix arg).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 If BUFFER has a dedicated frame, display on that frame instead of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 the current frame, unless OVERRIDE-FRAME is non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 If OVERRIDE-FRAME is non-nil, display on that frame instead of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 the current frame (or the dedicated frame).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 If `pop-up-windows' is non-nil, always use the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 current frame and create a new window regardless of whether the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 buffer has a dedicated frame, and regardless of whether
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 OVERRIDE-FRAME was specified.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 If `pop-up-frames' is non-nil, make a new frame if no window shows BUFFER.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 Returns the window displaying BUFFER."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 (interactive "BDisplay buffer:\nP")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 (let ((wconfig (current-window-configuration))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 (result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 ;; We just simulate a `return' in C. This function is way ugly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 ;; and does `returns' all over the place and there's no sense
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 ;; in trying to rewrite it to be more Lispy.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 (catch 'done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 (let (window old-frame target-frame explicit-frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 (setq old-frame (or (last-nonminibuf-frame) (selected-frame)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 (setq buffer (get-buffer buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 (check-argument-type 'bufferp buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 (setq explicit-frame
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 (if pre-display-buffer-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 (funcall pre-display-buffer-function buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 not-this-window-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 override-frame)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 ;; Give the user the ability to completely reimplement
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 ;; this function via the `display-buffer-function'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 (if display-buffer-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 (throw 'done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 (funcall display-buffer-function buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 not-this-window-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 override-frame)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 ;; If the buffer has a dedicated frame, that takes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 ;; precedence over the current frame, and over what the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 ;; pre-display-buffer-function did.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 (let ((dedi (buffer-dedicated-frame buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 (if (frame-live-p dedi) (setq explicit-frame dedi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 ;; if override-frame is supplied, that takes precedence over
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 ;; everything. This is gonna look bad if the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 ;; pre-display-buffer-function raised some other frame
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 ;; already.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 (if override-frame
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 (check-argument-type 'frame-live-p override-frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 (setq explicit-frame override-frame)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 (setq target-frame
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 (or explicit-frame
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 (last-nonminibuf-frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 (selected-frame)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 ;; If we have switched frames, then set not-this-window-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 ;; to false. Switching frames means that selected-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 ;; is no longer the same as it was on entry -- it's the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 ;; selected-window of target_frame instead of old_frame,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 ;; so it's a fine candidate for display.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 (if (not (eq old-frame target-frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (setq not-this-window-p nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 ;; if it's in the selected window, and that's ok, then we're done.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 (if (and (not not-this-window-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 (eq buffer (window-buffer (selected-window))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 (throw 'done (display-buffer-1 (selected-window))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 ;; See if the user has specified this buffer should appear
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 ;; in the selected window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (if not-this-window-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 (if (or (member (buffer-name buffer) same-window-buffer-names)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 (assoc (buffer-name buffer) same-window-buffer-names))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 (switch-to-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 (throw 'done (display-buffer-1 (selected-window)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 (let ((tem same-window-regexps))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 (while tem
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 (let ((car (car tem)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 (if (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 (and (stringp car)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 (string-match car (buffer-name buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 (and (consp car) (stringp (car car))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 (string-match (car car) (buffer-name buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 (switch-to-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 (throw 'done (display-buffer-1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 (selected-window))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 (setq tem (cdr tem)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 ;; If pop-up-frames, look for a window showing BUFFER on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 ;; any visible or iconified frame. Otherwise search only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 ;; the current frame.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 (if (and (not explicit-frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 (or pop-up-frames (not (last-nonminibuf-frame))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 (setq target-frame 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 ;; Otherwise, find some window that it's already in, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 ;; return that, unless that window is the selected window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 ;; and that isn't ok. What a contorted mess!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 (setq window (get-buffer-window buffer target-frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 (if (and window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 (or (not not-this-window-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 (not (eq window (selected-window)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 (throw 'done (display-buffer-1 window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 ;; Certain buffer names get special handling.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 (if special-display-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 (if (member (buffer-name buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 special-display-buffer-names)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 (throw 'done (funcall special-display-function buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 (let ((tem (assoc (buffer-name buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 special-display-buffer-names)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 (if tem
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 (throw 'done (funcall special-display-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 buffer (cdr tem)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 (let ((tem special-display-regexps))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 (while tem
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 (let ((car (car tem)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 (if (and (stringp car)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 (string-match car (buffer-name buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 (throw 'done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 (funcall special-display-function buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 (if (and (consp car)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 (stringp (car car))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 (string-match (car car)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 (buffer-name buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 (throw 'done (funcall
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 special-display-function buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 (cdr car)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 (setq tem (cdr tem))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 ;; If there are no frames open that have more than a minibuffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 ;; we need to create a new frame.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 (if (or pop-up-frames
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 (null (last-nonminibuf-frame)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 (setq window (frame-selected-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 (funcall pop-up-frame-function)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 (set-window-buffer window buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 (throw 'done (display-buffer-1 window))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 ;; Otherwise, make it be in some window, splitting if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 ;; appropriate/possible. Do not split a window if we are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 ;; displaying the buffer in a different frame than that which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 ;; was current when we were called. (It is already in a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 ;; different window by virtue of being in another frame.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 (if (or (and pop-up-windows (eq target-frame old-frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 (eq 'only (frame-property (selected-frame) 'minibuffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 ;; If the current frame is a special display frame,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 ;; don't try to reuse its windows.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 (window-dedicated-p (frame-root-window (selected-frame))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 (if (eq 'only (frame-property (selected-frame) 'minibuffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 (setq target-frame (last-nonminibuf-frame)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 ;; Don't try to create a window if would get an error with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 ;; height.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 (if (< split-height-threshold (* 2 window-min-height))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 (setq split-height-threshold (* 2 window-min-height)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 ;; Same with width.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 (if (< split-width-threshold (* 2 window-min-width))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 (setq split-width-threshold (* 2 window-min-width)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 ;; If the frame we would try to split cannot be split,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 ;; try other frames.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 (if (frame-property (if (null target-frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 (selected-frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 (last-nonminibuf-frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 'unsplittable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 (setq window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 ;; Try visible frames first.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 (or (get-largest-window 'visible)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 ;; If that didn't work, try iconified frames.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 (get-largest-window 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 (get-largest-window t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 (setq window (get-largest-window target-frame)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 ;; If we got a tall enough full-width window that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 ;; can be split, split it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 (if (and window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 (not (frame-property (window-frame window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 'unsplittable))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 (>= (window-height window) split-height-threshold)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 (or (>= (window-width window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 split-width-threshold)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 (and (window-leftmost-p window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 (window-rightmost-p window))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 (setq window (split-window window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 (let (upper lower other)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 (setq window (get-lru-window target-frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 ;; If the LRU window is selected, and big enough,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 ;; and can be split, split it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 (if (and window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 (not (frame-property (window-frame window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 'unsplittable))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 (or (eq window (selected-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 (not (window-parent window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 (>= (window-height window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 (* 2 window-min-height)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 (setq window (split-window window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 ;; If get-lru-window returned nil, try other approaches.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 ;; Try visible frames first.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 (or window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 (setq window (or (get-largest-window 'visible)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 ;; If that didn't work, try
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 ;; iconified frames.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 (get-largest-window 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 ;; Try invisible frames.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 (get-largest-window t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 ;; As a last resort, make
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 ;; a new frame.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 (frame-selected-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 (funcall
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 pop-up-frame-function)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 ;; If window appears above or below another,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 ;; even out their heights.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 (if (window-previous-child window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 (setq other (window-previous-child window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 upper other
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 lower window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 (if (window-next-child window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 (setq other (window-next-child window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 lower other
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 upper window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 ;; Check that OTHER and WINDOW are vertically arrayed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 (if (and other
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 (not (= (nth 1 (window-pixel-edges other))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 (nth 1 (window-pixel-edges window))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 (> (window-pixel-height other)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 (window-pixel-height window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 (enlarge-window (- (/ (+ (window-height other)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 (window-height window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 (window-height upper))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 nil upper)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 (setq window (get-lru-window target-frame)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 ;; Bring the window's previous buffer to the top of the MRU chain.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 (if (window-buffer window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 (save-selected-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 (select-window window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 (record-buffer (window-buffer window)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 (set-window-buffer window buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 (display-buffer-1 window)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 (or (equal wconfig (current-window-configuration))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 (push-window-configuration wconfig))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 result))