annotate lisp/prim/window.el @ 42:8b8b7f3559a2 r19-15b104

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