Mercurial > emacs
annotate lisp/window.el @ 55243:fa2641411db1
(struct it): Remove member use_default_face.
Add members override_ascent, override_descent, override_boff.
author | Kim F. Storm <storm@cua.dk> |
---|---|
date | Thu, 29 Apr 2004 22:36:34 +0000 |
parents | 10dc0a48bc2c |
children | 1709fc8089c9 |
rev | line source |
---|---|
38412
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
36666
diff
changeset
|
1 ;;; window.el --- GNU Emacs window commands aside from those written in C |
773
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
707
diff
changeset
|
2 |
53894
0a356c1b7057
(window-safely-shrinkable-p): Don't change the buffer-list.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52615
diff
changeset
|
3 ;; Copyright (C) 1985, 1989, 1992, 1993, 1994, 2000, 2001, 2002, 2004 |
28655
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
4 ;; Free Software Foundation, Inc. |
841 | 5 |
773
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
707
diff
changeset
|
6 ;; Maintainer: FSF |
39117 | 7 ;; Keywords: internal |
36 | 8 |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
707 | 13 ;; the Free Software Foundation; either version 2, or (at your option) |
36 | 14 ;; any later version. |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
14169 | 22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
36 | 25 |
33708
7c2b5397acbc
General comment and spacing fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33537
diff
changeset
|
26 ;;; Commentary: |
7c2b5397acbc
General comment and spacing fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33537
diff
changeset
|
27 |
7c2b5397acbc
General comment and spacing fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33537
diff
changeset
|
28 ;; Window tree functions. |
7c2b5397acbc
General comment and spacing fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33537
diff
changeset
|
29 |
773
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
707
diff
changeset
|
30 ;;; Code: |
36 | 31 |
43093
5b046c8a20a6
(save-selected-window): Move macro before first use.
Andreas Schwab <schwab@suse.de>
parents:
42876
diff
changeset
|
32 (defmacro save-selected-window (&rest body) |
5b046c8a20a6
(save-selected-window): Move macro before first use.
Andreas Schwab <schwab@suse.de>
parents:
42876
diff
changeset
|
33 "Execute BODY, then select the window that was selected before BODY. |
48941
7262fd90146a
(save-selected-window): Save and restore selected windows of all frames.
Richard M. Stallman <rms@gnu.org>
parents:
46896
diff
changeset
|
34 Also restore the selected window of each frame as it was at the start |
7262fd90146a
(save-selected-window): Save and restore selected windows of all frames.
Richard M. Stallman <rms@gnu.org>
parents:
46896
diff
changeset
|
35 of this construct. |
7262fd90146a
(save-selected-window): Save and restore selected windows of all frames.
Richard M. Stallman <rms@gnu.org>
parents:
46896
diff
changeset
|
36 However, if a window has become dead, don't get an error, |
7262fd90146a
(save-selected-window): Save and restore selected windows of all frames.
Richard M. Stallman <rms@gnu.org>
parents:
46896
diff
changeset
|
37 just refrain from reselecting it." |
7262fd90146a
(save-selected-window): Save and restore selected windows of all frames.
Richard M. Stallman <rms@gnu.org>
parents:
46896
diff
changeset
|
38 `(let ((save-selected-window-window (selected-window)) |
7262fd90146a
(save-selected-window): Save and restore selected windows of all frames.
Richard M. Stallman <rms@gnu.org>
parents:
46896
diff
changeset
|
39 (save-selected-window-alist |
7262fd90146a
(save-selected-window): Save and restore selected windows of all frames.
Richard M. Stallman <rms@gnu.org>
parents:
46896
diff
changeset
|
40 (mapcar (lambda (frame) (list frame (frame-selected-window frame))) |
7262fd90146a
(save-selected-window): Save and restore selected windows of all frames.
Richard M. Stallman <rms@gnu.org>
parents:
46896
diff
changeset
|
41 (frame-list)))) |
43093
5b046c8a20a6
(save-selected-window): Move macro before first use.
Andreas Schwab <schwab@suse.de>
parents:
42876
diff
changeset
|
42 (unwind-protect |
5b046c8a20a6
(save-selected-window): Move macro before first use.
Andreas Schwab <schwab@suse.de>
parents:
42876
diff
changeset
|
43 (progn ,@body) |
48941
7262fd90146a
(save-selected-window): Save and restore selected windows of all frames.
Richard M. Stallman <rms@gnu.org>
parents:
46896
diff
changeset
|
44 (dolist (elt save-selected-window-alist) |
7262fd90146a
(save-selected-window): Save and restore selected windows of all frames.
Richard M. Stallman <rms@gnu.org>
parents:
46896
diff
changeset
|
45 (and (frame-live-p (car elt)) |
7262fd90146a
(save-selected-window): Save and restore selected windows of all frames.
Richard M. Stallman <rms@gnu.org>
parents:
46896
diff
changeset
|
46 (window-live-p (cadr elt)) |
7262fd90146a
(save-selected-window): Save and restore selected windows of all frames.
Richard M. Stallman <rms@gnu.org>
parents:
46896
diff
changeset
|
47 (set-frame-selected-window (car elt) (cadr elt)))) |
43093
5b046c8a20a6
(save-selected-window): Move macro before first use.
Andreas Schwab <schwab@suse.de>
parents:
42876
diff
changeset
|
48 (if (window-live-p save-selected-window-window) |
5b046c8a20a6
(save-selected-window): Move macro before first use.
Andreas Schwab <schwab@suse.de>
parents:
42876
diff
changeset
|
49 (select-window save-selected-window-window))))) |
5b046c8a20a6
(save-selected-window): Move macro before first use.
Andreas Schwab <schwab@suse.de>
parents:
42876
diff
changeset
|
50 |
42818
55ed8ccce828
(window-body-height): New function.
Richard M. Stallman <rms@gnu.org>
parents:
42307
diff
changeset
|
51 (defun window-body-height (&optional window) |
55ed8ccce828
(window-body-height): New function.
Richard M. Stallman <rms@gnu.org>
parents:
42307
diff
changeset
|
52 "Return number of lines in window WINDOW for actual buffer text. |
55ed8ccce828
(window-body-height): New function.
Richard M. Stallman <rms@gnu.org>
parents:
42307
diff
changeset
|
53 This does not include the mode line (if any) or the header line (if any)." |
55ed8ccce828
(window-body-height): New function.
Richard M. Stallman <rms@gnu.org>
parents:
42307
diff
changeset
|
54 (or window (setq window (selected-window))) |
42876
869e78e96e2a
(window-body-height): Handle minibuffer window specially.
Richard M. Stallman <rms@gnu.org>
parents:
42818
diff
changeset
|
55 (if (window-minibuffer-p window) |
869e78e96e2a
(window-body-height): Handle minibuffer window specially.
Richard M. Stallman <rms@gnu.org>
parents:
42818
diff
changeset
|
56 (window-height window) |
869e78e96e2a
(window-body-height): Handle minibuffer window specially.
Richard M. Stallman <rms@gnu.org>
parents:
42818
diff
changeset
|
57 (with-current-buffer (window-buffer window) |
869e78e96e2a
(window-body-height): Handle minibuffer window specially.
Richard M. Stallman <rms@gnu.org>
parents:
42818
diff
changeset
|
58 (max 1 (- (window-height window) |
869e78e96e2a
(window-body-height): Handle minibuffer window specially.
Richard M. Stallman <rms@gnu.org>
parents:
42818
diff
changeset
|
59 (if mode-line-format 1 0) |
869e78e96e2a
(window-body-height): Handle minibuffer window specially.
Richard M. Stallman <rms@gnu.org>
parents:
42818
diff
changeset
|
60 (if header-line-format 1 0)))))) |
42818
55ed8ccce828
(window-body-height): New function.
Richard M. Stallman <rms@gnu.org>
parents:
42307
diff
changeset
|
61 |
11086
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
62 (defun one-window-p (&optional nomini all-frames) |
33708
7c2b5397acbc
General comment and spacing fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33537
diff
changeset
|
63 "Return non-nil if the selected window is the only window (in its frame). |
11086
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
64 Optional arg NOMINI non-nil means don't count the minibuffer |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
65 even if it is active. |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
66 |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
67 The optional arg ALL-FRAMES t means count windows on all frames. |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
68 If it is `visible', count windows on all visible frames. |
33708
7c2b5397acbc
General comment and spacing fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33537
diff
changeset
|
69 ALL-FRAMES nil or omitted means count only the selected frame, |
11086
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
70 plus the minibuffer it uses (which may be on another frame). |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
71 If ALL-FRAMES is neither nil nor t, count only the selected frame." |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
72 (let ((base-window (selected-window))) |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
73 (if (and nomini (eq base-window (minibuffer-window))) |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
74 (setq base-window (next-window base-window))) |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
75 (eq base-window |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
76 (next-window base-window (if nomini 'arg) all-frames)))) |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
77 |
52615
de1a002c48c7
(window-current-scroll-bars): New defun.
Kim F. Storm <storm@cua.dk>
parents:
52481
diff
changeset
|
78 (defun window-current-scroll-bars (&optional window) |
de1a002c48c7
(window-current-scroll-bars): New defun.
Kim F. Storm <storm@cua.dk>
parents:
52481
diff
changeset
|
79 "Return the current scroll-bar settings in window WINDOW. |
de1a002c48c7
(window-current-scroll-bars): New defun.
Kim F. Storm <storm@cua.dk>
parents:
52481
diff
changeset
|
80 Value is a cons (VERTICAL . HORISONTAL) where VERTICAL specifies the |
de1a002c48c7
(window-current-scroll-bars): New defun.
Kim F. Storm <storm@cua.dk>
parents:
52481
diff
changeset
|
81 current location of the vertical scroll-bars (left, right, or nil), |
de1a002c48c7
(window-current-scroll-bars): New defun.
Kim F. Storm <storm@cua.dk>
parents:
52481
diff
changeset
|
82 and HORISONTAL specifies the current location of the horisontal scroll |
de1a002c48c7
(window-current-scroll-bars): New defun.
Kim F. Storm <storm@cua.dk>
parents:
52481
diff
changeset
|
83 bars (top, bottom, or nil)." |
de1a002c48c7
(window-current-scroll-bars): New defun.
Kim F. Storm <storm@cua.dk>
parents:
52481
diff
changeset
|
84 (let ((vert (nth 2 (window-scroll-bars window))) |
de1a002c48c7
(window-current-scroll-bars): New defun.
Kim F. Storm <storm@cua.dk>
parents:
52481
diff
changeset
|
85 (hor nil)) |
de1a002c48c7
(window-current-scroll-bars): New defun.
Kim F. Storm <storm@cua.dk>
parents:
52481
diff
changeset
|
86 (when (or (eq vert t) (eq hor t)) |
de1a002c48c7
(window-current-scroll-bars): New defun.
Kim F. Storm <storm@cua.dk>
parents:
52481
diff
changeset
|
87 (let ((fcsb (frame-current-scroll-bars |
de1a002c48c7
(window-current-scroll-bars): New defun.
Kim F. Storm <storm@cua.dk>
parents:
52481
diff
changeset
|
88 (window-frame (or window (selected-window)))))) |
de1a002c48c7
(window-current-scroll-bars): New defun.
Kim F. Storm <storm@cua.dk>
parents:
52481
diff
changeset
|
89 (if (eq vert t) |
de1a002c48c7
(window-current-scroll-bars): New defun.
Kim F. Storm <storm@cua.dk>
parents:
52481
diff
changeset
|
90 (setq vert (car fcsb))) |
de1a002c48c7
(window-current-scroll-bars): New defun.
Kim F. Storm <storm@cua.dk>
parents:
52481
diff
changeset
|
91 (if (eq hor t) |
de1a002c48c7
(window-current-scroll-bars): New defun.
Kim F. Storm <storm@cua.dk>
parents:
52481
diff
changeset
|
92 (setq hor (cdr fcsb))))) |
de1a002c48c7
(window-current-scroll-bars): New defun.
Kim F. Storm <storm@cua.dk>
parents:
52481
diff
changeset
|
93 (cons vert hor))) |
de1a002c48c7
(window-current-scroll-bars): New defun.
Kim F. Storm <storm@cua.dk>
parents:
52481
diff
changeset
|
94 |
11086
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
95 (defun walk-windows (proc &optional minibuf all-frames) |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
96 "Cycle through all visible windows, calling PROC for each one. |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
97 PROC is called with a window as argument. |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
98 |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
99 Optional second arg MINIBUF t means count the minibuffer window even |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
100 if not active. MINIBUF nil or omitted means count the minibuffer iff |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
101 it is active. MINIBUF neither t nor nil means not to count the |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
102 minibuffer even if it is active. |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
103 |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
104 Several frames may share a single minibuffer; if the minibuffer |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
105 counts, all windows on all frames that share that minibuffer count |
15057
3f71523422e9
(walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
14836
diff
changeset
|
106 too. Therefore, if you are using a separate minibuffer frame |
3f71523422e9
(walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
14836
diff
changeset
|
107 and the minibuffer is active and MINIBUF says it counts, |
11086
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
108 `walk-windows' includes the windows in the frame from which you |
15057
3f71523422e9
(walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
14836
diff
changeset
|
109 entered the minibuffer, as well as the minibuffer window. |
11086
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
110 |
11302
a9b5c1d727b7
(walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11149
diff
changeset
|
111 ALL-FRAMES is the optional third argument. |
a9b5c1d727b7
(walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11149
diff
changeset
|
112 ALL-FRAMES nil or omitted means cycle within the frames as specified above. |
a9b5c1d727b7
(walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11149
diff
changeset
|
113 ALL-FRAMES = `visible' means include windows on all visible frames. |
11086
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
114 ALL-FRAMES = 0 means include windows on all visible and iconified frames. |
11302
a9b5c1d727b7
(walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11149
diff
changeset
|
115 ALL-FRAMES = t means include windows on all frames including invisible frames. |
26268
6e6ad5d67263
(walk-windows): If ALL-FRAMES is a frame,
Gerd Moellmann <gerd@gnu.org>
parents:
25263
diff
changeset
|
116 If ALL-FRAMES is a frame, it means include windows on that frame. |
15076
5e9132ff1d88
(walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
15057
diff
changeset
|
117 Anything else means restrict to the selected frame." |
11086
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
118 ;; If we start from the minibuffer window, don't fail to come back to it. |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
119 (if (window-minibuffer-p (selected-window)) |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
120 (setq minibuf t)) |
26268
6e6ad5d67263
(walk-windows): If ALL-FRAMES is a frame,
Gerd Moellmann <gerd@gnu.org>
parents:
25263
diff
changeset
|
121 (save-selected-window |
6e6ad5d67263
(walk-windows): If ALL-FRAMES is a frame,
Gerd Moellmann <gerd@gnu.org>
parents:
25263
diff
changeset
|
122 (if (framep all-frames) |
6e6ad5d67263
(walk-windows): If ALL-FRAMES is a frame,
Gerd Moellmann <gerd@gnu.org>
parents:
25263
diff
changeset
|
123 (select-window (frame-first-window all-frames))) |
30005
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
124 (let* (walk-windows-already-seen |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
125 (walk-windows-current (selected-window))) |
26268
6e6ad5d67263
(walk-windows): If ALL-FRAMES is a frame,
Gerd Moellmann <gerd@gnu.org>
parents:
25263
diff
changeset
|
126 (while (progn |
6e6ad5d67263
(walk-windows): If ALL-FRAMES is a frame,
Gerd Moellmann <gerd@gnu.org>
parents:
25263
diff
changeset
|
127 (setq walk-windows-current |
6e6ad5d67263
(walk-windows): If ALL-FRAMES is a frame,
Gerd Moellmann <gerd@gnu.org>
parents:
25263
diff
changeset
|
128 (next-window walk-windows-current minibuf all-frames)) |
30005
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
129 (not (memq walk-windows-current walk-windows-already-seen))) |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
130 (setq walk-windows-already-seen |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
131 (cons walk-windows-current walk-windows-already-seen)) |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
132 (funcall proc walk-windows-current))))) |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
133 |
39172
9ba7895e6ad2
(get-window-with-predicate): Renamed from some-window.
Gerd Moellmann <gerd@gnu.org>
parents:
39117
diff
changeset
|
134 (defun get-window-with-predicate (predicate &optional minibuf |
9ba7895e6ad2
(get-window-with-predicate): Renamed from some-window.
Gerd Moellmann <gerd@gnu.org>
parents:
39117
diff
changeset
|
135 all-frames default) |
30005
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
136 "Return a window satisfying PREDICATE. |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
137 |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
138 This function cycles through all visible windows using `walk-windows', |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
139 calling PREDICATE on each one. PREDICATE is called with a window as |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
140 argument. The first window for which PREDICATE returns a non-nil |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
141 value is returned. If no window satisfies PREDICATE, DEFAULT is |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
142 returned. |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
143 |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
144 Optional second arg MINIBUF t means count the minibuffer window even |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
145 if not active. MINIBUF nil or omitted means count the minibuffer iff |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
146 it is active. MINIBUF neither t nor nil means not to count the |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
147 minibuffer even if it is active. |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
148 |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
149 Several frames may share a single minibuffer; if the minibuffer |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
150 counts, all windows on all frames that share that minibuffer count |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
151 too. Therefore, if you are using a separate minibuffer frame |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
152 and the minibuffer is active and MINIBUF says it counts, |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
153 `walk-windows' includes the windows in the frame from which you |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
154 entered the minibuffer, as well as the minibuffer window. |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
155 |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
156 ALL-FRAMES is the optional third argument. |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
157 ALL-FRAMES nil or omitted means cycle within the frames as specified above. |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
158 ALL-FRAMES = `visible' means include windows on all visible frames. |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
159 ALL-FRAMES = 0 means include windows on all visible and iconified frames. |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
160 ALL-FRAMES = t means include windows on all frames including invisible frames. |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
161 If ALL-FRAMES is a frame, it means include windows on that frame. |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
162 Anything else means restrict to the selected frame." |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
163 (catch 'found |
33708
7c2b5397acbc
General comment and spacing fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33537
diff
changeset
|
164 (walk-windows #'(lambda (window) |
30005
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
165 (when (funcall predicate window) |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
166 (throw 'found window))) |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
167 minibuf all-frames) |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
168 default)) |
11086
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
169 |
39172
9ba7895e6ad2
(get-window-with-predicate): Renamed from some-window.
Gerd Moellmann <gerd@gnu.org>
parents:
39117
diff
changeset
|
170 (defalias 'some-window 'get-window-with-predicate) |
9ba7895e6ad2
(get-window-with-predicate): Renamed from some-window.
Gerd Moellmann <gerd@gnu.org>
parents:
39117
diff
changeset
|
171 |
11086
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
172 (defun minibuffer-window-active-p (window) |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
173 "Return t if WINDOW (a minibuffer window) is now active." |
11149
8904c26c2182
(minibuffer-window-active-p): Use active-minibuffer-window.
Richard M. Stallman <rms@gnu.org>
parents:
11086
diff
changeset
|
174 (eq window (active-minibuffer-window))) |
11086
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
175 |
36 | 176 (defun count-windows (&optional minibuf) |
33708
7c2b5397acbc
General comment and spacing fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33537
diff
changeset
|
177 "Return the number of visible windows. |
22328
874f007a7d9c
(shrink-window-if-larger-than-buffer):
Karl Heuer <kwzh@gnu.org>
parents:
22216
diff
changeset
|
178 This counts the windows in the selected frame and (if the minibuffer is |
874f007a7d9c
(shrink-window-if-larger-than-buffer):
Karl Heuer <kwzh@gnu.org>
parents:
22216
diff
changeset
|
179 to be counted) its minibuffer frame (if that's not the same frame). |
874f007a7d9c
(shrink-window-if-larger-than-buffer):
Karl Heuer <kwzh@gnu.org>
parents:
22216
diff
changeset
|
180 The optional arg MINIBUF non-nil means count the minibuffer |
14836 | 181 even if it is inactive." |
36 | 182 (let ((count 0)) |
3375
13ddc81f0b43
(count-windows): PROC argument of walk-windows takes an argument.
Richard M. Stallman <rms@gnu.org>
parents:
3342
diff
changeset
|
183 (walk-windows (function (lambda (w) |
36 | 184 (setq count (+ count 1)))) |
185 minibuf) | |
186 count)) | |
187 | |
33708
7c2b5397acbc
General comment and spacing fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33537
diff
changeset
|
188 (defun window-safely-shrinkable-p (&optional window) |
36366
62272f68e460
(fit-window-to-buffer, window-safely-shrinkable-p)
Eli Zaretskii <eliz@gnu.org>
parents:
34580
diff
changeset
|
189 "Non-nil if the WINDOW can be shrunk without shrinking other windows. |
62272f68e460
(fit-window-to-buffer, window-safely-shrinkable-p)
Eli Zaretskii <eliz@gnu.org>
parents:
34580
diff
changeset
|
190 If WINDOW is nil or omitted, it defaults to the currently selected window." |
53894
0a356c1b7057
(window-safely-shrinkable-p): Don't change the buffer-list.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52615
diff
changeset
|
191 (with-selected-window (or window (selected-window)) |
0a356c1b7057
(window-safely-shrinkable-p): Don't change the buffer-list.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52615
diff
changeset
|
192 (let ((edges (window-edges))) |
0a356c1b7057
(window-safely-shrinkable-p): Don't change the buffer-list.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52615
diff
changeset
|
193 (or (= (nth 2 edges) (nth 2 (window-edges (previous-window)))) |
0a356c1b7057
(window-safely-shrinkable-p): Don't change the buffer-list.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52615
diff
changeset
|
194 (= (nth 0 edges) (nth 0 (window-edges (next-window)))))))) |
0a356c1b7057
(window-safely-shrinkable-p): Don't change the buffer-list.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52615
diff
changeset
|
195 |
33708
7c2b5397acbc
General comment and spacing fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33537
diff
changeset
|
196 |
36 | 197 (defun balance-windows () |
33708
7c2b5397acbc
General comment and spacing fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33537
diff
changeset
|
198 "Make all visible windows the same height (approximately)." |
36 | 199 (interactive) |
42307
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
200 (let ((count -1) levels newsizes level-size |
13523
75c6a5e1ee7a
(balance-windows): Don't count the menu bar's lines in the frame height.
Richard M. Stallman <rms@gnu.org>
parents:
12184
diff
changeset
|
201 ;; Don't count the lines that are above the uppermost windows. |
75c6a5e1ee7a
(balance-windows): Don't count the menu bar's lines in the frame height.
Richard M. Stallman <rms@gnu.org>
parents:
12184
diff
changeset
|
202 ;; (These are the menu bar lines, if any.) |
42307
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
203 (mbl (nth 1 (window-edges (frame-first-window (selected-frame))))) |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
204 (last-window (previous-window (frame-first-window (selected-frame)))) |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
205 ;; Don't count the lines that are past the lowest main window. |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
206 total) |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
207 ;; Bottom edge of last window determines what size we have to work with. |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
208 (setq total |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
209 (+ (window-height last-window) |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
210 (nth 1 (window-edges last-window)))) |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
211 |
3724
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
212 ;; Find all the different vpos's at which windows start, |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
213 ;; then count them. But ignore levels that differ by only 1. |
42307
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
214 (let (tops (prev-top -2)) |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
215 (walk-windows (function (lambda (w) |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
216 (setq tops (cons (nth 1 (window-edges w)) |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
217 tops)))) |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
218 'nomini) |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
219 (setq tops (sort tops '<)) |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
220 (while tops |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
221 (if (> (car tops) (1+ prev-top)) |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
222 (setq prev-top (car tops) |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
223 count (1+ count))) |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
224 (setq levels (cons (cons (car tops) count) levels)) |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
225 (setq tops (cdr tops))) |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
226 (setq count (1+ count))) |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
227 ;; Subdivide the frame into desired number of vertical levels. |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
228 (setq level-size (/ (- total mbl) count)) |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
229 (save-selected-window |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
230 ;; Set up NEWSIZES to map windows to their desired sizes. |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
231 ;; If a window ends at the bottom level, don't include |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
232 ;; it in NEWSIZES. Those windows get the right sizes |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
233 ;; by adjusting the ones above them. |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
234 (walk-windows (function |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
235 (lambda (w) |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
236 (let ((newtop (cdr (assq (nth 1 (window-edges w)) |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
237 levels))) |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
238 (newbot (cdr (assq (+ (window-height w) |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
239 (nth 1 (window-edges w))) |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
240 levels)))) |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
241 (if newbot |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
242 (setq newsizes |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
243 (cons (cons w (* level-size (- newbot newtop))) |
43095
917bf04536ab
(balance-windows): Fix misplaced parenthesis.
Andreas Schwab <schwab@suse.de>
parents:
43093
diff
changeset
|
244 newsizes)))))) |
42307
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
245 'nomini) |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
246 ;; Make walk-windows start with the topmost window. |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
247 (select-window (previous-window (frame-first-window (selected-frame)))) |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
248 (let (done (count 0)) |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
249 ;; Give each window its precomputed size, or at least try. |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
250 ;; Keep trying until they all get the intended sizes, |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
251 ;; but not more than 3 times (to prevent infinite loop). |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
252 (while (and (not done) (< count 3)) |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
253 (setq done t) |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
254 (setq count (1+ count)) |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
255 (walk-windows (function (lambda (w) |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
256 (select-window w) |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
257 (let ((newsize (cdr (assq w newsizes)))) |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
258 (when newsize |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
259 (enlarge-window (- newsize |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
260 (window-height)) |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
261 nil t) |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
262 (unless (= (window-height) newsize) |
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
263 (setq done nil)))))) |
43095
917bf04536ab
(balance-windows): Fix misplaced parenthesis.
Andreas Schwab <schwab@suse.de>
parents:
43093
diff
changeset
|
264 'nomini)))))) |
11086
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
265 |
46896
549bdeb52a93
(split-window-save-restore-data): Use push and with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44297
diff
changeset
|
266 ;; I think this should be the default; I think people will prefer it--rms. |
17665 | 267 (defcustom split-window-keep-point t |
3724
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
268 "*If non-nil, split windows keeps the original point in both children. |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
269 This is often more convenient for editing. |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
270 If nil, adjust point in each of the two windows to minimize redisplay. |
17665 | 271 This is convenient on slow terminals, but point can move strangely." |
272 :type 'boolean | |
273 :group 'windows) | |
382 | 274 |
36 | 275 (defun split-window-vertically (&optional arg) |
276 "Split current window into two windows, one above the other. | |
108 | 277 The uppermost window gets ARG lines and the other gets the rest. |
6670
b2c5fca3c10c
(split-window-vertically): If size is negative, measure from bottom.
Karl Heuer <kwzh@gnu.org>
parents:
6019
diff
changeset
|
278 Negative arg means select the size of the lowermost window instead. |
108 | 279 With no argument, split equally or close to it. |
280 Both windows display the same buffer now current. | |
382 | 281 |
22216
5750539e01e7
(split-window-vertically): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
21970
diff
changeset
|
282 If the variable `split-window-keep-point' is non-nil, both new windows |
382 | 283 will get the same value of point as the current window. This is often |
284 more convenient for editing. | |
108 | 285 |
382 | 286 Otherwise, we chose window starts so as to minimize the amount of |
287 redisplay; this is convenient on slow terminals. The new selected | |
288 window is the one that the current value of point appears in. The | |
289 value of point can change if the text around point is hidden by the | |
290 new mode line." | |
36 | 291 (interactive "P") |
292 (let ((old-w (selected-window)) | |
108 | 293 (old-point (point)) |
6670
b2c5fca3c10c
(split-window-vertically): If size is negative, measure from bottom.
Karl Heuer <kwzh@gnu.org>
parents:
6019
diff
changeset
|
294 (size (and arg (prefix-numeric-value arg))) |
13854
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
295 (window-full-p nil) |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
296 new-w bottom switch moved) |
6670
b2c5fca3c10c
(split-window-vertically): If size is negative, measure from bottom.
Karl Heuer <kwzh@gnu.org>
parents:
6019
diff
changeset
|
297 (and size (< size 0) (setq size (+ (window-height) size))) |
b2c5fca3c10c
(split-window-vertically): If size is negative, measure from bottom.
Karl Heuer <kwzh@gnu.org>
parents:
6019
diff
changeset
|
298 (setq new-w (split-window nil size)) |
419 | 299 (or split-window-keep-point |
108 | 300 (progn |
382 | 301 (save-excursion |
302 (set-buffer (window-buffer)) | |
303 (goto-char (window-start)) | |
13854
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
304 (setq moved (vertical-motion (window-height))) |
382 | 305 (set-window-start new-w (point)) |
306 (if (> (point) (window-point new-w)) | |
307 (set-window-point new-w (point))) | |
13854
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
308 (and (= moved (window-height)) |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
309 (progn |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
310 (setq window-full-p t) |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
311 (vertical-motion -1))) |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
312 (setq bottom (point))) |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
313 (and window-full-p |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
314 (<= bottom (point)) |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
315 (set-window-point old-w (1- bottom))) |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
316 (and window-full-p |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
317 (<= (window-start new-w) old-point) |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
318 (progn |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
319 (set-window-point new-w old-point) |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
320 (select-window new-w))))) |
18279
a9c40a80c9b1
(split-window-save-restore-data): New function that
Richard M. Stallman <rms@gnu.org>
parents:
17665
diff
changeset
|
321 (split-window-save-restore-data new-w old-w))) |
a9c40a80c9b1
(split-window-save-restore-data): New function that
Richard M. Stallman <rms@gnu.org>
parents:
17665
diff
changeset
|
322 |
21118
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
323 ;; This is to avoid compiler warnings. |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
324 (defvar view-return-to-alist) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
325 |
18279
a9c40a80c9b1
(split-window-save-restore-data): New function that
Richard M. Stallman <rms@gnu.org>
parents:
17665
diff
changeset
|
326 (defun split-window-save-restore-data (new-w old-w) |
46896
549bdeb52a93
(split-window-save-restore-data): Use push and with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44297
diff
changeset
|
327 (with-current-buffer (window-buffer) |
18279
a9c40a80c9b1
(split-window-save-restore-data): New function that
Richard M. Stallman <rms@gnu.org>
parents:
17665
diff
changeset
|
328 (if view-mode |
a9c40a80c9b1
(split-window-save-restore-data): New function that
Richard M. Stallman <rms@gnu.org>
parents:
17665
diff
changeset
|
329 (let ((old-info (assq old-w view-return-to-alist))) |
55015
10dc0a48bc2c
(split-window-save-restore-data):
Richard M. Stallman <rms@gnu.org>
parents:
53894
diff
changeset
|
330 (if old-info |
10dc0a48bc2c
(split-window-save-restore-data):
Richard M. Stallman <rms@gnu.org>
parents:
53894
diff
changeset
|
331 (push (cons new-w (cons (car (cdr old-info)) t)) |
10dc0a48bc2c
(split-window-save-restore-data):
Richard M. Stallman <rms@gnu.org>
parents:
53894
diff
changeset
|
332 view-return-to-alist)))) |
3253
f4d37be94734
(split-window-vertically): Return the new window.
Richard M. Stallman <rms@gnu.org>
parents:
2529
diff
changeset
|
333 new-w)) |
36 | 334 |
335 (defun split-window-horizontally (&optional arg) | |
336 "Split current window into two windows side by side. | |
8565
2a2208286955
(split-window-horizontally): If size is negative, measure from the right.
Karl Heuer <kwzh@gnu.org>
parents:
7300
diff
changeset
|
337 This window becomes the leftmost of the two, and gets ARG columns. |
2a2208286955
(split-window-horizontally): If size is negative, measure from the right.
Karl Heuer <kwzh@gnu.org>
parents:
7300
diff
changeset
|
338 Negative arg means select the size of the rightmost window instead. |
22924
13888875bea1
(split-window-horizontally): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
22328
diff
changeset
|
339 The argument includes the width of the window's scroll bar; if there |
13888875bea1
(split-window-horizontally): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
22328
diff
changeset
|
340 are no scroll bars, it includes the width of the divider column |
13888875bea1
(split-window-horizontally): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
22328
diff
changeset
|
341 to the window's right, if any. No arg means split equally." |
36 | 342 (interactive "P") |
18279
a9c40a80c9b1
(split-window-save-restore-data): New function that
Richard M. Stallman <rms@gnu.org>
parents:
17665
diff
changeset
|
343 (let ((old-w (selected-window)) |
a9c40a80c9b1
(split-window-save-restore-data): New function that
Richard M. Stallman <rms@gnu.org>
parents:
17665
diff
changeset
|
344 (size (and arg (prefix-numeric-value arg)))) |
8565
2a2208286955
(split-window-horizontally): If size is negative, measure from the right.
Karl Heuer <kwzh@gnu.org>
parents:
7300
diff
changeset
|
345 (and size (< size 0) |
2a2208286955
(split-window-horizontally): If size is negative, measure from the right.
Karl Heuer <kwzh@gnu.org>
parents:
7300
diff
changeset
|
346 (setq size (+ (window-width) size))) |
18279
a9c40a80c9b1
(split-window-save-restore-data): New function that
Richard M. Stallman <rms@gnu.org>
parents:
17665
diff
changeset
|
347 (split-window-save-restore-data (split-window nil size t) old-w))) |
32689
9f29610841ca
(window-text-height, set-window-text-height): New functions.
Miles Bader <miles@gnu.org>
parents:
32684
diff
changeset
|
348 |
9f29610841ca
(window-text-height, set-window-text-height): New functions.
Miles Bader <miles@gnu.org>
parents:
32684
diff
changeset
|
349 |
9f29610841ca
(window-text-height, set-window-text-height): New functions.
Miles Bader <miles@gnu.org>
parents:
32684
diff
changeset
|
350 (defun set-window-text-height (window height) |
9f29610841ca
(window-text-height, set-window-text-height): New functions.
Miles Bader <miles@gnu.org>
parents:
32684
diff
changeset
|
351 "Sets the height in lines of the text display area of WINDOW to HEIGHT. |
9f29610841ca
(window-text-height, set-window-text-height): New functions.
Miles Bader <miles@gnu.org>
parents:
32684
diff
changeset
|
352 This doesn't include the mode-line (or header-line if any) or any |
9f29610841ca
(window-text-height, set-window-text-height): New functions.
Miles Bader <miles@gnu.org>
parents:
32684
diff
changeset
|
353 partial-height lines in the text display area. |
9f29610841ca
(window-text-height, set-window-text-height): New functions.
Miles Bader <miles@gnu.org>
parents:
32684
diff
changeset
|
354 |
9f29610841ca
(window-text-height, set-window-text-height): New functions.
Miles Bader <miles@gnu.org>
parents:
32684
diff
changeset
|
355 If WINDOW is nil, the selected window is used. |
9f29610841ca
(window-text-height, set-window-text-height): New functions.
Miles Bader <miles@gnu.org>
parents:
32684
diff
changeset
|
356 |
9f29610841ca
(window-text-height, set-window-text-height): New functions.
Miles Bader <miles@gnu.org>
parents:
32684
diff
changeset
|
357 Note that the current implementation of this function cannot always set |
9f29610841ca
(window-text-height, set-window-text-height): New functions.
Miles Bader <miles@gnu.org>
parents:
32684
diff
changeset
|
358 the height exactly, but attempts to be conservative, by allocating more |
9f29610841ca
(window-text-height, set-window-text-height): New functions.
Miles Bader <miles@gnu.org>
parents:
32684
diff
changeset
|
359 lines than are actually needed in the case where some error may be present." |
9f29610841ca
(window-text-height, set-window-text-height): New functions.
Miles Bader <miles@gnu.org>
parents:
32684
diff
changeset
|
360 (let ((delta (- height (window-text-height window)))) |
9f29610841ca
(window-text-height, set-window-text-height): New functions.
Miles Bader <miles@gnu.org>
parents:
32684
diff
changeset
|
361 (unless (zerop delta) |
32695
5a4f1fbd4ed7
(set-window-text-height): Force window-min-height to 1.
Miles Bader <miles@gnu.org>
parents:
32689
diff
changeset
|
362 (let ((window-min-height 1)) |
5a4f1fbd4ed7
(set-window-text-height): Force window-min-height to 1.
Miles Bader <miles@gnu.org>
parents:
32689
diff
changeset
|
363 (if (and window (not (eq window (selected-window)))) |
5a4f1fbd4ed7
(set-window-text-height): Force window-min-height to 1.
Miles Bader <miles@gnu.org>
parents:
32689
diff
changeset
|
364 (save-selected-window |
5a4f1fbd4ed7
(set-window-text-height): Force window-min-height to 1.
Miles Bader <miles@gnu.org>
parents:
32689
diff
changeset
|
365 (select-window window) |
5a4f1fbd4ed7
(set-window-text-height): Force window-min-height to 1.
Miles Bader <miles@gnu.org>
parents:
32689
diff
changeset
|
366 (enlarge-window delta)) |
5a4f1fbd4ed7
(set-window-text-height): Force window-min-height to 1.
Miles Bader <miles@gnu.org>
parents:
32689
diff
changeset
|
367 (enlarge-window delta)))))) |
32689
9f29610841ca
(window-text-height, set-window-text-height): New functions.
Miles Bader <miles@gnu.org>
parents:
32684
diff
changeset
|
368 |
32681
569ef1445e17
(mode-line-window-height-fudge): New variable.
Miles Bader <miles@gnu.org>
parents:
31790
diff
changeset
|
369 |
36 | 370 (defun enlarge-window-horizontally (arg) |
371 "Make current window ARG columns wider." | |
372 (interactive "p") | |
373 (enlarge-window arg t)) | |
374 | |
375 (defun shrink-window-horizontally (arg) | |
376 "Make current window ARG columns narrower." | |
377 (interactive "p") | |
378 (shrink-window arg t)) | |
379 | |
23748
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
380 (defun window-buffer-height (window) |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
381 "Return the height (in screen lines) of the buffer that WINDOW is displaying." |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
382 (save-excursion |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
383 (set-buffer (window-buffer window)) |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
384 (goto-char (point-min)) |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
385 (let ((ignore-final-newline |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
386 ;; If buffer ends with a newline, ignore it when counting height |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
387 ;; unless point is after it. |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
388 (and (not (eobp)) (eq ?\n (char-after (1- (point-max))))))) |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
389 (+ 1 (nth 2 (compute-motion (point-min) |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
390 '(0 . 0) |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
391 (- (point-max) (if ignore-final-newline 1 0)) |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
392 (cons 0 100000000) |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
393 (window-width window) |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
394 nil |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
395 window)))))) |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
396 |
28655
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
397 (defun count-screen-lines (&optional beg end count-final-newline window) |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
398 "Return the number of screen lines in the region. |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
399 The number of screen lines may be different from the number of actual lines, |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
400 due to line breaking, display table, etc. |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
401 |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
402 Optional arguments BEG and END default to `point-min' and `point-max' |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
403 respectively. |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
404 |
33708
7c2b5397acbc
General comment and spacing fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33537
diff
changeset
|
405 If region ends with a newline, ignore it unless optional third argument |
28655
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
406 COUNT-FINAL-NEWLINE is non-nil. |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
407 |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
408 The optional fourth argument WINDOW specifies the window used for obtaining |
33708
7c2b5397acbc
General comment and spacing fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33537
diff
changeset
|
409 parameters such as width, horizontal scrolling, and so on. The default is |
28655
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
410 to use the selected window's parameters. |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
411 |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
412 Like `vertical-motion', `count-screen-lines' always uses the current buffer, |
33708
7c2b5397acbc
General comment and spacing fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33537
diff
changeset
|
413 regardless of which buffer is displayed in WINDOW. This makes possible to use |
28655
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
414 `count-screen-lines' in any buffer, whether or not it is currently displayed |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
415 in some window." |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
416 (unless beg |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
417 (setq beg (point-min))) |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
418 (unless end |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
419 (setq end (point-max))) |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
420 (if (= beg end) |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
421 0 |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
422 (save-excursion |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
423 (save-restriction |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
424 (widen) |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
425 (narrow-to-region (min beg end) |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
426 (if (and (not count-final-newline) |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
427 (= ?\n (char-before (max beg end)))) |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
428 (1- (max beg end)) |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
429 (max beg end))) |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
430 (goto-char (point-min)) |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
431 (1+ (vertical-motion (buffer-size) window)))))) |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
432 |
32705
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
433 (defun fit-window-to-buffer (&optional window max-height min-height) |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
434 "Make WINDOW the right size to display its contents exactly. |
36366
62272f68e460
(fit-window-to-buffer, window-safely-shrinkable-p)
Eli Zaretskii <eliz@gnu.org>
parents:
34580
diff
changeset
|
435 If WINDOW is omitted or nil, it defaults to the selected window. |
32705
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
436 If the optional argument MAX-HEIGHT is supplied, it is the maximum height |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
437 the window is allowed to be, defaulting to the frame height. |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
438 If the optional argument MIN-HEIGHT is supplied, it is the minimum |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
439 height the window is allowed to be, defaulting to `window-min-height'. |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
440 |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
441 The heights in MAX-HEIGHT and MIN-HEIGHT include the mode-line and/or |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
442 header-line." |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
443 (interactive) |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
444 |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
445 (when (null window) |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
446 (setq window (selected-window))) |
32737
29a87f28cd51
(fit-window-to-buffer): Change defaulting of MAX-HEIGHT slightly.
Miles Bader <miles@gnu.org>
parents:
32736
diff
changeset
|
447 (when (null max-height) |
29a87f28cd51
(fit-window-to-buffer): Change defaulting of MAX-HEIGHT slightly.
Miles Bader <miles@gnu.org>
parents:
32736
diff
changeset
|
448 (setq max-height (frame-height (window-frame window)))) |
32705
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
449 |
33478
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
450 (let* ((buf |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
451 ;; Buffer that is displayed in WINDOW |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
452 (window-buffer window)) |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
453 (window-height |
32705
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
454 ;; The current height of WINDOW |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
455 (window-height window)) |
33478
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
456 (desired-height |
32705
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
457 ;; The height necessary to show the buffer displayed by WINDOW |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
458 ;; (`count-screen-lines' always works on the current buffer). |
33478
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
459 (with-current-buffer buf |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
460 (+ (count-screen-lines) |
33536
035e7b097577
(fit-window-to-buffer): Be sure to acquire at least
Kenichi Handa <handa@m17n.org>
parents:
33478
diff
changeset
|
461 ;; If the buffer is empty, (count-screen-lines) is |
035e7b097577
(fit-window-to-buffer): Be sure to acquire at least
Kenichi Handa <handa@m17n.org>
parents:
33478
diff
changeset
|
462 ;; zero. But, even in that case, we need one text line |
035e7b097577
(fit-window-to-buffer): Be sure to acquire at least
Kenichi Handa <handa@m17n.org>
parents:
33478
diff
changeset
|
463 ;; for cursor. |
035e7b097577
(fit-window-to-buffer): Be sure to acquire at least
Kenichi Handa <handa@m17n.org>
parents:
33478
diff
changeset
|
464 (if (= (point-min) (point-max)) |
035e7b097577
(fit-window-to-buffer): Be sure to acquire at least
Kenichi Handa <handa@m17n.org>
parents:
33478
diff
changeset
|
465 1 0) |
33478
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
466 ;; For non-minibuffers, count the mode-line, if any |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
467 (if (and (not (window-minibuffer-p window)) |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
468 mode-line-format) |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
469 1 0) |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
470 ;; Count the header-line, if any |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
471 (if header-line-format 1 0)))) |
32705
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
472 (delta |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
473 ;; Calculate how much the window height has to change to show |
33478
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
474 ;; desired-height lines, constrained by MIN-HEIGHT and MAX-HEIGHT. |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
475 (- (max (min desired-height max-height) |
32705
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
476 (or min-height window-min-height)) |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
477 window-height)) |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
478 ;; We do our own height checking, so avoid any restrictions due to |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
479 ;; window-min-height. |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
480 (window-min-height 1)) |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
481 |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
482 ;; Don't try to redisplay with the cursor at the end |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
483 ;; on its own line--that would force a scroll and spoil things. |
33478
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
484 (when (with-current-buffer buf |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
485 (and (eobp) (bolp) (not (bobp)))) |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
486 (set-window-point window (1- (window-point window)))) |
32705
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
487 |
33478
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
488 (save-selected-window |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
489 (select-window window) |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
490 |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
491 ;; Adjust WINDOW to the nominally correct size (which may actually |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
492 ;; be slightly off because of variable height text, etc). |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
493 (unless (zerop delta) |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
494 (enlarge-window delta)) |
33475
b18c7c71cf2e
(fit-window-to-buffer): Don't check
Kenichi Handa <handa@m17n.org>
parents:
32811
diff
changeset
|
495 |
33478
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
496 ;; Check if the last line is surely fully visible. If not, |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
497 ;; enlarge the window. |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
498 (let ((end (with-current-buffer buf |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
499 (save-excursion |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
500 (goto-char (point-max)) |
34079
6316cacc1e16
(fit-window-to-buffer): Handle non-nil `truncate-lines'.
Miles Bader <miles@gnu.org>
parents:
33708
diff
changeset
|
501 (when (and (bolp) (not (bobp))) |
6316cacc1e16
(fit-window-to-buffer): Handle non-nil `truncate-lines'.
Miles Bader <miles@gnu.org>
parents:
33708
diff
changeset
|
502 ;; Don't include final newline |
6316cacc1e16
(fit-window-to-buffer): Handle non-nil `truncate-lines'.
Miles Bader <miles@gnu.org>
parents:
33708
diff
changeset
|
503 (backward-char 1)) |
6316cacc1e16
(fit-window-to-buffer): Handle non-nil `truncate-lines'.
Miles Bader <miles@gnu.org>
parents:
33708
diff
changeset
|
504 (when truncate-lines |
6316cacc1e16
(fit-window-to-buffer): Handle non-nil `truncate-lines'.
Miles Bader <miles@gnu.org>
parents:
33708
diff
changeset
|
505 ;; If line-wrapping is turned off, test the |
6316cacc1e16
(fit-window-to-buffer): Handle non-nil `truncate-lines'.
Miles Bader <miles@gnu.org>
parents:
33708
diff
changeset
|
506 ;; beginning of the last line for visibility |
6316cacc1e16
(fit-window-to-buffer): Handle non-nil `truncate-lines'.
Miles Bader <miles@gnu.org>
parents:
33708
diff
changeset
|
507 ;; instead of the end, as the end of the line |
6316cacc1e16
(fit-window-to-buffer): Handle non-nil `truncate-lines'.
Miles Bader <miles@gnu.org>
parents:
33708
diff
changeset
|
508 ;; could be invisible by virtue of extending past |
6316cacc1e16
(fit-window-to-buffer): Handle non-nil `truncate-lines'.
Miles Bader <miles@gnu.org>
parents:
33708
diff
changeset
|
509 ;; the edge of the window. |
6316cacc1e16
(fit-window-to-buffer): Handle non-nil `truncate-lines'.
Miles Bader <miles@gnu.org>
parents:
33708
diff
changeset
|
510 (forward-line 0)) |
6316cacc1e16
(fit-window-to-buffer): Handle non-nil `truncate-lines'.
Miles Bader <miles@gnu.org>
parents:
33708
diff
changeset
|
511 (point))))) |
33478
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
512 (set-window-vscroll window 0) |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
513 (while (and (< desired-height max-height) |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
514 (= desired-height (window-height window)) |
34383
87e249cf993b
(fit-window-to-buffer): Don't pass last argument to
Miles Bader <miles@gnu.org>
parents:
34079
diff
changeset
|
515 (not (pos-visible-in-window-p end window))) |
33478
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
516 (enlarge-window 1) |
33537
53c51fd75027
(fit-window-to-buffer): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
33536
diff
changeset
|
517 (setq desired-height (1+ desired-height))))))) |
32705
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
518 |
2529
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
519 (defun shrink-window-if-larger-than-buffer (&optional window) |
3342
ce8aa0ba8b08
(shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents:
3253
diff
changeset
|
520 "Shrink the WINDOW to be as small as possible to display its contents. |
36366
62272f68e460
(fit-window-to-buffer, window-safely-shrinkable-p)
Eli Zaretskii <eliz@gnu.org>
parents:
34580
diff
changeset
|
521 If WINDOW is omitted or nil, it defaults to the selected window. |
8721
c94f87ea8a1b
(shrink-window-if-larger-than-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
8672
diff
changeset
|
522 Do not shrink to less than `window-min-height' lines. |
3342
ce8aa0ba8b08
(shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents:
3253
diff
changeset
|
523 Do nothing if the buffer contains more lines than the present window height, |
4364
69e5c2373d37
(shrink-window-if-larger-than-buffer): Do nothing if the
Richard M. Stallman <rms@gnu.org>
parents:
3724
diff
changeset
|
524 or if some of the window's contents are scrolled out of view, |
33708
7c2b5397acbc
General comment and spacing fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33537
diff
changeset
|
525 or if shrinking this window would also shrink another window. |
7c2b5397acbc
General comment and spacing fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33537
diff
changeset
|
526 or if the window is the only window of its frame. |
7c2b5397acbc
General comment and spacing fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33537
diff
changeset
|
527 Return non-nil if the window was shrunk." |
3342
ce8aa0ba8b08
(shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents:
3253
diff
changeset
|
528 (interactive) |
32705
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
529 (when (null window) |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
530 (setq window (selected-window))) |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
531 (let* ((frame (window-frame window)) |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
532 (mini (frame-parameter frame 'minibuffer)) |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
533 (edges (window-edges window))) |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
534 (if (and (not (eq window (frame-root-window frame))) |
33708
7c2b5397acbc
General comment and spacing fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33537
diff
changeset
|
535 (window-safely-shrinkable-p) |
32705
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
536 (pos-visible-in-window-p (point-min) window) |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
537 (not (eq mini 'only)) |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
538 (or (not mini) |
36666
2b284278da9c
(shrink-window-if-larger-than-buffer): Handle frame
Gerd Moellmann <gerd@gnu.org>
parents:
36366
diff
changeset
|
539 (let ((mini-window (minibuffer-window frame))) |
2b284278da9c
(shrink-window-if-larger-than-buffer): Handle frame
Gerd Moellmann <gerd@gnu.org>
parents:
36366
diff
changeset
|
540 (or (null mini-window) |
2b284278da9c
(shrink-window-if-larger-than-buffer): Handle frame
Gerd Moellmann <gerd@gnu.org>
parents:
36366
diff
changeset
|
541 (not (eq frame (window-frame mini-window))) |
2b284278da9c
(shrink-window-if-larger-than-buffer): Handle frame
Gerd Moellmann <gerd@gnu.org>
parents:
36366
diff
changeset
|
542 (< (nth 3 edges) |
2b284278da9c
(shrink-window-if-larger-than-buffer): Handle frame
Gerd Moellmann <gerd@gnu.org>
parents:
36366
diff
changeset
|
543 (nth 1 (window-edges mini-window))) |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48941
diff
changeset
|
544 (> (nth 1 edges) |
36666
2b284278da9c
(shrink-window-if-larger-than-buffer): Handle frame
Gerd Moellmann <gerd@gnu.org>
parents:
36366
diff
changeset
|
545 (frame-parameter frame 'menu-bar-lines)))))) |
32705
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
546 (fit-window-to-buffer window (window-height window))))) |
16469
479c96f4be3a
(kill-buffer-and-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
15076
diff
changeset
|
547 |
479c96f4be3a
(kill-buffer-and-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
15076
diff
changeset
|
548 (defun kill-buffer-and-window () |
479c96f4be3a
(kill-buffer-and-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
15076
diff
changeset
|
549 "Kill the current buffer and delete the selected window." |
479c96f4be3a
(kill-buffer-and-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
15076
diff
changeset
|
550 (interactive) |
52481
f1cce2846e29
(kill-buffer-and-window): Remove `yes-or-no-p' so that
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
551 (let ((window-to-delete (selected-window)) |
f1cce2846e29
(kill-buffer-and-window): Remove `yes-or-no-p' so that
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
552 (delete-window-hook (lambda () |
f1cce2846e29
(kill-buffer-and-window): Remove `yes-or-no-p' so that
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
553 (condition-case nil |
f1cce2846e29
(kill-buffer-and-window): Remove `yes-or-no-p' so that
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
554 (delete-window) |
f1cce2846e29
(kill-buffer-and-window): Remove `yes-or-no-p' so that
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
555 (error nil))))) |
f1cce2846e29
(kill-buffer-and-window): Remove `yes-or-no-p' so that
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
556 (add-hook 'kill-buffer-hook delete-window-hook t t) |
f1cce2846e29
(kill-buffer-and-window): Remove `yes-or-no-p' so that
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
557 (if (kill-buffer (current-buffer)) |
f1cce2846e29
(kill-buffer-and-window): Remove `yes-or-no-p' so that
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
558 ;; If `delete-window' failed before, we rerun it to regenerate |
f1cce2846e29
(kill-buffer-and-window): Remove `yes-or-no-p' so that
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
559 ;; the error so it can be seen in the minibuffer. |
f1cce2846e29
(kill-buffer-and-window): Remove `yes-or-no-p' so that
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
560 (when (eq (selected-window) window-to-delete) |
f1cce2846e29
(kill-buffer-and-window): Remove `yes-or-no-p' so that
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
561 (delete-window)) |
f1cce2846e29
(kill-buffer-and-window): Remove `yes-or-no-p' so that
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
562 (remove-hook 'kill-buffer-hook delete-window-hook t)))) |
16469
479c96f4be3a
(kill-buffer-and-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
15076
diff
changeset
|
563 |
21118
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
564 (defun quit-window (&optional kill window) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
565 "Quit the current buffer. Bury it, and maybe delete the selected frame. |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
566 \(The frame is deleted if it is contains a dedicated window for the buffer.) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
567 With a prefix argument, kill the buffer instead. |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
568 |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
569 Noninteractively, if KILL is non-nil, then kill the current buffer, |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
570 otherwise bury it. |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
571 |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
572 If WINDOW is non-nil, it specifies a window; we delete that window, |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
573 and the buffer that is killed or buried is the one in that window." |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
574 (interactive "P") |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
575 (let ((buffer (window-buffer window)) |
21970
3c8d5ab91f84
(quit-window): Fixed FRAME to be the frame and never window.
Richard M. Stallman <rms@gnu.org>
parents:
21860
diff
changeset
|
576 (frame (window-frame (or window (selected-window)))) |
21118
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
577 (window-solitary |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
578 (save-selected-window |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
579 (if window |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
580 (select-window window)) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
581 (one-window-p t))) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
582 window-handled) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
583 |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
584 (save-selected-window |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
585 (if window |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
586 (select-window window)) |
21860
58d299618042
(quit-window): Don't try to switch buffers
Richard M. Stallman <rms@gnu.org>
parents:
21118
diff
changeset
|
587 (or (window-minibuffer-p) |
58d299618042
(quit-window): Don't try to switch buffers
Richard M. Stallman <rms@gnu.org>
parents:
21118
diff
changeset
|
588 (window-dedicated-p (selected-window)) |
58d299618042
(quit-window): Don't try to switch buffers
Richard M. Stallman <rms@gnu.org>
parents:
21118
diff
changeset
|
589 (switch-to-buffer (other-buffer)))) |
21118
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
590 |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
591 ;; Get rid of the frame, if it has just one dedicated window |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
592 ;; and other visible frames exist. |
21860
58d299618042
(quit-window): Don't try to switch buffers
Richard M. Stallman <rms@gnu.org>
parents:
21118
diff
changeset
|
593 (and (or (window-minibuffer-p) (window-dedicated-p window)) |
21118
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
594 (delq frame (visible-frame-list)) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
595 window-solitary |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
596 (if (and (eq default-minibuffer-frame frame) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
597 (= 1 (length (minibuffer-frame-list)))) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
598 (setq window nil) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
599 (delete-frame frame) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
600 (setq window-handled t))) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
601 |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
602 ;; Deal with the buffer. |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
603 (if kill |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
604 (kill-buffer buffer) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
605 (bury-buffer buffer)) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
606 |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
607 ;; Maybe get rid of the window. |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
608 (and window (not window-handled) (not window-solitary) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
609 (delete-window window)))) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
610 |
44296
915a76139f37
(handle-select-window): New function.
Pavel Janík <Pavel@Janik.cz>
parents:
43095
diff
changeset
|
611 (defun handle-select-window (event) |
915a76139f37
(handle-select-window): New function.
Pavel Janík <Pavel@Janik.cz>
parents:
43095
diff
changeset
|
612 "Handle select-window events." |
915a76139f37
(handle-select-window): New function.
Pavel Janík <Pavel@Janik.cz>
parents:
43095
diff
changeset
|
613 (interactive "e") |
915a76139f37
(handle-select-window): New function.
Pavel Janík <Pavel@Janik.cz>
parents:
43095
diff
changeset
|
614 (let ((window (posn-window (event-start event)))) |
46896
549bdeb52a93
(split-window-save-restore-data): Use push and with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44297
diff
changeset
|
615 (if (and (window-live-p window) |
549bdeb52a93
(split-window-save-restore-data): Use push and with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44297
diff
changeset
|
616 (or (not (window-minibuffer-p window)) |
549bdeb52a93
(split-window-save-restore-data): Use push and with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44297
diff
changeset
|
617 (minibuffer-window-active-p window))) |
44296
915a76139f37
(handle-select-window): New function.
Pavel Janík <Pavel@Janik.cz>
parents:
43095
diff
changeset
|
618 (select-window window)))) |
915a76139f37
(handle-select-window): New function.
Pavel Janík <Pavel@Janik.cz>
parents:
43095
diff
changeset
|
619 |
36 | 620 (define-key ctl-x-map "2" 'split-window-vertically) |
707 | 621 (define-key ctl-x-map "3" 'split-window-horizontally) |
36 | 622 (define-key ctl-x-map "}" 'enlarge-window-horizontally) |
623 (define-key ctl-x-map "{" 'shrink-window-horizontally) | |
2529
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
624 (define-key ctl-x-map "-" 'shrink-window-if-larger-than-buffer) |
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
625 (define-key ctl-x-map "+" 'balance-windows) |
16469
479c96f4be3a
(kill-buffer-and-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
15076
diff
changeset
|
626 (define-key ctl-x-4-map "0" 'kill-buffer-and-window) |
656
d74e65773062
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
419
diff
changeset
|
627 |
52401 | 628 ;;; arch-tag: b508dfcc-c353-4c37-89fa-e773fe10cea9 |
33708
7c2b5397acbc
General comment and spacing fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33537
diff
changeset
|
629 ;;; window.el ends here |