annotate lisp/window.el @ 1218:ceedb6eeaba8

[xemacs-hg @ 2003-01-16 08:59:47 by michaels] 2003-01-13 Mike Sperber <mike@xemacs.org> * packages.el: * find-paths.el: Revert this change 2000-04-01 Mike Sperber <mike@xemacs.org> * packages.el (packages-find-package-directories): Added support for external package hierarchies with in-place installations. * find-paths.el (paths-root-in-place-p): Added. (paths-find-emacs-directory): Added support for external directories with in-place installations. (paths-find-site-directory): Ditto.
author michaels
date Thu, 16 Jan 2003 08:59:47 +0000
parents 960da99ad52b
children cd0abfdb9e9d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 ;;; window.el --- XEmacs window commands aside from those written in C.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985, 1989, 1993-94, 1997 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 ;; Copyright (C) 1995, 1996 Ben Wing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 ;; Maintainer: XEmacs Development Team
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 ;; Keywords: frames, extensions, dumped
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 ;; This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 ;; XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 ;; under the terms of the GNU General Public License as published by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 ;; any later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 ;; General Public License for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 ;; along with XEmacs; see the file COPYING. If not, write to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 ;; Free Software Foundation, 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 ;; Boston, MA 02111-1307, USA.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 ;;; Synched up with: Emacs/Mule zeta.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 ;;; Commentary:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 ;; This file is dumped with XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 ;;; Code:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 ;;;; Window tree functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
36 (defun one-window-p (&optional nomini which-frames which-devices)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 "Return non-nil if the selected window is the only window (in its frame).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 Optional arg NOMINI non-nil means don't count the minibuffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 even if it is active.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
41 By default, only the windows in the selected frame are considered.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
42 The optional argument WHICH-FRAMES changes this behavior:
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
43 WHICH-FRAMES nil or omitted means count only the selected frame,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 plus the minibuffer it uses (which may be on another frame).
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
45 WHICH-FRAMES = `visible' means include windows on all visible frames.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
46 WHICH-FRAMES = 0 means include windows on all visible and iconified frames.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
47 WHICH-FRAMES = t means include windows on all frames including invisible frames.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
48 If WHICH-FRAMES is any other value, count only the selected frame.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
50 The optional third argument WHICH-DEVICES further clarifies on which
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
51 devices to search for frames as specified by WHICH-FRAMES. This value
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
52 is only meaningful if WHICH-FRAMES is non-nil.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
53 If nil or omitted, search all devices on the selected console.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
54 If a device, only search that device.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
55 If a console, search all devices on that console.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
56 If a device type, search all devices of that type.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
57 If `window-system', search all devices on window-system consoles.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
58 Any other non-nil value means search all devices."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 (let ((base-window (selected-window)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 (if (and nomini (eq base-window (minibuffer-window)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 (setq base-window (next-window base-window)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 (eq base-window
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
63 (next-window base-window (if nomini 'arg) which-frames which-devices))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
65 (defun walk-windows (function &optional minibuf which-frames which-devices)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
66 "Cycle through all visible windows, calling FUNCTION for each one.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
67 FUNCTION is called with a window as argument.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 Optional second arg MINIBUF t means count the minibuffer window even
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 if not active. MINIBUF nil or omitted means count the minibuffer iff
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 it is active. MINIBUF neither t nor nil means not to count the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 minibuffer even if it is active.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 Several frames may share a single minibuffer; if the minibuffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 counts, all windows on all frames that share that minibuffer count
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 too. Therefore, when a separate minibuffer frame is active,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 `walk-windows' includes the windows in the frame from which you
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 entered the minibuffer, as well as the minibuffer window. But if the
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
79 minibuffer does not count, only the selected window counts.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
81 By default, only the windows in the selected frame are included.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
82 The optional argument WHICH-FRAMES changes this behavior:
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
83 WHICH-FRAMES nil or omitted means cycle within the frames as specified above.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
84 WHICH-FRAMES = `visible' means include windows on all visible frames.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
85 WHICH-FRAMES = 0 means include windows on all visible and iconified frames.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
86 WHICH-FRAMES = t means include windows on all frames including invisible frames.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 Anything else means restrict to WINDOW's frame.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
89 The optional fourth argument WHICH-DEVICES further clarifies on which
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
90 devices to search for frames as specified by WHICH-FRAMES. This value
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
91 is only meaningful if WHICH-FRAMES is non-nil.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
92 If nil or omitted, search all devices on the selected console.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
93 If a device, only search that device.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
94 If a console, search all devices on that console.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
95 If a device type, search all devices of that type.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
96 If `window-system', search all devices on window-system consoles.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
97 Any other non-nil value means search all devices."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 ;; If we start from the minibuffer window, don't fail to come back to it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 (if (window-minibuffer-p (selected-window))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 (setq minibuf t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 ;; Note that, like next-window & previous-window, this behaves a little
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 ;; strangely if the selected window is on an invisible frame: it hits
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 ;; some of the windows on that frame, and all windows on visible frames.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 (let* ((walk-windows-start (selected-window))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 (walk-windows-current walk-windows-start))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 (while (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 (setq walk-windows-current
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
108 (next-window walk-windows-current minibuf which-frames
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
109 which-devices))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
110 (funcall function walk-windows-current)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 (not (eq walk-windows-current walk-windows-start))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 ;; The old XEmacs definition of the above clause. It's more correct in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 ;; that it will never hit a window that's already been hit even if you
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 ;; do something odd like `delete-other-windows', but has the problem
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 ;; that it conses. (This may be called repeatedly, from lazy-lock
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 ;; for example.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 ; (let* ((walk-windows-history nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 ; (walk-windows-current (selected-window)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 ; (while (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 ; (setq walk-windows-current
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
121 ; (next-window walk-windows-current minibuf which-frames
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
122 ; which-devices))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 ; (not (memq walk-windows-current walk-windows-history)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 ; (setq walk-windows-history (cons walk-windows-current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 ; walk-windows-history))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
126 ; (funcall function walk-windows-current))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
128 (defun get-window-with-predicate (predicate &optional minibuf
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
129 all-frames default)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
130 "Return a window satisfying PREDICATE.
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
131
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
132 This function cycles through all visible windows using `walk-windows',
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
133 calling PREDICATE on each one. PREDICATE is called with a window as
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
134 argument. The first window for which PREDICATE returns a non-nil
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
135 value is returned. If no window satisfies PREDICATE, DEFAULT is
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
136 returned.
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
137
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
138 Optional second arg MINIBUF t means count the minibuffer window even
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
139 if not active. MINIBUF nil or omitted means count the minibuffer iff
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
140 it is active. MINIBUF neither t nor nil means not to count the
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
141 minibuffer even if it is active.
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
142
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
143 Several frames may share a single minibuffer; if the minibuffer
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
144 counts, all windows on all frames that share that minibuffer count
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
145 too. Therefore, if you are using a separate minibuffer frame
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
146 and the minibuffer is active and MINIBUF says it counts,
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
147 `walk-windows' includes the windows in the frame from which you
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
148 entered the minibuffer, as well as the minibuffer window.
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
149
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
150 ALL-FRAMES is the optional third argument.
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
151 ALL-FRAMES nil or omitted means cycle within the frames as specified above.
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
152 ALL-FRAMES = `visible' means include windows on all visible frames.
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
153 ALL-FRAMES = 0 means include windows on all visible and iconified frames.
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
154 ALL-FRAMES = t means include windows on all frames including invisible frames.
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
155 If ALL-FRAMES is a frame, it means include windows on that frame.
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
156 Anything else means restrict to the selected frame."
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
157 (catch 'found
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
158 (walk-windows #'(lambda (window)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
159 (when (funcall predicate window)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
160 (throw 'found window)))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
161 minibuf all-frames)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
162 default))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
163
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
164 (defalias 'some-window 'get-window-with-predicate)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
165
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 (defun minibuffer-window-active-p (window)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 "Return t if WINDOW (a minibuffer window) is now active."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 (eq window (active-minibuffer-window)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 (defmacro save-selected-window (&rest body)
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 444
diff changeset
171 "Execute BODY, then select the window that was selected before BODY.
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 444
diff changeset
172 The value returned is the value of the last form in BODY."
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 444
diff changeset
173 (let ((old-window (gensym "ssw")))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 444
diff changeset
174 `(let ((,old-window (selected-window)))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
175 (unwind-protect
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
176 (progn ,@body)
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 444
diff changeset
177 (when (window-live-p ,old-window)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 444
diff changeset
178 (select-window ,old-window))))))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
179
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
180 (defmacro with-selected-window (window &rest body)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
181 "Execute forms in BODY with WINDOW as the selected window.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
182 The value returned is the value of the last form in BODY."
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
183 `(save-selected-window
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
184 (select-window ,window)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
185 ,@body))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186
1133
960da99ad52b [xemacs-hg @ 2002-12-02 12:27:18 by michaels]
michaels
parents: 1127
diff changeset
187 (defmacro save-window-excursion (&rest body)
960da99ad52b [xemacs-hg @ 2002-12-02 12:27:18 by michaels]
michaels
parents: 1127
diff changeset
188 "Execute body, preserving window sizes and contents.
960da99ad52b [xemacs-hg @ 2002-12-02 12:27:18 by michaels]
michaels
parents: 1127
diff changeset
189 Restores which buffer appears in which window, where display starts,
960da99ad52b [xemacs-hg @ 2002-12-02 12:27:18 by michaels]
michaels
parents: 1127
diff changeset
190 as well as the current buffer.
960da99ad52b [xemacs-hg @ 2002-12-02 12:27:18 by michaels]
michaels
parents: 1127
diff changeset
191 Does not restore the value of point in current buffer."
960da99ad52b [xemacs-hg @ 2002-12-02 12:27:18 by michaels]
michaels
parents: 1127
diff changeset
192 (let ((window-config (gensym 'window-config)))
960da99ad52b [xemacs-hg @ 2002-12-02 12:27:18 by michaels]
michaels
parents: 1127
diff changeset
193 `(let ((,window-config (current-window-configuration)))
960da99ad52b [xemacs-hg @ 2002-12-02 12:27:18 by michaels]
michaels
parents: 1127
diff changeset
194 (unwind-protect
960da99ad52b [xemacs-hg @ 2002-12-02 12:27:18 by michaels]
michaels
parents: 1127
diff changeset
195 (progn ,@body)
960da99ad52b [xemacs-hg @ 2002-12-02 12:27:18 by michaels]
michaels
parents: 1127
diff changeset
196 (set-window-configuration ,window-config)))))
960da99ad52b [xemacs-hg @ 2002-12-02 12:27:18 by michaels]
michaels
parents: 1127
diff changeset
197
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 (defun count-windows (&optional minibuf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 "Return the number of visible windows.
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
200 This counts the windows in the selected frame and (if the minibuffer is
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
201 to be counted) its minibuffer frame (if that's not the same frame).
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
202 The optional arg MINIBUF non-nil means count the minibuffer
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 even if it is inactive."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 (let ((count 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 (walk-windows (function (lambda (w)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 (setq count (+ count 1))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 minibuf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 count))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
210 (defun window-safely-shrinkable-p (&optional window)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
211 "Non-nil if the WINDOW can be shrunk without shrinking other windows.
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
212 If WINDOW is nil or omitted, it defaults to the currently selected window."
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
213 (save-selected-window
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
214 (when window (select-window window))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
215 (or (and (not (eq window (frame-first-window)))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
216 (= (car (window-pixel-edges))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
217 (car (window-pixel-edges (previous-window)))))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
218 (= (car (window-pixel-edges))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
219 (car (window-pixel-edges (next-window)))))))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
220
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 (defun balance-windows ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 "Make all visible windows the same height (approximately)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 (let ((count -1) levels newsizes size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 ;FSFmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 ;;; Don't count the lines that are above the uppermost windows.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 ;;; (These are the menu bar lines, if any.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 ;(mbl (nth 1 (window-edges (frame-first-window (selected-frame))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 ;; Find all the different vpos's at which windows start,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 ;; then count them. But ignore levels that differ by only 1.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 (save-window-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 (let (tops (prev-top -2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 (walk-windows (function (lambda (w)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 (setq tops (cons (nth 1 (window-pixel-edges w))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 tops))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 'nomini)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 (setq tops (sort tops '<))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 (while tops
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 (if (> (car tops) (1+ prev-top))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 (setq prev-top (car tops)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 count (1+ count)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 (setq levels (cons (cons (car tops) count) levels))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 (setq tops (cdr tops)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 (setq count (1+ count))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 ;; Subdivide the frame into that many vertical levels.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 ;FSFmacs (setq size (/ (- (frame-height) mbl) count))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 (setq size (/ (window-pixel-height (frame-root-window)) count))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 (walk-windows (function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 (lambda (w)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 (select-window w)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 (let ((newtop (cdr (assq (nth 1 (window-pixel-edges))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 levels)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 (newbot (or (cdr (assq
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 (+ (window-pixel-height)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 (nth 1 (window-pixel-edges)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 levels))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 count)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 (setq newsizes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 (cons (cons w (* size (- newbot newtop)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 newsizes)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 'nomini)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 (walk-windows (function (lambda (w)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 (select-window w)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 (let ((newsize (cdr (assq w newsizes))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 (enlarge-window
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 (/ (- newsize (window-pixel-height))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 (face-height 'default))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 'nomini)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 ;;; I think this should be the default; I think people will prefer it--rms.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 (defcustom split-window-keep-point t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 "*If non-nil, split windows keeps the original point in both children.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 This is often more convenient for editing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 If nil, adjust point in each of the two windows to minimize redisplay.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 This is convenient on slow terminals, but point can move strangely."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 :group 'windows)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 (defun split-window-vertically (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 "Split current window into two windows, one above the other.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 The uppermost window gets ARG lines and the other gets the rest.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 Negative arg means select the size of the lowermost window instead.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 With no argument, split equally or close to it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 Both windows display the same buffer now current.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285
730
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
286 If the variable `split-window-keep-point' is non-nil, both new windows
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 will get the same value of point as the current window. This is often
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 more convenient for editing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
290 Otherwise, we choose window starts so as to minimize the amount of
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 redisplay; this is convenient on slow terminals. The new selected
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 window is the one that the current value of point appears in. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 value of point can change if the text around point is hidden by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 new mode line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 Programs should probably use split-window instead of this."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 (let ((old-w (selected-window))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 (old-point (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 (size (and arg (prefix-numeric-value arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 (window-full-p nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 new-w bottom moved)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 (and size (< size 0) (setq size (+ (window-height) size)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 (setq new-w (split-window nil size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 (or split-window-keep-point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 (set-buffer (window-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 (goto-char (window-start))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 (setq moved (vertical-motion (window-height)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 (set-window-start new-w (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 (if (> (point) (window-point new-w))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 (set-window-point new-w (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 (and (= moved (window-height))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 (setq window-full-p t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 (vertical-motion -1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 (setq bottom (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 (and window-full-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 (<= bottom (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 (set-window-point old-w (1- bottom)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 (and window-full-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 (<= (window-start new-w) old-point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 (set-window-point new-w old-point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 (select-window new-w)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 new-w))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 (defun split-window-horizontally (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 "Split current window into two windows side by side.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 This window becomes the leftmost of the two, and gets ARG columns.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 Negative arg means select the size of the rightmost window instead.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 No arg means split equally."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 (let ((size (and arg (prefix-numeric-value arg))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 (and size (< size 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 (setq size (+ (window-width) size)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 (split-window nil size t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 (defun enlarge-window-horizontally (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 "Make current window ARG columns wider."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 (enlarge-window arg t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 (defun shrink-window-horizontally (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 "Make current window ARG columns narrower."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 (shrink-window arg t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
350 ; (defun window-buffer-height (window)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
351 ; "Return the height (in screen lines) of the buffer that WINDOW is displaying."
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
352 ; (save-excursion
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
353 ; (set-buffer (window-buffer window))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
354 ; (goto-char (point-min))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
355 ; (let ((ignore-final-newline
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
356 ; ;; If buffer ends with a newline, ignore it when counting height
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
357 ; ;; unless point is after it.
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
358 ; (and (not (eobp)) (eq ?\n (char-after (1- (point-max)))))))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
359 ; (+ 1 (nth 2 (compute-motion (point-min)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
360 ; '(0 . 0)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
361 ; (- (point-max) (if ignore-final-newline 1 0))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
362 ; (cons 0 100000000)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
363 ; (window-width window)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
364 ; nil
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
365 ; window))))))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
366
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
367 (defun count-screen-lines (&optional beg end count-final-newline window)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
368 "Return the number of screen lines in the region.
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
369 The number of screen lines may be different from the number of actual lines,
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
370 due to line breaking, display table, etc.
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
371
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
372 Optional arguments BEG and END default to `point-min' and `point-max'
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
373 respectively.
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
374
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
375 If region ends with a newline, ignore it unless optional third argument
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
376 COUNT-FINAL-NEWLINE is non-nil.
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
377
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
378 The optional fourth argument WINDOW specifies the window used for obtaining
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
379 parameters such as width, horizontal scrolling, and so on. The default is
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
380 to use the selected window's parameters.
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
381
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
382 Like `vertical-motion', `count-screen-lines' always uses the current buffer,
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
383 regardless of which buffer is displayed in WINDOW. This makes possible to use
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
384 `count-screen-lines' in any buffer, whether or not it is currently displayed
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
385 in some window."
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
386 (unless beg
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
387 (setq beg (point-min)))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
388 (unless end
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
389 (setq end (point-max)))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
390 (if (= beg end)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
391 0
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
392 (save-excursion
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
393 (save-restriction
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
394 (widen)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
395 (narrow-to-region (min beg end)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
396 (if (and (not count-final-newline)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
397 (= ?\n (char-before (max beg end))))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
398 (1- (max beg end))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
399 (max beg end)))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
400 (goto-char (point-min))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
401 (1+ (vertical-motion (buffer-size) window))))))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
402
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
403 ; (defun fit-window-to-buffer (&optional window max-height min-height)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
404 ; "Make WINDOW the right size to display its contents exactly.
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
405 ; If WINDOW is omitted or nil, it defaults to the selected window.
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
406 ; If the optional argument MAX-HEIGHT is supplied, it is the maximum height
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
407 ; the window is allowed to be, defaulting to the frame height.
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
408 ; If the optional argument MIN-HEIGHT is supplied, it is the minimum
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
409 ; height the window is allowed to be, defaulting to `window-min-height'.
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
410
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
411 ; The heights in MAX-HEIGHT and MIN-HEIGHT include the mode-line and/or
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
412 ; header-line."
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
413 ; (interactive)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
414
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
415 ; (when (null window)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
416 ; (setq window (selected-window)))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
417 ; (when (null max-height)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
418 ; (setq max-height (frame-height (window-frame window))))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
419
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
420 ; (let* ((buf
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
421 ; ;; Buffer that is displayed in WINDOW
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
422 ; (window-buffer window))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
423 ; (window-height
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
424 ; ;; The current height of WINDOW
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
425 ; (window-height window))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
426 ; (desired-height
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
427 ; ;; The height necessary to show the buffer displayed by WINDOW
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
428 ; ;; (`count-screen-lines' always works on the current buffer).
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
429 ; (with-current-buffer buf
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
430 ; (+ (count-screen-lines)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
431 ; ;; If the buffer is empty, (count-screen-lines) is
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
432 ; ;; zero. But, even in that case, we need one text line
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
433 ; ;; for cursor.
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
434 ; (if (= (point-min) (point-max))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
435 ; 1 0)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
436 ; ;; For non-minibuffers, count the mode-line, if any
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
437 ; (if (and (not (window-minibuffer-p window))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
438 ; mode-line-format)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
439 ; 1 0)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
440 ; ;; Count the header-line, if any
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
441 ; (if header-line-format 1 0))))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
442 ; (delta
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
443 ; ;; Calculate how much the window height has to change to show
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
444 ; ;; desired-height lines, constrained by MIN-HEIGHT and MAX-HEIGHT.
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
445 ; (- (max (min desired-height max-height)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
446 ; (or min-height window-min-height))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
447 ; window-height))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
448 ; ;; We do our own height checking, so avoid any restrictions due to
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
449 ; ;; window-min-height.
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
450 ; (window-min-height 1))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
451
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
452 ; ;; Don't try to redisplay with the cursor at the end
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
453 ; ;; on its own line--that would force a scroll and spoil things.
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
454 ; (when (with-current-buffer buf
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
455 ; (and (eobp) (bolp) (not (bobp))))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
456 ; (set-window-point window (1- (window-point window))))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
457
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
458 ; (save-selected-window
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
459 ; (select-window window)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
460
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
461 ; ;; Adjust WINDOW to the nominally correct size (which may actually
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
462 ; ;; be slightly off because of variable height text, etc).
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
463 ; (unless (zerop delta)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
464 ; (enlarge-window delta))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
465
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
466 ; ;; Check if the last line is surely fully visible. If not,
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
467 ; ;; enlarge the window.
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
468 ; (let ((end (with-current-buffer buf
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
469 ; (save-excursion
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
470 ; (goto-char (point-max))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
471 ; (when (and (bolp) (not (bobp)))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
472 ; ;; Don't include final newline
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
473 ; (backward-char 1))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
474 ; (when truncate-lines
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
475 ; ;; If line-wrapping is turned off, test the
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
476 ; ;; beginning of the last line for visibility
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
477 ; ;; instead of the end, as the end of the line
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
478 ; ;; could be invisible by virtue of extending past
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
479 ; ;; the edge of the window.
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
480 ; (forward-line 0))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
481 ; (point)))))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
482 ; (set-window-vscroll window 0)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
483 ; (while (and (< desired-height max-height)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
484 ; (= desired-height (window-height window))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
485 ; (not (pos-visible-in-window-p end window)))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
486 ; (enlarge-window 1)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
487 ; (setq desired-height (1+ desired-height)))))))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 730
diff changeset
488
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 (defun shrink-window-if-larger-than-buffer (&optional window)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 "Shrink the WINDOW to be as small as possible to display its contents.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 Do not shrink to less than `window-min-height' lines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 Do nothing if the buffer contains more lines than the present window height,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 or if some of the window's contents are scrolled out of view,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 or if the window is not the full width of the frame,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 or if the window is the only window of its frame."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 (or window (setq window (selected-window)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 (set-buffer (window-buffer window))
1127
68f6865bee47 [xemacs-hg @ 2002-11-28 12:38:16 by michaels]
michaels
parents: 800
diff changeset
500 (let ((test-pos
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 (- (point-max)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 ;; If buffer ends with a newline, ignore it when counting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 ;; height unless point is after it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 (if (and (not (eobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 (eq ?\n (char-after (1- (point-max)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 1 0)))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
507 (mini (frame-property (window-frame window) 'minibuffer)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 (if (and (< 1 (let ((frame (selected-frame)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 (select-frame (window-frame window))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 (unwind-protect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 (count-windows)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 (select-frame frame))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 ;; check to make sure that the window is the full width
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 ;; of the frame
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
515 (window-leftmost-p window)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
516 (window-rightmost-p window)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 ;; The whole buffer must be visible.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 (pos-visible-in-window-p (point-min) window)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 ;; The frame must not be minibuffer-only.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 (not (eq mini 'only)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 (progn
1127
68f6865bee47 [xemacs-hg @ 2002-11-28 12:38:16 by michaels]
michaels
parents: 800
diff changeset
522 (goto-char (point-min))
68f6865bee47 [xemacs-hg @ 2002-11-28 12:38:16 by michaels]
michaels
parents: 800
diff changeset
523 (while (and (pos-visible-in-window-p test-pos window)
68f6865bee47 [xemacs-hg @ 2002-11-28 12:38:16 by michaels]
michaels
parents: 800
diff changeset
524 (> (window-height window) window-min-height))
68f6865bee47 [xemacs-hg @ 2002-11-28 12:38:16 by michaels]
michaels
parents: 800
diff changeset
525 (shrink-window 1 nil window))
68f6865bee47 [xemacs-hg @ 2002-11-28 12:38:16 by michaels]
michaels
parents: 800
diff changeset
526 (if (not (pos-visible-in-window-p test-pos window))
68f6865bee47 [xemacs-hg @ 2002-11-28 12:38:16 by michaels]
michaels
parents: 800
diff changeset
527 (enlarge-window 1 nil window)))))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 (defun kill-buffer-and-window ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 "Kill the current buffer and delete the selected window."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 (if (yes-or-no-p (format "Kill buffer `%s'? " (buffer-name)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 (let ((buffer (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 (delete-window (selected-window))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 (kill-buffer buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 (error "Aborted")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537
730
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
538 (defun quit-window (&optional kill window)
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
539 "Quit the current buffer. Bury it, and maybe delete the selected frame.
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
540 \(The frame is deleted if it is contains a dedicated window for the buffer.)
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
541 With a prefix argument, kill the buffer instead.
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
542
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
543 Noninteractively, if KILL is non-nil, then kill the current buffer,
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
544 otherwise bury it.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545
730
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
546 If WINDOW is non-nil, it specifies a window; we delete that window,
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
547 and the buffer that is killed or buried is the one in that window."
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
548 (interactive "P")
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
549 (let ((buffer (window-buffer window))
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
550 (frame (window-frame (or window (selected-window))))
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
551 (window-solitary
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
552 (save-selected-window
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
553 (if window
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
554 (select-window window))
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
555 (one-window-p t)))
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
556 window-handled)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
557
730
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
558 (save-selected-window
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
559 (if window
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
560 (select-window window))
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
561 (or (window-minibuffer-p)
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
562 (window-dedicated-p (selected-window))
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
563 (switch-to-buffer (other-buffer))))
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
564
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
565 ;; Get rid of the frame, if it has just one dedicated window
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
566 ;; and other visible frames exist.
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
567 (and (or (window-minibuffer-p) (window-dedicated-p window))
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
568 (delq frame (visible-frame-list))
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
569 window-solitary
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
570 (if (and (eq default-minibuffer-frame frame)
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
571 (= 1 (length (minibuffer-frame-list))))
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
572 (setq window nil)
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
573 (delete-frame frame)
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
574 (setq window-handled t)))
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
575
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
576 ;; Deal with the buffer.
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
577 (if kill
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
578 (kill-buffer buffer)
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
579 (bury-buffer buffer))
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
580
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
581 ;; Maybe get rid of the window.
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
582 (and window (not window-handled) (not window-solitary)
3e321319c5ba [xemacs-hg @ 2002-01-12 00:19:50 by janv]
janv
parents: 460
diff changeset
583 (delete-window window))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 ;;; window.el ends here