Mercurial > emacs
annotate lisp/window.el @ 71461:90cf42c37682
Mention www.nongnu.org pages that list free Unicode fonts.
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Sat, 24 Jun 2006 07:00:58 +0000 |
parents | 073af3c41750 |
children | 695dbebf4c20 a8190f7e546e |
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 |
64762
41bb365f41c4
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64091
diff
changeset
|
3 ;; Copyright (C) 1985, 1989, 1992, 1993, 1994, 2000, 2001, 2002, |
68651
3bd95f4f2941
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
68487
diff
changeset
|
4 ;; 2003, 2004, 2005, 2006 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 |
64091 | 23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
24 ;; Boston, MA 02110-1301, 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 |
61764
0d3c33403da5
(window-size-fixed): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
61038
diff
changeset
|
32 (defvar window-size-fixed nil |
0d3c33403da5
(window-size-fixed): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
61038
diff
changeset
|
33 "*Non-nil in a buffer means windows displaying the buffer are fixed-size. |
63162
ae0502a0a9c7
(window-size-fixed): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
62671
diff
changeset
|
34 If the value is `height', then only the window's height is fixed. |
61764
0d3c33403da5
(window-size-fixed): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
61038
diff
changeset
|
35 If the value is `width', then only the window's width is fixed. |
0d3c33403da5
(window-size-fixed): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
61038
diff
changeset
|
36 Any other non-nil value fixes both the width and the height. |
0d3c33403da5
(window-size-fixed): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
61038
diff
changeset
|
37 Emacs won't change the size of any window displaying that buffer, |
0d3c33403da5
(window-size-fixed): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
61038
diff
changeset
|
38 unless you explicitly change the size, or Emacs has no other choice.") |
0d3c33403da5
(window-size-fixed): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
61038
diff
changeset
|
39 (make-variable-buffer-local 'window-size-fixed) |
0d3c33403da5
(window-size-fixed): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
61038
diff
changeset
|
40 |
43093
5b046c8a20a6
(save-selected-window): Move macro before first use.
Andreas Schwab <schwab@suse.de>
parents:
42876
diff
changeset
|
41 (defmacro save-selected-window (&rest body) |
5b046c8a20a6
(save-selected-window): Move macro before first use.
Andreas Schwab <schwab@suse.de>
parents:
42876
diff
changeset
|
42 "Execute BODY, then select the window that was selected before BODY. |
63759
015a62a98a1c
(save-selected-window): Use save-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
63179
diff
changeset
|
43 The value returned is the value of the last form in BODY. |
015a62a98a1c
(save-selected-window): Use save-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
63179
diff
changeset
|
44 |
015a62a98a1c
(save-selected-window): Use save-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
63179
diff
changeset
|
45 This macro saves and restores the current buffer, since otherwise |
015a62a98a1c
(save-selected-window): Use save-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
63179
diff
changeset
|
46 its normal operation could potentially make a different |
63760 | 47 buffer current. It does not alter the buffer list ordering. |
63759
015a62a98a1c
(save-selected-window): Use save-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
63179
diff
changeset
|
48 |
015a62a98a1c
(save-selected-window): Use save-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
63179
diff
changeset
|
49 This macro saves and restores the selected window, as well as |
015a62a98a1c
(save-selected-window): Use save-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
63179
diff
changeset
|
50 the selected window in each frame. If the previously selected |
015a62a98a1c
(save-selected-window): Use save-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
63179
diff
changeset
|
51 window of some frame is no longer live at the end of BODY, that |
015a62a98a1c
(save-selected-window): Use save-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
63179
diff
changeset
|
52 frame's selected window is left alone. If the selected window is |
015a62a98a1c
(save-selected-window): Use save-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
63179
diff
changeset
|
53 no longer live, then whatever window is selected at the end of |
015a62a98a1c
(save-selected-window): Use save-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
63179
diff
changeset
|
54 BODY remains selected." |
48941
7262fd90146a
(save-selected-window): Save and restore selected windows of all frames.
Richard M. Stallman <rms@gnu.org>
parents:
46896
diff
changeset
|
55 `(let ((save-selected-window-window (selected-window)) |
55825 | 56 ;; It is necessary to save all of these, because calling |
57 ;; select-window changes frame-selected-window for whatever | |
58 ;; frame that window is in. | |
48941
7262fd90146a
(save-selected-window): Save and restore selected windows of all frames.
Richard M. Stallman <rms@gnu.org>
parents:
46896
diff
changeset
|
59 (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
|
60 (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
|
61 (frame-list)))) |
63759
015a62a98a1c
(save-selected-window): Use save-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
63179
diff
changeset
|
62 (save-current-buffer |
015a62a98a1c
(save-selected-window): Use save-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
63179
diff
changeset
|
63 (unwind-protect |
015a62a98a1c
(save-selected-window): Use save-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
63179
diff
changeset
|
64 (progn ,@body) |
015a62a98a1c
(save-selected-window): Use save-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
63179
diff
changeset
|
65 (dolist (elt save-selected-window-alist) |
015a62a98a1c
(save-selected-window): Use save-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
63179
diff
changeset
|
66 (and (frame-live-p (car elt)) |
015a62a98a1c
(save-selected-window): Use save-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
63179
diff
changeset
|
67 (window-live-p (cadr elt)) |
015a62a98a1c
(save-selected-window): Use save-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
63179
diff
changeset
|
68 (set-frame-selected-window (car elt) (cadr elt)))) |
015a62a98a1c
(save-selected-window): Use save-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
63179
diff
changeset
|
69 (if (window-live-p save-selected-window-window) |
015a62a98a1c
(save-selected-window): Use save-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
63179
diff
changeset
|
70 (select-window save-selected-window-window)))))) |
43093
5b046c8a20a6
(save-selected-window): Move macro before first use.
Andreas Schwab <schwab@suse.de>
parents:
42876
diff
changeset
|
71 |
42818
55ed8ccce828
(window-body-height): New function.
Richard M. Stallman <rms@gnu.org>
parents:
42307
diff
changeset
|
72 (defun window-body-height (&optional window) |
55ed8ccce828
(window-body-height): New function.
Richard M. Stallman <rms@gnu.org>
parents:
42307
diff
changeset
|
73 "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
|
74 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
|
75 (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
|
76 (if (window-minibuffer-p window) |
869e78e96e2a
(window-body-height): Handle minibuffer window specially.
Richard M. Stallman <rms@gnu.org>
parents:
42818
diff
changeset
|
77 (window-height window) |
869e78e96e2a
(window-body-height): Handle minibuffer window specially.
Richard M. Stallman <rms@gnu.org>
parents:
42818
diff
changeset
|
78 (with-current-buffer (window-buffer window) |
869e78e96e2a
(window-body-height): Handle minibuffer window specially.
Richard M. Stallman <rms@gnu.org>
parents:
42818
diff
changeset
|
79 (max 1 (- (window-height window) |
869e78e96e2a
(window-body-height): Handle minibuffer window specially.
Richard M. Stallman <rms@gnu.org>
parents:
42818
diff
changeset
|
80 (if mode-line-format 1 0) |
869e78e96e2a
(window-body-height): Handle minibuffer window specially.
Richard M. Stallman <rms@gnu.org>
parents:
42818
diff
changeset
|
81 (if header-line-format 1 0)))))) |
42818
55ed8ccce828
(window-body-height): New function.
Richard M. Stallman <rms@gnu.org>
parents:
42307
diff
changeset
|
82 |
11086
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
83 (defun one-window-p (&optional nomini all-frames) |
56391
fa07df089602
(save-selected-window, one-window-p)
Luc Teirlinck <teirllm@auburn.edu>
parents:
55825
diff
changeset
|
84 "Return non-nil if the selected window is the only 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
|
85 Optional arg NOMINI non-nil means don't count the minibuffer |
56391
fa07df089602
(save-selected-window, one-window-p)
Luc Teirlinck <teirllm@auburn.edu>
parents:
55825
diff
changeset
|
86 even if it is active. Otherwise, the minibuffer is counted |
fa07df089602
(save-selected-window, one-window-p)
Luc Teirlinck <teirllm@auburn.edu>
parents:
55825
diff
changeset
|
87 when it is active. |
11086
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
88 |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
89 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
|
90 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
|
91 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
|
92 plus the minibuffer it uses (which may be on another frame). |
56391
fa07df089602
(save-selected-window, one-window-p)
Luc Teirlinck <teirllm@auburn.edu>
parents:
55825
diff
changeset
|
93 ALL-FRAMES 0 means count all windows in all visible or iconified frames. |
fa07df089602
(save-selected-window, one-window-p)
Luc Teirlinck <teirllm@auburn.edu>
parents:
55825
diff
changeset
|
94 If ALL-FRAMES is anything else, 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
|
95 (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
|
96 (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
|
97 (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
|
98 (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
|
99 (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
|
100 |
52615
de1a002c48c7
(window-current-scroll-bars): New defun.
Kim F. Storm <storm@cua.dk>
parents:
52481
diff
changeset
|
101 (defun window-current-scroll-bars (&optional window) |
de1a002c48c7
(window-current-scroll-bars): New defun.
Kim F. Storm <storm@cua.dk>
parents:
52481
diff
changeset
|
102 "Return the current scroll-bar settings in window WINDOW. |
63179
01c52a1fbfe8
(window-current-scroll-bars): Fix typos in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
63168
diff
changeset
|
103 Value is a cons (VERTICAL . HORIZONTAL) where VERTICAL specifies the |
52615
de1a002c48c7
(window-current-scroll-bars): New defun.
Kim F. Storm <storm@cua.dk>
parents:
52481
diff
changeset
|
104 current location of the vertical scroll-bars (left, right, or nil), |
63179
01c52a1fbfe8
(window-current-scroll-bars): Fix typos in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
63168
diff
changeset
|
105 and HORIZONTAL specifies the current location of the horizontal scroll |
52615
de1a002c48c7
(window-current-scroll-bars): New defun.
Kim F. Storm <storm@cua.dk>
parents:
52481
diff
changeset
|
106 bars (top, bottom, or nil)." |
de1a002c48c7
(window-current-scroll-bars): New defun.
Kim F. Storm <storm@cua.dk>
parents:
52481
diff
changeset
|
107 (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
|
108 (hor nil)) |
de1a002c48c7
(window-current-scroll-bars): New defun.
Kim F. Storm <storm@cua.dk>
parents:
52481
diff
changeset
|
109 (when (or (eq vert t) (eq hor t)) |
56391
fa07df089602
(save-selected-window, one-window-p)
Luc Teirlinck <teirllm@auburn.edu>
parents:
55825
diff
changeset
|
110 (let ((fcsb (frame-current-scroll-bars |
52615
de1a002c48c7
(window-current-scroll-bars): New defun.
Kim F. Storm <storm@cua.dk>
parents:
52481
diff
changeset
|
111 (window-frame (or window (selected-window)))))) |
de1a002c48c7
(window-current-scroll-bars): New defun.
Kim F. Storm <storm@cua.dk>
parents:
52481
diff
changeset
|
112 (if (eq vert t) |
de1a002c48c7
(window-current-scroll-bars): New defun.
Kim F. Storm <storm@cua.dk>
parents:
52481
diff
changeset
|
113 (setq vert (car fcsb))) |
de1a002c48c7
(window-current-scroll-bars): New defun.
Kim F. Storm <storm@cua.dk>
parents:
52481
diff
changeset
|
114 (if (eq hor t) |
de1a002c48c7
(window-current-scroll-bars): New defun.
Kim F. Storm <storm@cua.dk>
parents:
52481
diff
changeset
|
115 (setq hor (cdr fcsb))))) |
de1a002c48c7
(window-current-scroll-bars): New defun.
Kim F. Storm <storm@cua.dk>
parents:
52481
diff
changeset
|
116 (cons vert hor))) |
de1a002c48c7
(window-current-scroll-bars): New defun.
Kim F. Storm <storm@cua.dk>
parents:
52481
diff
changeset
|
117 |
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 (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
|
119 "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
|
120 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
|
121 |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
122 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
|
123 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
|
124 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
|
125 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
|
126 |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
127 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
|
128 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
|
129 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
|
130 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
|
131 `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
|
132 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
|
133 |
11302
a9b5c1d727b7
(walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11149
diff
changeset
|
134 ALL-FRAMES is the optional third argument. |
a9b5c1d727b7
(walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11149
diff
changeset
|
135 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
|
136 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
|
137 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
|
138 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
|
139 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
|
140 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
|
141 ;; 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
|
142 (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
|
143 (setq minibuf t)) |
26268
6e6ad5d67263
(walk-windows): If ALL-FRAMES is a frame,
Gerd Moellmann <gerd@gnu.org>
parents:
25263
diff
changeset
|
144 (save-selected-window |
6e6ad5d67263
(walk-windows): If ALL-FRAMES is a frame,
Gerd Moellmann <gerd@gnu.org>
parents:
25263
diff
changeset
|
145 (if (framep all-frames) |
6e6ad5d67263
(walk-windows): If ALL-FRAMES is a frame,
Gerd Moellmann <gerd@gnu.org>
parents:
25263
diff
changeset
|
146 (select-window (frame-first-window all-frames))) |
30005
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
147 (let* (walk-windows-already-seen |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
148 (walk-windows-current (selected-window))) |
26268
6e6ad5d67263
(walk-windows): If ALL-FRAMES is a frame,
Gerd Moellmann <gerd@gnu.org>
parents:
25263
diff
changeset
|
149 (while (progn |
6e6ad5d67263
(walk-windows): If ALL-FRAMES is a frame,
Gerd Moellmann <gerd@gnu.org>
parents:
25263
diff
changeset
|
150 (setq walk-windows-current |
6e6ad5d67263
(walk-windows): If ALL-FRAMES is a frame,
Gerd Moellmann <gerd@gnu.org>
parents:
25263
diff
changeset
|
151 (next-window walk-windows-current minibuf all-frames)) |
30005
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
152 (not (memq walk-windows-current walk-windows-already-seen))) |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
153 (setq walk-windows-already-seen |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
154 (cons walk-windows-current walk-windows-already-seen)) |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
155 (funcall proc walk-windows-current))))) |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
156 |
39172
9ba7895e6ad2
(get-window-with-predicate): Renamed from some-window.
Gerd Moellmann <gerd@gnu.org>
parents:
39117
diff
changeset
|
157 (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
|
158 all-frames default) |
30005
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
159 "Return a window satisfying PREDICATE. |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
160 |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
161 This function cycles through all visible windows using `walk-windows', |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
162 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
|
163 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
|
164 value is returned. If no window satisfies PREDICATE, DEFAULT is |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
165 returned. |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
166 |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
167 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
|
168 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
|
169 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
|
170 minibuffer even if it is active. |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
171 |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
172 Several frames may share a single minibuffer; if the minibuffer |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
173 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
|
174 too. Therefore, if you are using a separate minibuffer frame |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
175 and the minibuffer is active and MINIBUF says it counts, |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
176 `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
|
177 entered the minibuffer, as well as the minibuffer window. |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
178 |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
179 ALL-FRAMES is the optional third argument. |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
180 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
|
181 ALL-FRAMES = `visible' means include windows on all visible frames. |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
182 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
|
183 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
|
184 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
|
185 Anything else means restrict to the selected frame." |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
186 (catch 'found |
33708
7c2b5397acbc
General comment and spacing fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33537
diff
changeset
|
187 (walk-windows #'(lambda (window) |
30005
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
188 (when (funcall predicate window) |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
189 (throw 'found window))) |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
190 minibuf all-frames) |
766caf49d6a9
(some-window): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
28655
diff
changeset
|
191 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
|
192 |
39172
9ba7895e6ad2
(get-window-with-predicate): Renamed from some-window.
Gerd Moellmann <gerd@gnu.org>
parents:
39117
diff
changeset
|
193 (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
|
194 |
66310
c7bbd7c2f47c
(get-buffer-window-list): Moved from subr.el.
Richard M. Stallman <rms@gnu.org>
parents:
64762
diff
changeset
|
195 ;; This should probably be written in C (i.e., without using `walk-windows'). |
c7bbd7c2f47c
(get-buffer-window-list): Moved from subr.el.
Richard M. Stallman <rms@gnu.org>
parents:
64762
diff
changeset
|
196 (defun get-buffer-window-list (buffer &optional minibuf frame) |
c7bbd7c2f47c
(get-buffer-window-list): Moved from subr.el.
Richard M. Stallman <rms@gnu.org>
parents:
64762
diff
changeset
|
197 "Return list of all windows displaying BUFFER, or nil if none. |
c7bbd7c2f47c
(get-buffer-window-list): Moved from subr.el.
Richard M. Stallman <rms@gnu.org>
parents:
64762
diff
changeset
|
198 BUFFER can be a buffer or a buffer name. |
c7bbd7c2f47c
(get-buffer-window-list): Moved from subr.el.
Richard M. Stallman <rms@gnu.org>
parents:
64762
diff
changeset
|
199 See `walk-windows' for the meaning of MINIBUF and FRAME." |
c7bbd7c2f47c
(get-buffer-window-list): Moved from subr.el.
Richard M. Stallman <rms@gnu.org>
parents:
64762
diff
changeset
|
200 (let ((buffer (if (bufferp buffer) buffer (get-buffer buffer))) windows) |
c7bbd7c2f47c
(get-buffer-window-list): Moved from subr.el.
Richard M. Stallman <rms@gnu.org>
parents:
64762
diff
changeset
|
201 (walk-windows (function (lambda (window) |
c7bbd7c2f47c
(get-buffer-window-list): Moved from subr.el.
Richard M. Stallman <rms@gnu.org>
parents:
64762
diff
changeset
|
202 (if (eq (window-buffer window) buffer) |
c7bbd7c2f47c
(get-buffer-window-list): Moved from subr.el.
Richard M. Stallman <rms@gnu.org>
parents:
64762
diff
changeset
|
203 (setq windows (cons window windows))))) |
c7bbd7c2f47c
(get-buffer-window-list): Moved from subr.el.
Richard M. Stallman <rms@gnu.org>
parents:
64762
diff
changeset
|
204 minibuf frame) |
c7bbd7c2f47c
(get-buffer-window-list): Moved from subr.el.
Richard M. Stallman <rms@gnu.org>
parents:
64762
diff
changeset
|
205 windows)) |
c7bbd7c2f47c
(get-buffer-window-list): Moved from subr.el.
Richard M. Stallman <rms@gnu.org>
parents:
64762
diff
changeset
|
206 |
11086
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
207 (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
|
208 "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
|
209 (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
|
210 |
36 | 211 (defun count-windows (&optional minibuf) |
33708
7c2b5397acbc
General comment and spacing fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33537
diff
changeset
|
212 "Return the number of visible windows. |
22328
874f007a7d9c
(shrink-window-if-larger-than-buffer):
Karl Heuer <kwzh@gnu.org>
parents:
22216
diff
changeset
|
213 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
|
214 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
|
215 The optional arg MINIBUF non-nil means count the minibuffer |
14836 | 216 even if it is inactive." |
36 | 217 (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
|
218 (walk-windows (function (lambda (w) |
36 | 219 (setq count (+ count 1)))) |
220 minibuf) | |
221 count)) | |
222 | |
33708
7c2b5397acbc
General comment and spacing fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33537
diff
changeset
|
223 (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
|
224 "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
|
225 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
|
226 (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
|
227 (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
|
228 (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
|
229 (= (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
|
230 |
67478
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
231 |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
232 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
233 ;;; `balance-windows' subroutines using `window-tree' |
33708
7c2b5397acbc
General comment and spacing fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33537
diff
changeset
|
234 |
67478
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
235 ;;; Translate from internal window tree format |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
236 |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
237 (defun bw-get-tree (&optional window-or-frame) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
238 "Get a window split tree in our format. |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
239 |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
240 WINDOW-OR-FRAME must be nil, a frame, or a window. If it is nil, |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
241 then the whole window split tree for `selected-frame' is returned. |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
242 If it is a frame, then this is used instead. If it is a window, |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
243 then the smallest tree containing that window is returned." |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
244 (when window-or-frame |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
245 (unless (or (framep window-or-frame) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
246 (windowp window-or-frame)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
247 (error "Not a frame or window: %s" window-or-frame))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
248 (let ((subtree (bw-find-tree-sub window-or-frame))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
249 (if (integerp subtree) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
250 nil |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
251 (bw-get-tree-1 subtree)))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
252 |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
253 (defun bw-get-tree-1 (split) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
254 (if (windowp split) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
255 split |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
256 (let ((dir (car split)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
257 (edges (car (cdr split))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
258 (childs (cdr (cdr split)))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
259 (list |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
260 (cons 'dir (if dir 'ver 'hor)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
261 (cons 'b (nth 3 edges)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
262 (cons 'r (nth 2 edges)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
263 (cons 't (nth 1 edges)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
264 (cons 'l (nth 0 edges)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
265 (cons 'childs (mapcar #'bw-get-tree-1 childs)))))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
266 |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
267 (defun bw-find-tree-sub (window-or-frame &optional get-parent) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
268 (let* ((window (when (windowp window-or-frame) window-or-frame)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
269 (frame (when (windowp window) (window-frame window))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
270 (wt (car (window-tree frame)))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
271 (when (< 1 (length (window-list frame 0))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
272 (if window |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
273 (bw-find-tree-sub-1 wt window get-parent) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
274 wt)))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
275 |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
276 (defun bw-find-tree-sub-1 (tree win &optional get-parent) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
277 (unless (windowp win) (error "Not a window: %s" win)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
278 (if (memq win tree) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
279 (if get-parent |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
280 get-parent |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
281 tree) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
282 (let ((childs (cdr (cdr tree))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
283 child |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
284 subtree) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
285 (while (and childs (not subtree)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
286 (setq child (car childs)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
287 (setq childs (cdr childs)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
288 (when (and child (listp child)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
289 (setq subtree (bw-find-tree-sub-1 child win get-parent)))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
290 (if (integerp subtree) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
291 (progn |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
292 (if (= 1 subtree) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
293 tree |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
294 (1- subtree))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
295 subtree |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
296 )))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
297 |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
298 ;;; Window or object edges |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
299 |
68487
bde0adf72ba8
(bw-dir, bw-eqdir, balance-windows, split-window-keep-point):
Juanma Barranquero <lekktu@gmail.com>
parents:
67478
diff
changeset
|
300 (defun bw-l (obj) |
67478
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
301 "Left edge of OBJ." |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
302 (if (windowp obj) (nth 0 (window-edges obj)) (cdr (assq 'l obj)))) |
68487
bde0adf72ba8
(bw-dir, bw-eqdir, balance-windows, split-window-keep-point):
Juanma Barranquero <lekktu@gmail.com>
parents:
67478
diff
changeset
|
303 (defun bw-t (obj) |
67478
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
304 "Top edge of OBJ." |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
305 (if (windowp obj) (nth 1 (window-edges obj)) (cdr (assq 't obj)))) |
68487
bde0adf72ba8
(bw-dir, bw-eqdir, balance-windows, split-window-keep-point):
Juanma Barranquero <lekktu@gmail.com>
parents:
67478
diff
changeset
|
306 (defun bw-r (obj) |
67478
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
307 "Right edge of OBJ." |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
308 (if (windowp obj) (nth 2 (window-edges obj)) (cdr (assq 'r obj)))) |
68487
bde0adf72ba8
(bw-dir, bw-eqdir, balance-windows, split-window-keep-point):
Juanma Barranquero <lekktu@gmail.com>
parents:
67478
diff
changeset
|
309 (defun bw-b (obj) |
67478
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
310 "Bottom edge of OBJ." |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
311 (if (windowp obj) (nth 3 (window-edges obj)) (cdr (assq 'b obj)))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
312 |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
313 ;;; Split directions |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
314 |
68487
bde0adf72ba8
(bw-dir, bw-eqdir, balance-windows, split-window-keep-point):
Juanma Barranquero <lekktu@gmail.com>
parents:
67478
diff
changeset
|
315 (defun bw-dir (obj) |
67478
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
316 "Return window split tree direction if OBJ. |
68487
bde0adf72ba8
(bw-dir, bw-eqdir, balance-windows, split-window-keep-point):
Juanma Barranquero <lekktu@gmail.com>
parents:
67478
diff
changeset
|
317 If OBJ is a window return 'both. If it is a window split tree |
67478
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
318 then return its direction." |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
319 (if (symbolp obj) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
320 obj |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
321 (if (windowp obj) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
322 'both |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
323 (let ((dir (cdr (assq 'dir obj)))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
324 (unless (memq dir '(hor ver both)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
325 (error "Can't find dir in %s" obj)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
326 dir)))) |
42307
922f0ef2951b
(balance-windows): Use new PRESERVE-BEFORE arg
Richard M. Stallman <rms@gnu.org>
parents:
41541
diff
changeset
|
327 |
68487
bde0adf72ba8
(bw-dir, bw-eqdir, balance-windows, split-window-keep-point):
Juanma Barranquero <lekktu@gmail.com>
parents:
67478
diff
changeset
|
328 (defun bw-eqdir (obj1 obj2) |
67478
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
329 "Return t if window split tree directions are equal. |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
330 OBJ1 and OBJ2 should be either windows or window split trees in |
68487
bde0adf72ba8
(bw-dir, bw-eqdir, balance-windows, split-window-keep-point):
Juanma Barranquero <lekktu@gmail.com>
parents:
67478
diff
changeset
|
331 our format. The directions returned by `bw-dir' are compared and |
67478
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
332 t is returned if they are `eq' or one of them is 'both." |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
333 (let ((dir1 (bw-dir obj1)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
334 (dir2 (bw-dir obj2))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
335 (or (eq dir1 dir2) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
336 (eq dir1 'both) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
337 (eq dir2 'both)))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
338 |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
339 ;;; Building split tree |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
340 |
68487
bde0adf72ba8
(bw-dir, bw-eqdir, balance-windows, split-window-keep-point):
Juanma Barranquero <lekktu@gmail.com>
parents:
67478
diff
changeset
|
341 (defun bw-refresh-edges (obj) |
67478
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
342 "Refresh the edge information of OBJ and return OBJ." |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
343 (unless (windowp obj) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
344 (let ((childs (cdr (assq 'childs obj))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
345 (ol 1000) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
346 (ot 1000) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
347 (or -1) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
348 (ob -1)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
349 (dolist (o childs) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
350 (when (> ol (bw-l o)) (setq ol (bw-l o))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
351 (when (> ot (bw-t o)) (setq ot (bw-t o))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
352 (when (< or (bw-r o)) (setq or (bw-r o))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
353 (when (< ob (bw-b o)) (setq ob (bw-b o)))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
354 (setq obj (delq 'l obj)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
355 (setq obj (delq 't obj)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
356 (setq obj (delq 'r obj)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
357 (setq obj (delq 'b obj)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
358 (add-to-list 'obj (cons 'l ol)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
359 (add-to-list 'obj (cons 't ot)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
360 (add-to-list 'obj (cons 'r or)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
361 (add-to-list 'obj (cons 'b ob)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
362 )) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
363 obj) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
364 |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
365 ;;; Balance windows |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
366 |
68487
bde0adf72ba8
(bw-dir, bw-eqdir, balance-windows, split-window-keep-point):
Juanma Barranquero <lekktu@gmail.com>
parents:
67478
diff
changeset
|
367 (defun balance-windows (&optional window-or-frame) |
67478
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
368 "Make windows the same heights or widths in window split subtrees. |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
369 |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
370 When called non-interactively WINDOW-OR-FRAME may be either a |
68487
bde0adf72ba8
(bw-dir, bw-eqdir, balance-windows, split-window-keep-point):
Juanma Barranquero <lekktu@gmail.com>
parents:
67478
diff
changeset
|
371 window or a frame. It then balances the windows on the implied |
bde0adf72ba8
(bw-dir, bw-eqdir, balance-windows, split-window-keep-point):
Juanma Barranquero <lekktu@gmail.com>
parents:
67478
diff
changeset
|
372 frame. If the parameter is a window only the corresponding window |
67478
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
373 subtree is balanced." |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
374 (interactive) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
375 (let ( |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
376 (wt (bw-get-tree window-or-frame)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
377 (w) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
378 (h) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
379 (tried-sizes) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
380 (last-sizes) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
381 (windows (window-list nil 0)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
382 (counter 0)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
383 (when wt |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
384 (while (not (member last-sizes tried-sizes)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
385 (when last-sizes (setq tried-sizes (cons last-sizes tried-sizes))) |
68487
bde0adf72ba8
(bw-dir, bw-eqdir, balance-windows, split-window-keep-point):
Juanma Barranquero <lekktu@gmail.com>
parents:
67478
diff
changeset
|
386 (setq last-sizes (mapcar (lambda (w) |
67478
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
387 (window-edges w)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
388 windows)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
389 (when (eq 'hor (bw-dir wt)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
390 (setq w (- (bw-r wt) (bw-l wt)))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
391 (when (eq 'ver (bw-dir wt)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
392 (setq h (- (bw-b wt) (bw-t wt)))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
393 (bw-balance-sub wt w h))))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
394 |
68487
bde0adf72ba8
(bw-dir, bw-eqdir, balance-windows, split-window-keep-point):
Juanma Barranquero <lekktu@gmail.com>
parents:
67478
diff
changeset
|
395 (defun bw-adjust-window (window delta horizontal) |
67478
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
396 "Wrapper around `adjust-window-trailing-edge' with error checking. |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
397 Arguments WINDOW, DELTA and HORIZONTAL are passed on to that function." |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
398 (condition-case err |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
399 (adjust-window-trailing-edge window delta horizontal) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
400 (error |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
401 ;;(message "adjust: %s" (error-message-string err)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
402 ))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
403 |
68487
bde0adf72ba8
(bw-dir, bw-eqdir, balance-windows, split-window-keep-point):
Juanma Barranquero <lekktu@gmail.com>
parents:
67478
diff
changeset
|
404 (defun bw-balance-sub (wt w h) |
67478
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
405 (setq wt (bw-refresh-edges wt)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
406 (unless w (setq w (- (bw-r wt) (bw-l wt)))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
407 (unless h (setq h (- (bw-b wt) (bw-t wt)))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
408 (if (windowp wt) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
409 (progn |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
410 (when w |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
411 (let ((dw (- w (- (bw-r wt) (bw-l wt))))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
412 (when (/= 0 dw) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
413 (bw-adjust-window wt dw t)))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
414 (when h |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
415 (let ((dh (- h (- (bw-b wt) (bw-t wt))))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
416 (when (/= 0 dh) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
417 (bw-adjust-window wt dh nil))))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
418 (let* ((childs (cdr (assq 'childs wt))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
419 (lastchild (car (last childs))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
420 (cw (when w (/ w (if (bw-eqdir 'hor wt) (length childs) 1)))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
421 (ch (when h (/ h (if (bw-eqdir 'ver wt) (length childs) 1))))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
422 (dolist (c childs) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
423 (bw-balance-sub c cw ch))))) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
424 |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
425 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
11086
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
426 |
46896
549bdeb52a93
(split-window-save-restore-data): Use push and with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44297
diff
changeset
|
427 ;; I think this should be the default; I think people will prefer it--rms. |
17665 | 428 (defcustom split-window-keep-point t |
56391
fa07df089602
(save-selected-window, one-window-p)
Luc Teirlinck <teirllm@auburn.edu>
parents:
55825
diff
changeset
|
429 "*If non-nil, \\[split-window-vertically] keeps the original point \ |
fa07df089602
(save-selected-window, one-window-p)
Luc Teirlinck <teirllm@auburn.edu>
parents:
55825
diff
changeset
|
430 in both children. |
3724
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
431 This is often more convenient for editing. |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
432 If nil, adjust point in each of the two windows to minimize redisplay. |
56391
fa07df089602
(save-selected-window, one-window-p)
Luc Teirlinck <teirllm@auburn.edu>
parents:
55825
diff
changeset
|
433 This is convenient on slow terminals, but point can move strangely. |
fa07df089602
(save-selected-window, one-window-p)
Luc Teirlinck <teirllm@auburn.edu>
parents:
55825
diff
changeset
|
434 |
fa07df089602
(save-selected-window, one-window-p)
Luc Teirlinck <teirllm@auburn.edu>
parents:
55825
diff
changeset
|
435 This option applies only to `split-window-vertically' and |
fa07df089602
(save-selected-window, one-window-p)
Luc Teirlinck <teirllm@auburn.edu>
parents:
55825
diff
changeset
|
436 functions that call it. `split-window' always keeps the original |
68487
bde0adf72ba8
(bw-dir, bw-eqdir, balance-windows, split-window-keep-point):
Juanma Barranquero <lekktu@gmail.com>
parents:
67478
diff
changeset
|
437 point in both children." |
17665 | 438 :type 'boolean |
439 :group 'windows) | |
382 | 440 |
36 | 441 (defun split-window-vertically (&optional arg) |
442 "Split current window into two windows, one above the other. | |
108 | 443 The uppermost window gets ARG lines and the other gets the rest. |
56391
fa07df089602
(save-selected-window, one-window-p)
Luc Teirlinck <teirllm@auburn.edu>
parents:
55825
diff
changeset
|
444 Negative ARG means select the size of the lowermost window instead. |
108 | 445 With no argument, split equally or close to it. |
446 Both windows display the same buffer now current. | |
382 | 447 |
22216
5750539e01e7
(split-window-vertically): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
21970
diff
changeset
|
448 If the variable `split-window-keep-point' is non-nil, both new windows |
382 | 449 will get the same value of point as the current window. This is often |
56391
fa07df089602
(save-selected-window, one-window-p)
Luc Teirlinck <teirllm@auburn.edu>
parents:
55825
diff
changeset
|
450 more convenient for editing. The upper window is the selected window. |
108 | 451 |
56391
fa07df089602
(save-selected-window, one-window-p)
Luc Teirlinck <teirllm@auburn.edu>
parents:
55825
diff
changeset
|
452 Otherwise, we choose window starts so as to minimize the amount of |
382 | 453 redisplay; this is convenient on slow terminals. The new selected |
454 window is the one that the current value of point appears in. The | |
455 value of point can change if the text around point is hidden by the | |
56391
fa07df089602
(save-selected-window, one-window-p)
Luc Teirlinck <teirllm@auburn.edu>
parents:
55825
diff
changeset
|
456 new mode line. |
fa07df089602
(save-selected-window, one-window-p)
Luc Teirlinck <teirllm@auburn.edu>
parents:
55825
diff
changeset
|
457 |
fa07df089602
(save-selected-window, one-window-p)
Luc Teirlinck <teirllm@auburn.edu>
parents:
55825
diff
changeset
|
458 Regardless of the value of `split-window-keep-point', the upper |
fa07df089602
(save-selected-window, one-window-p)
Luc Teirlinck <teirllm@auburn.edu>
parents:
55825
diff
changeset
|
459 window is the original one and the return value is the new, lower |
fa07df089602
(save-selected-window, one-window-p)
Luc Teirlinck <teirllm@auburn.edu>
parents:
55825
diff
changeset
|
460 window." |
36 | 461 (interactive "P") |
462 (let ((old-w (selected-window)) | |
108 | 463 (old-point (point)) |
6670
b2c5fca3c10c
(split-window-vertically): If size is negative, measure from bottom.
Karl Heuer <kwzh@gnu.org>
parents:
6019
diff
changeset
|
464 (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
|
465 (window-full-p nil) |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
466 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
|
467 (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
|
468 (setq new-w (split-window nil size)) |
419 | 469 (or split-window-keep-point |
108 | 470 (progn |
382 | 471 (save-excursion |
472 (set-buffer (window-buffer)) | |
473 (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
|
474 (setq moved (vertical-motion (window-height))) |
382 | 475 (set-window-start new-w (point)) |
476 (if (> (point) (window-point new-w)) | |
477 (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
|
478 (and (= moved (window-height)) |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
479 (progn |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
480 (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
|
481 (vertical-motion -1))) |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
482 (setq bottom (point))) |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
483 (and window-full-p |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
484 (<= bottom (point)) |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
485 (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
|
486 (and window-full-p |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
487 (<= (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
|
488 (progn |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
489 (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
|
490 (select-window new-w))))) |
18279
a9c40a80c9b1
(split-window-save-restore-data): New function that
Richard M. Stallman <rms@gnu.org>
parents:
17665
diff
changeset
|
491 (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
|
492 |
21118
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
493 ;; This is to avoid compiler warnings. |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
494 (defvar view-return-to-alist) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
495 |
18279
a9c40a80c9b1
(split-window-save-restore-data): New function that
Richard M. Stallman <rms@gnu.org>
parents:
17665
diff
changeset
|
496 (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
|
497 (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
|
498 (if view-mode |
a9c40a80c9b1
(split-window-save-restore-data): New function that
Richard M. Stallman <rms@gnu.org>
parents:
17665
diff
changeset
|
499 (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
|
500 (if old-info |
10dc0a48bc2c
(split-window-save-restore-data):
Richard M. Stallman <rms@gnu.org>
parents:
53894
diff
changeset
|
501 (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
|
502 view-return-to-alist)))) |
3253
f4d37be94734
(split-window-vertically): Return the new window.
Richard M. Stallman <rms@gnu.org>
parents:
2529
diff
changeset
|
503 new-w)) |
36 | 504 |
505 (defun split-window-horizontally (&optional arg) | |
506 "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
|
507 This window becomes the leftmost of the two, and gets ARG columns. |
56391
fa07df089602
(save-selected-window, one-window-p)
Luc Teirlinck <teirllm@auburn.edu>
parents:
55825
diff
changeset
|
508 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
|
509 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
|
510 are no scroll bars, it includes the width of the divider column |
56391
fa07df089602
(save-selected-window, one-window-p)
Luc Teirlinck <teirllm@auburn.edu>
parents:
55825
diff
changeset
|
511 to the window's right, if any. No ARG means split equally. |
fa07df089602
(save-selected-window, one-window-p)
Luc Teirlinck <teirllm@auburn.edu>
parents:
55825
diff
changeset
|
512 |
fa07df089602
(save-selected-window, one-window-p)
Luc Teirlinck <teirllm@auburn.edu>
parents:
55825
diff
changeset
|
513 The original, leftmost window remains selected. |
fa07df089602
(save-selected-window, one-window-p)
Luc Teirlinck <teirllm@auburn.edu>
parents:
55825
diff
changeset
|
514 The return value is the new, rightmost window." |
36 | 515 (interactive "P") |
18279
a9c40a80c9b1
(split-window-save-restore-data): New function that
Richard M. Stallman <rms@gnu.org>
parents:
17665
diff
changeset
|
516 (let ((old-w (selected-window)) |
a9c40a80c9b1
(split-window-save-restore-data): New function that
Richard M. Stallman <rms@gnu.org>
parents:
17665
diff
changeset
|
517 (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
|
518 (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
|
519 (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
|
520 (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
|
521 |
9f29610841ca
(window-text-height, set-window-text-height): New functions.
Miles Bader <miles@gnu.org>
parents:
32684
diff
changeset
|
522 |
9f29610841ca
(window-text-height, set-window-text-height): New functions.
Miles Bader <miles@gnu.org>
parents:
32684
diff
changeset
|
523 (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
|
524 "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
|
525 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
|
526 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
|
527 |
9f29610841ca
(window-text-height, set-window-text-height): New functions.
Miles Bader <miles@gnu.org>
parents:
32684
diff
changeset
|
528 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
|
529 |
9f29610841ca
(window-text-height, set-window-text-height): New functions.
Miles Bader <miles@gnu.org>
parents:
32684
diff
changeset
|
530 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
|
531 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
|
532 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
|
533 (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
|
534 (unless (zerop delta) |
32695
5a4f1fbd4ed7
(set-window-text-height): Force window-min-height to 1.
Miles Bader <miles@gnu.org>
parents:
32689
diff
changeset
|
535 (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
|
536 (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
|
537 (save-selected-window |
5a4f1fbd4ed7
(set-window-text-height): Force window-min-height to 1.
Miles Bader <miles@gnu.org>
parents:
32689
diff
changeset
|
538 (select-window window) |
5a4f1fbd4ed7
(set-window-text-height): Force window-min-height to 1.
Miles Bader <miles@gnu.org>
parents:
32689
diff
changeset
|
539 (enlarge-window delta)) |
5a4f1fbd4ed7
(set-window-text-height): Force window-min-height to 1.
Miles Bader <miles@gnu.org>
parents:
32689
diff
changeset
|
540 (enlarge-window delta)))))) |
32689
9f29610841ca
(window-text-height, set-window-text-height): New functions.
Miles Bader <miles@gnu.org>
parents:
32684
diff
changeset
|
541 |
32681
569ef1445e17
(mode-line-window-height-fudge): New variable.
Miles Bader <miles@gnu.org>
parents:
31790
diff
changeset
|
542 |
36 | 543 (defun enlarge-window-horizontally (arg) |
544 "Make current window ARG columns wider." | |
545 (interactive "p") | |
546 (enlarge-window arg t)) | |
547 | |
548 (defun shrink-window-horizontally (arg) | |
549 "Make current window ARG columns narrower." | |
550 (interactive "p") | |
551 (shrink-window arg t)) | |
552 | |
23748
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
553 (defun window-buffer-height (window) |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
554 "Return the height (in screen lines) of the buffer that WINDOW is displaying." |
61038
f7f0c6eb075b
(window-buffer-height): Use count-screen-lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59652
diff
changeset
|
555 (with-current-buffer (window-buffer window) |
f7f0c6eb075b
(window-buffer-height): Use count-screen-lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59652
diff
changeset
|
556 (max 1 |
f7f0c6eb075b
(window-buffer-height): Use count-screen-lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59652
diff
changeset
|
557 (count-screen-lines (point-min) (point-max) |
f7f0c6eb075b
(window-buffer-height): Use count-screen-lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59652
diff
changeset
|
558 ;; If buffer ends with a newline, ignore it when |
f7f0c6eb075b
(window-buffer-height): Use count-screen-lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59652
diff
changeset
|
559 ;; counting height unless point is after it. |
f7f0c6eb075b
(window-buffer-height): Use count-screen-lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59652
diff
changeset
|
560 (eobp) |
f7f0c6eb075b
(window-buffer-height): Use count-screen-lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59652
diff
changeset
|
561 window)))) |
23748
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
562 |
28655
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
563 (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
|
564 "Return the number of screen lines in the region. |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
565 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
|
566 due to line breaking, display table, etc. |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
567 |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
568 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
|
569 respectively. |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
570 |
33708
7c2b5397acbc
General comment and spacing fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33537
diff
changeset
|
571 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
|
572 COUNT-FINAL-NEWLINE is non-nil. |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
573 |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
574 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
|
575 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
|
576 to use the selected window's parameters. |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
577 |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
578 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
|
579 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
|
580 `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
|
581 in some window." |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
582 (unless beg |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
583 (setq beg (point-min))) |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
584 (unless end |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
585 (setq end (point-max))) |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
586 (if (= beg end) |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
587 0 |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
588 (save-excursion |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
589 (save-restriction |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
590 (widen) |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
591 (narrow-to-region (min beg end) |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
592 (if (and (not count-final-newline) |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
593 (= ?\n (char-before (max beg end)))) |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
594 (1- (max beg end)) |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
595 (max beg end))) |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
596 (goto-char (point-min)) |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
597 (1+ (vertical-motion (buffer-size) window)))))) |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
598 |
32705
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
599 (defun fit-window-to-buffer (&optional window max-height min-height) |
71083
073af3c41750
(fit-window-to-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
600 "Make WINDOW the right height to display its contents exactly. |
36366
62272f68e460
(fit-window-to-buffer, window-safely-shrinkable-p)
Eli Zaretskii <eliz@gnu.org>
parents:
34580
diff
changeset
|
601 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
|
602 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
|
603 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
|
604 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
|
605 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
|
606 |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
607 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
|
608 header-line." |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
609 (interactive) |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
610 |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
611 (when (null window) |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
612 (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
|
613 (when (null max-height) |
29a87f28cd51
(fit-window-to-buffer): Change defaulting of MAX-HEIGHT slightly.
Miles Bader <miles@gnu.org>
parents:
32736
diff
changeset
|
614 (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
|
615 |
33478
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
616 (let* ((buf |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
617 ;; 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
|
618 (window-buffer window)) |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
619 (window-height |
32705
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
620 ;; The current height of WINDOW |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
621 (window-height window)) |
33478
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
622 (desired-height |
32705
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
623 ;; 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
|
624 ;; (`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
|
625 (with-current-buffer buf |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
626 (+ (count-screen-lines) |
33536
035e7b097577
(fit-window-to-buffer): Be sure to acquire at least
Kenichi Handa <handa@m17n.org>
parents:
33478
diff
changeset
|
627 ;; 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
|
628 ;; 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
|
629 ;; for cursor. |
035e7b097577
(fit-window-to-buffer): Be sure to acquire at least
Kenichi Handa <handa@m17n.org>
parents:
33478
diff
changeset
|
630 (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
|
631 1 0) |
33478
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
632 ;; 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
|
633 (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
|
634 mode-line-format) |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
635 1 0) |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
636 ;; 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
|
637 (if header-line-format 1 0)))) |
32705
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
638 (delta |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
639 ;; 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
|
640 ;; 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
|
641 (- (max (min desired-height max-height) |
32705
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
642 (or min-height window-min-height)) |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
643 window-height)) |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
644 ;; 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
|
645 ;; window-min-height. |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
646 (window-min-height 1)) |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
647 |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
648 ;; 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
|
649 ;; 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
|
650 (when (with-current-buffer buf |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
651 (and (eobp) (bolp) (not (bobp)))) |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
652 (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
|
653 |
33478
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
654 (save-selected-window |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
655 (select-window window) |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
656 |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
657 ;; 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
|
658 ;; 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
|
659 (unless (zerop delta) |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
660 (enlarge-window delta)) |
33475
b18c7c71cf2e
(fit-window-to-buffer): Don't check
Kenichi Handa <handa@m17n.org>
parents:
32811
diff
changeset
|
661 |
33478
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
662 ;; 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
|
663 ;; enlarge the window. |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
664 (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
|
665 (save-excursion |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
666 (goto-char (point-max)) |
34079
6316cacc1e16
(fit-window-to-buffer): Handle non-nil `truncate-lines'.
Miles Bader <miles@gnu.org>
parents:
33708
diff
changeset
|
667 (when (and (bolp) (not (bobp))) |
6316cacc1e16
(fit-window-to-buffer): Handle non-nil `truncate-lines'.
Miles Bader <miles@gnu.org>
parents:
33708
diff
changeset
|
668 ;; Don't include final newline |
6316cacc1e16
(fit-window-to-buffer): Handle non-nil `truncate-lines'.
Miles Bader <miles@gnu.org>
parents:
33708
diff
changeset
|
669 (backward-char 1)) |
6316cacc1e16
(fit-window-to-buffer): Handle non-nil `truncate-lines'.
Miles Bader <miles@gnu.org>
parents:
33708
diff
changeset
|
670 (when truncate-lines |
6316cacc1e16
(fit-window-to-buffer): Handle non-nil `truncate-lines'.
Miles Bader <miles@gnu.org>
parents:
33708
diff
changeset
|
671 ;; 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
|
672 ;; 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
|
673 ;; 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
|
674 ;; 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
|
675 ;; the edge of the window. |
6316cacc1e16
(fit-window-to-buffer): Handle non-nil `truncate-lines'.
Miles Bader <miles@gnu.org>
parents:
33708
diff
changeset
|
676 (forward-line 0)) |
6316cacc1e16
(fit-window-to-buffer): Handle non-nil `truncate-lines'.
Miles Bader <miles@gnu.org>
parents:
33708
diff
changeset
|
677 (point))))) |
33478
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
678 (set-window-vscroll window 0) |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
679 (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
|
680 (= 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
|
681 (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
|
682 (enlarge-window 1) |
33537
53c51fd75027
(fit-window-to-buffer): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
33536
diff
changeset
|
683 (setq desired-height (1+ desired-height))))))) |
32705
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
684 |
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
|
685 (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
|
686 "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
|
687 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
|
688 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
|
689 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
|
690 or if some of the window's contents are scrolled out of view, |
63168
54196b74d427
(shrink-window-if-larger-than-buffer): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
63162
diff
changeset
|
691 or if shrinking this window would also shrink another window, |
62671
bf8ebb1d0b0b
(quit-window, shrink-window-if-larger-than-buffer): Doc fixes.
Juanma Barranquero <lekktu@gmail.com>
parents:
61764
diff
changeset
|
692 or if the window is the only window of its frame." |
3342
ce8aa0ba8b08
(shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents:
3253
diff
changeset
|
693 (interactive) |
32705
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
694 (when (null window) |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
695 (setq window (selected-window))) |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
696 (let* ((frame (window-frame window)) |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
697 (mini (frame-parameter frame 'minibuffer)) |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
698 (edges (window-edges window))) |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
699 (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
|
700 (window-safely-shrinkable-p) |
32705
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
701 (pos-visible-in-window-p (point-min) window) |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
702 (not (eq mini 'only)) |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
703 (or (not mini) |
36666
2b284278da9c
(shrink-window-if-larger-than-buffer): Handle frame
Gerd Moellmann <gerd@gnu.org>
parents:
36366
diff
changeset
|
704 (let ((mini-window (minibuffer-window frame))) |
2b284278da9c
(shrink-window-if-larger-than-buffer): Handle frame
Gerd Moellmann <gerd@gnu.org>
parents:
36366
diff
changeset
|
705 (or (null mini-window) |
2b284278da9c
(shrink-window-if-larger-than-buffer): Handle frame
Gerd Moellmann <gerd@gnu.org>
parents:
36366
diff
changeset
|
706 (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
|
707 (< (nth 3 edges) |
2b284278da9c
(shrink-window-if-larger-than-buffer): Handle frame
Gerd Moellmann <gerd@gnu.org>
parents:
36366
diff
changeset
|
708 (nth 1 (window-edges mini-window))) |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48941
diff
changeset
|
709 (> (nth 1 edges) |
36666
2b284278da9c
(shrink-window-if-larger-than-buffer): Handle frame
Gerd Moellmann <gerd@gnu.org>
parents:
36366
diff
changeset
|
710 (frame-parameter frame 'menu-bar-lines)))))) |
32705
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
711 (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
|
712 |
479c96f4be3a
(kill-buffer-and-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
15076
diff
changeset
|
713 (defun kill-buffer-and-window () |
479c96f4be3a
(kill-buffer-and-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
15076
diff
changeset
|
714 "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
|
715 (interactive) |
52481
f1cce2846e29
(kill-buffer-and-window): Remove `yes-or-no-p' so that
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
716 (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
|
717 (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
|
718 (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
|
719 (delete-window) |
f1cce2846e29
(kill-buffer-and-window): Remove `yes-or-no-p' so that
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
720 (error nil))))) |
f1cce2846e29
(kill-buffer-and-window): Remove `yes-or-no-p' so that
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
721 (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
|
722 (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
|
723 ;; 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
|
724 ;; 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
|
725 (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
|
726 (delete-window)) |
f1cce2846e29
(kill-buffer-and-window): Remove `yes-or-no-p' so that
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
727 (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
|
728 |
21118
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
729 (defun quit-window (&optional kill window) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
730 "Quit the current buffer. Bury it, and maybe delete the selected frame. |
62671
bf8ebb1d0b0b
(quit-window, shrink-window-if-larger-than-buffer): Doc fixes.
Juanma Barranquero <lekktu@gmail.com>
parents:
61764
diff
changeset
|
731 \(The frame is deleted if it contains a dedicated window for the buffer.) |
21118
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
732 With a prefix argument, kill the buffer instead. |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
733 |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
734 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
|
735 otherwise bury it. |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
736 |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
737 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
|
738 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
|
739 (interactive "P") |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
740 (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
|
741 (frame (window-frame (or window (selected-window)))) |
21118
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
742 (window-solitary |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
743 (save-selected-window |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
744 (if window |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
745 (select-window window)) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
746 (one-window-p t))) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
747 window-handled) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
748 |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
749 (save-selected-window |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
750 (if window |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
751 (select-window window)) |
21860
58d299618042
(quit-window): Don't try to switch buffers
Richard M. Stallman <rms@gnu.org>
parents:
21118
diff
changeset
|
752 (or (window-minibuffer-p) |
58d299618042
(quit-window): Don't try to switch buffers
Richard M. Stallman <rms@gnu.org>
parents:
21118
diff
changeset
|
753 (window-dedicated-p (selected-window)) |
58d299618042
(quit-window): Don't try to switch buffers
Richard M. Stallman <rms@gnu.org>
parents:
21118
diff
changeset
|
754 (switch-to-buffer (other-buffer)))) |
21118
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
755 |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
756 ;; 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
|
757 ;; 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
|
758 (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
|
759 (delq frame (visible-frame-list)) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
760 window-solitary |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
761 (if (and (eq default-minibuffer-frame frame) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
762 (= 1 (length (minibuffer-frame-list)))) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
763 (setq window nil) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
764 (delete-frame frame) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
765 (setq window-handled t))) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
766 |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
767 ;; Deal with the buffer. |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
768 (if kill |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
769 (kill-buffer buffer) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
770 (bury-buffer buffer)) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
771 |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
772 ;; Maybe get rid of the window. |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
773 (and window (not window-handled) (not window-solitary) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
774 (delete-window window)))) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
775 |
44296
915a76139f37
(handle-select-window): New function.
Pavel Janík <Pavel@Janik.cz>
parents:
43095
diff
changeset
|
776 (defun handle-select-window (event) |
915a76139f37
(handle-select-window): New function.
Pavel Janík <Pavel@Janik.cz>
parents:
43095
diff
changeset
|
777 "Handle select-window events." |
915a76139f37
(handle-select-window): New function.
Pavel Janík <Pavel@Janik.cz>
parents:
43095
diff
changeset
|
778 (interactive "e") |
915a76139f37
(handle-select-window): New function.
Pavel Janík <Pavel@Janik.cz>
parents:
43095
diff
changeset
|
779 (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
|
780 (if (and (window-live-p window) |
59652
9672303dbf4f
(handle-select-window): Don't switch window when we're in the minibuffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
56588
diff
changeset
|
781 ;; Don't switch if we're currently in the minibuffer. |
9672303dbf4f
(handle-select-window): Don't switch window when we're in the minibuffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
56588
diff
changeset
|
782 ;; This tries to work around problems where the minibuffer gets |
9672303dbf4f
(handle-select-window): Don't switch window when we're in the minibuffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
56588
diff
changeset
|
783 ;; unselected unexpectedly, and where you then have to move |
9672303dbf4f
(handle-select-window): Don't switch window when we're in the minibuffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
56588
diff
changeset
|
784 ;; your mouse all the way down to the minibuffer to select it. |
9672303dbf4f
(handle-select-window): Don't switch window when we're in the minibuffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
56588
diff
changeset
|
785 (not (window-minibuffer-p (selected-window))) |
9672303dbf4f
(handle-select-window): Don't switch window when we're in the minibuffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
56588
diff
changeset
|
786 ;; Don't switch to a minibuffer window unless it's active. |
46896
549bdeb52a93
(split-window-save-restore-data): Use push and with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44297
diff
changeset
|
787 (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
|
788 (minibuffer-window-active-p window))) |
44296
915a76139f37
(handle-select-window): New function.
Pavel Janík <Pavel@Janik.cz>
parents:
43095
diff
changeset
|
789 (select-window window)))) |
915a76139f37
(handle-select-window): New function.
Pavel Janík <Pavel@Janik.cz>
parents:
43095
diff
changeset
|
790 |
36 | 791 (define-key ctl-x-map "2" 'split-window-vertically) |
707 | 792 (define-key ctl-x-map "3" 'split-window-horizontally) |
36 | 793 (define-key ctl-x-map "}" 'enlarge-window-horizontally) |
794 (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
|
795 (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
|
796 (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
|
797 (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
|
798 |
59652
9672303dbf4f
(handle-select-window): Don't switch window when we're in the minibuffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
56588
diff
changeset
|
799 ;; arch-tag: b508dfcc-c353-4c37-89fa-e773fe10cea9 |
33708
7c2b5397acbc
General comment and spacing fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33537
diff
changeset
|
800 ;;; window.el ends here |