Mercurial > emacs
annotate lisp/window.el @ 95610:cb95dadcb2de
Merge from gnus--devo--0
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-1215
author | Miles Bader <miles@gnu.org> |
---|---|
date | Fri, 06 Jun 2008 22:53:14 +0000 |
parents | b406f55ccc12 |
children | 2072976ded5e |
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, |
79721 | 4 ;; 2003, 2004, 2005, 2006, 2007, 2008 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 | |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94641
diff
changeset
|
11 ;; GNU Emacs is free software: you can redistribute it and/or modify |
36 | 12 ;; it under the terms of the GNU General Public License as published by |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94641
diff
changeset
|
13 ;; the Free Software Foundation, either version 3 of the License, or |
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94641
diff
changeset
|
14 ;; (at your option) any later version. |
36 | 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 | |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94641
diff
changeset
|
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
36 | 23 |
33708
7c2b5397acbc
General comment and spacing fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33537
diff
changeset
|
24 ;;; Commentary: |
7c2b5397acbc
General comment and spacing fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33537
diff
changeset
|
25 |
7c2b5397acbc
General comment and spacing fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33537
diff
changeset
|
26 ;; Window tree functions. |
7c2b5397acbc
General comment and spacing fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33537
diff
changeset
|
27 |
773
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
707
diff
changeset
|
28 ;;; Code: |
36 | 29 |
94725
0fc821738484
Require 'cl when compiling.
Andreas Schwab <schwab@suse.de>
parents:
94678
diff
changeset
|
30 (eval-when-compile (require 'cl)) |
0fc821738484
Require 'cl when compiling.
Andreas Schwab <schwab@suse.de>
parents:
94678
diff
changeset
|
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 |
82097
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
60 (mapcar (lambda (frame) (cons frame (frame-selected-window frame))) |
48941
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)) |
82097
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
67 (window-live-p (cdr elt)) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
68 (set-frame-selected-window (car elt) (cdr elt)))) |
63759
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 |
78492
7c8949dbfa0d
Replace `iff' in doc-strings and comments.
Glenn Morris <rgm@gnu.org>
parents:
78236
diff
changeset
|
123 if not active. MINIBUF nil or omitted means count the minibuffer only if |
11086
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 |
78492
7c8949dbfa0d
Replace `iff' in doc-strings and comments.
Glenn Morris <rgm@gnu.org>
parents:
78236
diff
changeset
|
168 if not active. MINIBUF nil or omitted means count the minibuffer only if |
30005
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'). |
95590
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
196 (defun get-buffer-window-list (buffer &optional minibuf all-frames) |
66310
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. |
95590
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
199 See `walk-windows' for the meaning of MINIBUF and ALL-FRAMES." |
66310
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))))) |
95590
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
204 minibuf all-frames) |
66310
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)) |
86337
161416156d88
(balance-windows): Remove unused var `counter'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
86159
diff
changeset
|
218 (walk-windows (lambda (w) (setq count (+ count 1))) |
36 | 219 minibuf) |
220 count)) | |
221 | |
33708
7c2b5397acbc
General comment and spacing fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33537
diff
changeset
|
222 (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
|
223 "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
|
224 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
|
225 (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
|
226 (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
|
227 (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
|
228 (= (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
|
229 |
67478
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
230 |
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 ;;; `balance-windows' subroutines using `window-tree' |
33708
7c2b5397acbc
General comment and spacing fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33537
diff
changeset
|
233 |
67478
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
234 ;;; 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
|
235 |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
236 (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
|
237 "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
|
238 |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
239 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
|
240 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
|
241 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
|
242 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
|
243 (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
|
244 (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
|
245 (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
|
246 (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
|
247 (let ((subtree (bw-find-tree-sub window-or-frame))) |
72182
9482f7b84d4d
(bw-get-tree): Don't integerp subtree if it's nil.
Eli Zaretskii <eliz@gnu.org>
parents:
71557
diff
changeset
|
248 (when subtree |
9482f7b84d4d
(bw-get-tree): Don't integerp subtree if it's nil.
Eli Zaretskii <eliz@gnu.org>
parents:
71557
diff
changeset
|
249 (if (integerp subtree) |
9482f7b84d4d
(bw-get-tree): Don't integerp subtree if it's nil.
Eli Zaretskii <eliz@gnu.org>
parents:
71557
diff
changeset
|
250 nil |
9482f7b84d4d
(bw-get-tree): Don't integerp subtree if it's nil.
Eli Zaretskii <eliz@gnu.org>
parents:
71557
diff
changeset
|
251 (bw-get-tree-1 subtree))))) |
67478
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) |
86337
161416156d88
(balance-windows): Remove unused var `counter'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
86159
diff
changeset
|
381 (windows (window-list nil 0))) |
67478
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
382 (when wt |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
383 (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
|
384 (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
|
385 (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
|
386 (window-edges w)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
387 windows)) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
388 (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
|
389 (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
|
390 (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
|
391 (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
|
392 (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
|
393 |
68487
bde0adf72ba8
(bw-dir, bw-eqdir, balance-windows, split-window-keep-point):
Juanma Barranquero <lekktu@gmail.com>
parents:
67478
diff
changeset
|
394 (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
|
395 "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
|
396 Arguments WINDOW, DELTA and HORIZONTAL are passed on to that function." |
82097
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
397 ;; `adjust-window-trailing-edge' may fail if delta is too large. |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
398 (while (>= (abs delta) 1) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
399 (condition-case err |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
400 (progn |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
401 (adjust-window-trailing-edge window delta horizontal) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
402 (setq delta 0)) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
403 (error |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
404 ;;(message "adjust: %s" (error-message-string err)) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
405 (setq delta (/ delta 2)))))) |
67478
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
406 |
68487
bde0adf72ba8
(bw-dir, bw-eqdir, balance-windows, split-window-keep-point):
Juanma Barranquero <lekktu@gmail.com>
parents:
67478
diff
changeset
|
407 (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
|
408 (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
|
409 (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
|
410 (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
|
411 (if (windowp wt) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
412 (progn |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
413 (when w |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
414 (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
|
415 (when (/= 0 dw) |
86337
161416156d88
(balance-windows): Remove unused var `counter'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
86159
diff
changeset
|
416 (bw-adjust-window wt dw t)))) |
67478
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
417 (when h |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
418 (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
|
419 (when (/= 0 dh) |
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
420 (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
|
421 (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
|
422 (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
|
423 (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
|
424 (dolist (c childs) |
86337
161416156d88
(balance-windows): Remove unused var `counter'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
86159
diff
changeset
|
425 (bw-balance-sub c cw ch))))) |
67478
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
426 |
82097
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
427 ;;; A different solution to balance-windows |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
428 |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
429 (defun window-fixed-size-p (&optional window direction) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
430 "Non-nil if WINDOW cannot be resized in DIRECTION. |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
431 DIRECTION can be nil (i.e. any), `height' or `width'." |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
432 (with-current-buffer (window-buffer window) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
433 (let ((fixed (and (boundp 'window-size-fixed) window-size-fixed))) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
434 (when fixed |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
435 (not (and direction |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
436 (member (cons direction window-size-fixed) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
437 '((height . width) (width . height))))))))) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
438 |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
439 (defvar window-area-factor 1 |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
440 "Factor by which the window area should be over-estimated. |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
441 This is used by `balance-windows-area'. |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
442 Changing this globally has no effect.") |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
443 |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
444 (defun balance-windows-area () |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
445 "Make all visible windows the same area (approximately). |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
446 See also `window-area-factor' to change the relative size of specific buffers." |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
447 (interactive) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
448 (let* ((unchanged 0) (carry 0) (round 0) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
449 ;; Remove fixed-size windows. |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
450 (wins (delq nil (mapcar (lambda (win) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
451 (if (not (window-fixed-size-p win)) win)) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
452 (window-list nil 'nomini)))) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
453 (changelog nil) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
454 next) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
455 ;; Resizing a window changes the size of surrounding windows in complex |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
456 ;; ways, so it's difficult to balance them all. The introduction of |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
457 ;; `adjust-window-trailing-edge' made it a bit easier, but it is still |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
458 ;; very difficult to do. `balance-window' above takes an off-line |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
459 ;; approach: get the whole window tree, then balance it, then try to |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
460 ;; adjust the windows so they fit the result. |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
461 ;; Here, instead, we take a "local optimization" approach, where we just |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
462 ;; go through all the windows several times until nothing needs to be |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
463 ;; changed. The main problem with this approach is that it's difficult |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
464 ;; to make sure it terminates, so we use some heuristic to try and break |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
465 ;; off infinite loops. |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
466 ;; After a round without any change, we allow a second, to give a chance |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
467 ;; to the carry to propagate a minor imbalance from the end back to |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
468 ;; the beginning. |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
469 (while (< unchanged 2) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
470 ;; (message "New round") |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
471 (setq unchanged (1+ unchanged) round (1+ round)) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
472 (dolist (win wins) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
473 (setq next win) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
474 (while (progn (setq next (next-window next)) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
475 (window-fixed-size-p next))) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
476 ;; (assert (eq next (or (cadr (member win wins)) (car wins)))) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
477 (let* ((horiz |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
478 (< (car (window-edges win)) (car (window-edges next)))) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
479 (areadiff (/ (- (* (window-height next) (window-width next) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
480 (buffer-local-value 'window-area-factor |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
481 (window-buffer next))) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
482 (* (window-height win) (window-width win) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
483 (buffer-local-value 'window-area-factor |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
484 (window-buffer win)))) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
485 (max (buffer-local-value 'window-area-factor |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
486 (window-buffer win)) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
487 (buffer-local-value 'window-area-factor |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
488 (window-buffer next))))) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
489 (edgesize (if horiz |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
490 (+ (window-height win) (window-height next)) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
491 (+ (window-width win) (window-width next)))) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
492 (diff (/ areadiff edgesize))) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
493 (when (zerop diff) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
494 ;; Maybe diff is actually closer to 1 than to 0. |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
495 (setq diff (/ (* 3 areadiff) (* 2 edgesize)))) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
496 (when (and (zerop diff) (not (zerop areadiff))) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
497 (setq diff (/ (+ areadiff carry) edgesize)) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
498 ;; Change things smoothly. |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
499 (if (or (> diff 1) (< diff -1)) (setq diff (/ diff 2)))) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
500 (if (zerop diff) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
501 ;; Make sure negligible differences don't accumulate to |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
502 ;; become significant. |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
503 (setq carry (+ carry areadiff)) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
504 (bw-adjust-window win diff horiz) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
505 ;; (sit-for 0.5) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
506 (let ((change (cons win (window-edges win)))) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
507 ;; If the same change has been seen already for this window, |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
508 ;; we're most likely in an endless loop, so don't count it as |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
509 ;; a change. |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
510 (unless (member change changelog) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
511 (push change changelog) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
512 (setq unchanged 0 carry 0))))))) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
513 ;; We've now basically balanced all the windows. |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
514 ;; But there may be some minor off-by-one imbalance left over, |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
515 ;; so let's do some fine tuning. |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
516 ;; (bw-finetune wins) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
517 ;; (message "Done in %d rounds" round) |
9d01f26910cf
(save-selected-window): Minor optimization.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81770
diff
changeset
|
518 )) |
67478
d78d32605019
(bw-get-tree, bw-get-tree-1, bw-find-tree-sub)
Eli Zaretskii <eliz@gnu.org>
parents:
67341
diff
changeset
|
519 |
11086
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
520 |
95590
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
521 (defcustom display-buffer-function nil |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
522 "If non-nil, function to call to handle `display-buffer'. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
523 It will receive two args, the buffer and a flag which if non-nil |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
524 means that the currently selected window is not acceptable. It |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
525 should choose or create a window, display the specified buffer in |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
526 it, and return the window. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
527 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
528 Commands such as `switch-to-buffer-other-window' and |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
529 `find-file-other-window' work using this function." |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
530 :type '(choice |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
531 (const nil) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
532 (function :tag "function")) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
533 :group 'windows) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
534 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
535 (defun special-display-p (buffer-name) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
536 "Return non-nil if a buffer named BUFFER-NAME gets a special frame. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
537 If the value is t, `display-buffer' or `pop-to-buffer' would |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
538 create a special frame for that buffer using the default frame |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
539 parameters. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
540 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
541 If the value is a list, it is a list of frame parameters that |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
542 would be used to make a frame for that buffer. The variables |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
543 `special-display-buffer-names' and `special-display-regexps' |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
544 control this." |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
545 (cond |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
546 ((not (stringp buffer-name))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
547 ;; Make sure to return t in the following two cases. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
548 ((member buffer-name special-display-buffer-names) t) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
549 ((assoc buffer-name special-display-buffer-names) t) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
550 ((catch 'found |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
551 (dolist (regexp special-display-regexps) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
552 (cond |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
553 ((stringp regexp) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
554 (when (string-match-p regexp buffer-name) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
555 (throw 'found t))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
556 ((and (consp regexp) (stringp (car regexp)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
557 (string-match-p (car regexp) buffer-name)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
558 (throw 'found (cdr regexp))))))))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
559 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
560 (defcustom special-display-buffer-names nil |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
561 "List of buffer names that should have their own special frames. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
562 Displaying a buffer with `display-buffer' or `pop-to-buffer', if |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
563 its name is in this list, makes a special frame for it using |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
564 `special-display-function'. See also `special-display-regexps'. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
565 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
566 An element of the list can be a list instead of just a string. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
567 There are two ways to use a list as an element: |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
568 (BUFFER FRAME-PARAMETERS...) (BUFFER FUNCTION OTHER-ARGS...) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
569 In the first case, the FRAME-PARAMETERS are pairs of the form |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
570 \(PARAMETER . VALUE); these parameter values are used to create |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
571 the frame. In the second case, FUNCTION is called with BUFFER as |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
572 the first argument, followed by the OTHER-ARGS--it can display |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
573 BUFFER in any way it likes. All this is done by the function |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
574 found in `special-display-function'. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
575 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
576 If the specified frame parameters include (same-buffer . t), the |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
577 buffer is displayed in the currently selected window. Otherwise, if |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
578 they include (same-frame . t), the buffer is displayed in a new window |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
579 in the currently selected frame. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
580 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
581 If this variable appears \"not to work\", because you add a name to it |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
582 but that buffer still appears in the selected window, look at the |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
583 values of `same-window-buffer-names' and `same-window-regexps'. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
584 Those variables take precedence over this one." |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
585 :type '(repeat (choice :tag "Buffer" |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
586 :value "" |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
587 (string :format "%v") |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
588 (cons :tag "With attributes" |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
589 :format "%v" |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
590 :value ("" . nil) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
591 (string :format "%v") |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
592 (repeat :tag "Attributes" |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
593 (cons :format "%v" |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
594 (symbol :tag "Parameter") |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
595 (sexp :tag "Value")))))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
596 :group 'frames) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
597 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
598 (defcustom special-display-regexps nil |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
599 "List of regexps saying which buffers should have their own special frames. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
600 When displaying a buffer with `display-buffer' or |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
601 `pop-to-buffer', if any regexp in this list matches the buffer |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
602 name, it makes a special frame for the buffer by calling |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
603 `special-display-function'. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
604 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
605 An element of the list can be a list instead of just a string. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
606 There are two ways to use a list as an element: |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
607 (REGEXP FRAME-PARAMETERS...) (REGEXP FUNCTION OTHER-ARGS...) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
608 In the first case, the FRAME-PARAMETERS are pairs of the form |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
609 \(PARAMETER . VALUE); these parameter values are used to create |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
610 the frame. In the second case, FUNCTION is called with BUFFER as |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
611 the first argument, followed by the OTHER-ARGS--it can display |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
612 the buffer in any way it likes. All this is done by the function |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
613 found in `special-display-function'. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
614 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
615 If the specified frame parameters include (same-buffer . t), the |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
616 buffer is displayed in the currently selected window. Otherwise, |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
617 if they include (same-frame . t), the buffer is displayed in a |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
618 new window in the currently selected frame. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
619 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
620 If this variable appears \"not to work\", because you add a |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
621 regexp to it but the matching buffers still appear in the |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
622 selected window, look at the values of `same-window-buffer-names' |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
623 and `same-window-regexps'. Those variables take precedence over |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
624 this one." |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
625 :type '(repeat (choice :tag "Buffer" |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
626 :value "" |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
627 (regexp :format "%v") |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
628 (cons :tag "With attributes" |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
629 :format "%v" |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
630 :value ("" . nil) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
631 (regexp :format "%v") |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
632 (repeat :tag "Attributes" |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
633 (cons :format "%v" |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
634 (symbol :tag "Parameter") |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
635 (sexp :tag "Value")))))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
636 :group 'frames) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
637 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
638 (defcustom special-display-function 'special-display-popup-frame |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
639 "Function to call to make a new frame for a special buffer. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
640 It is called with two arguments, the buffer and optional buffer |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
641 specific data, and should return a window displaying that buffer. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
642 The default value normally makes a separate frame for the buffer, |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
643 using `special-display-frame-alist' to specify the frame |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
644 parameters. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
645 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
646 But if the buffer specific data includes (same-buffer . t) then |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
647 the buffer is displayed in the current selected window. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
648 Otherwise if it includes (same-frame . t) then the buffer is |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
649 displayed in a new window in the currently selected frame. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
650 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
651 A buffer is special if it is listed in |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
652 `special-display-buffer-names' or matches a regexp in |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
653 `special-display-regexps'." |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
654 :type 'function |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
655 :group 'frames) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
656 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
657 (defun same-window-p (buffer-name) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
658 "Return non-nil if a buffer named BUFFER-NAME would be shown in the \"same\" window. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
659 This function returns non-nil if `display-buffer' or |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
660 `pop-to-buffer' would show a buffer named BUFFER-NAME in the |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
661 selected rather than \(as usual\) some other window. See |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
662 `same-window-buffer-names' and `same-window-regexps'." |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
663 (cond |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
664 ((not (stringp buffer-name))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
665 ;; The elements of `same-window-buffer-names' can be buffer |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
666 ;; names or cons cells whose cars are buffer names. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
667 ((member buffer-name same-window-buffer-names)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
668 ((assoc buffer-name same-window-buffer-names)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
669 ((catch 'found |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
670 (dolist (regexp same-window-regexps) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
671 ;; The elements of `same-window-regexps' can be regexps |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
672 ;; or cons cells whose cars are regexps. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
673 (when (or (and (stringp regexp) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
674 (string-match regexp buffer-name)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
675 (and (consp regexp) (stringp (car regexp)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
676 (string-match-p (car regexp) buffer-name))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
677 (throw 'found t))))))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
678 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
679 (defcustom same-window-buffer-names nil |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
680 "List of names of buffers that should appear in the \"same\" window. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
681 `display-buffer' and `pop-to-buffer' show a buffer whose name is |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
682 on this list in the selected rather than some other window. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
683 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
684 An element of this list can be a cons cell instead of just a |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
685 string. In that case the car must be a string specifying the |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
686 buffer name. This is for compatibility with |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
687 `special-display-buffer-names'; the cdr of the cons cell is |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
688 ignored. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
689 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
690 See also `same-window-regexps'." |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
691 :type '(repeat (string :format "%v")) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
692 :group 'windows) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
693 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
694 (defcustom same-window-regexps nil |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
695 "List of regexps saying which buffers should appear in the \"same\" window. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
696 `display-buffer' and `pop-to-buffer' show a buffer whose name |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
697 matches a regexp on this list in the selected rather than some |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
698 other window. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
699 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
700 An element of this list can be a cons cell instead of just a |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
701 string. In that case the car must be a string, which specifies |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
702 the buffer name. This is for compatibility with |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
703 `special-display-buffer-names'; the cdr of the cons cell is |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
704 ignored. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
705 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
706 See also `same-window-buffer-names'." |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
707 :type '(repeat (regexp :format "%v")) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
708 :group 'windows) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
709 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
710 (defcustom pop-up-frames nil |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
711 "Non-nil means `display-buffer' should make a separate frame." |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
712 :type 'boolean |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
713 :group 'windows) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
714 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
715 (defcustom display-buffer-reuse-frames nil |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
716 "Non-nil means `display-buffer' should reuse frames. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
717 If the buffer in question is already displayed in a frame, raise |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
718 that frame." |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
719 :type 'boolean |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
720 :version "21.1" |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
721 :group 'windows) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
722 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
723 (defcustom pop-up-frame-function nil |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
724 "Function to call to handle automatic new frame creation. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
725 It is called with no arguments and should return a newly created frame. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
726 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
727 A typical value might be |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
728 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
729 `(lambda () (new-frame pop-up-frame-alist))' |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
730 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
731 where `pop-up-frame-alist' would hold the default frame |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
732 parameters." |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
733 :type '(choice |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
734 (const nil) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
735 (function :tag "function")) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
736 :group 'windows) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
737 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
738 (defcustom pop-up-windows t |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
739 "Non-nil means `display-buffer' should make a new window." |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
740 :type 'boolean |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
741 :group 'windows) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
742 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
743 (defcustom split-window-preferred-function nil |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
744 "How `display-buffer' shall split windows. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
745 Choices are `Vertically', `Horizontally', and `Sensibly' where |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
746 the latter attempts to split wide windows horizontally, narrow |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
747 ones vertically. Alternatively, you can set this to a function |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
748 called with a window as single argument to split that window in |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
749 two and return the new window." |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
750 :type '(choice |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
751 (const :tag "Vertically" nil) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
752 (const :tag "Horizontally" horizontally) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
753 (const :tag "Sensibly" sensibly) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
754 (function :tag "Function")) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
755 :version "23.1" |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
756 :group 'windows) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
757 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
758 (defcustom split-height-threshold 80 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
759 "Minimum height of window to be split vertically by `display-buffer'. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
760 If there is only one window, it can be split regardless of this." |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
761 :type 'number |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
762 :version "23.1" |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
763 :group 'windows) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
764 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
765 (defcustom split-width-threshold 160 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
766 "Minimum width of window to be split horizontally by `display-buffer'. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
767 If there is only one window, it can be split regardless of this." |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
768 :type 'number |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
769 :version "23.1" |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
770 :group 'windows) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
771 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
772 (defun window--splittable-p (window &optional horizontal) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
773 "Return non-nil if window WINDOW can be split evenly. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
774 Optional argument HORIZONTAL non-nil means check whether WINDOW |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
775 can be split horizontally. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
776 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
777 WINDOW can be split vertically when the following conditions |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
778 hold: |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
779 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
780 - `window-size-fixed' is either nil or equals `width' for the buffer of |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
781 WINDOW. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
782 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
783 - WINDOW is at least as high as `split-height-threshold' or it is |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
784 the only window on its frame. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
785 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
786 - When WINDOW is split evenly, the emanating windows are at least |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
787 `window-min-height' lines tall and can accomodate at least one |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
788 line plus - if WINDOW has one - a modeline. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
789 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
790 WINDOW can be split horizontally when the following conditions |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
791 hold: |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
792 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
793 - `window-size-fixed' is either nil or equals `height' for the |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
794 buffer of WINDOW. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
795 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
796 - WINDOW is at least as wide as `split-width-threshold'. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
797 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
798 - When WINDOW is split evenly, the emanating windows are at least |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
799 `window-min-width' or two (whichever is larger) columns wide." |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
800 (when (window-live-p window) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
801 (with-selected-window window |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
802 (if horizontal |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
803 ;; A window can be split horizontally when its width is not |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
804 ;; fixed, it is at least `split-width-threshold' columns wide |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
805 ;; and at least twice as wide as `window-min-width' and 2 (the |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
806 ;; latter value is hardcoded). |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
807 (and (memq window-size-fixed '(nil height)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
808 (>= (window-width window) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
809 (max split-width-threshold |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
810 (* 2 (max window-min-width 2))))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
811 ;; A window can be split vertically when its height is not |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
812 ;; fixed, it is at least `split-height-threshold' lines high or |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
813 ;; the only window on its frame, and it is at least twice as |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
814 ;; high as `window-min-height' and 2 if it has a modeline or 1. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
815 (and (memq window-size-fixed '(nil width)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
816 (>= (window-height window) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
817 (max (if (one-window-p 'nomini) 0 split-height-threshold) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
818 (* 2 (max window-min-height |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
819 (if mode-line-format 2 1)))))))))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
820 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
821 (defun window--try-to-split-window (window) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
822 "Split window WINDOW if it is splittable. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
823 See `split-window-preferred-function' for how WINDOW shall be |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
824 split. See `window--splittable-p' for how to determine whether a |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
825 window is splittable. If WINDOW can be split, return the value |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
826 returned by `split-window' or `split-window-preferred-function'." |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
827 (when (and (window-live-p window) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
828 ;; Testing `window-full-width-p' here hardly makes any |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
829 ;; sense nowadays. This can be done more intuitively by |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
830 ;; setting up `split-width-threshold' appropriately. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
831 (not (frame-parameter (window-frame window) 'unsplittable))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
832 (or (and (not split-window-preferred-function) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
833 (window--splittable-p window) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
834 (split-window window)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
835 (and (eq split-window-preferred-function 'horizontally) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
836 (window--splittable-p window t) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
837 (split-window window nil t)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
838 (and (eq split-window-preferred-function 'sensibly) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
839 ;; The following naive aspect-ratio test should become |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
840 ;; more sensible. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
841 (or (and (> (window-width window) (window-height window)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
842 (window--splittable-p window t) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
843 (split-window window nil t)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
844 (and (window--splittable-p window) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
845 (split-window window)))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
846 (and (functionp split-window-preferred-function) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
847 (funcall split-window-preferred-function window))))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
848 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
849 (defun window--frame-usable-p (frame) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
850 "Return frame FRAME if it can be used to display another buffer." |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
851 (let ((window (frame-root-window frame))) |
95596
b406f55ccc12
(display-buffer): Remove dead call to get-lru-window.
Martin Rudalics <rudalics@gmx.at>
parents:
95590
diff
changeset
|
852 ;; `frame-root-window' may be an internal window which is considered |
b406f55ccc12
(display-buffer): Remove dead call to get-lru-window.
Martin Rudalics <rudalics@gmx.at>
parents:
95590
diff
changeset
|
853 ;; "dead" by `window-live-p'. Hence if `window' is not live we |
b406f55ccc12
(display-buffer): Remove dead call to get-lru-window.
Martin Rudalics <rudalics@gmx.at>
parents:
95590
diff
changeset
|
854 ;; implicitly know that `frame' has a visible window we can use. |
95590
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
855 (when (or (not (window-live-p window)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
856 (and (not (window-minibuffer-p window)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
857 (not (window-dedicated-p window)))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
858 frame))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
859 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
860 (defcustom even-window-heights t |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
861 "If non-nil `display-buffer' will try to even window heights. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
862 Otherwise `display-buffer' will leave the window configuration |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
863 alone. Heights are evened only when `display-buffer' chooses a |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
864 window that appears above or below the selected window." |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
865 :type 'boolean |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
866 :group 'windows) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
867 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
868 (defun window--even-window-heights (window) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
869 "Even heights of window WINDOW and selected window. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
870 Do this only if these windows are vertically adjacent to each |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
871 other and `even-window-heights' is non-nil." |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
872 (when (and even-window-heights |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
873 (not (eq window (selected-window))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
874 ;; Don't resize minibuffer windows. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
875 (not (window-minibuffer-p (selected-window))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
876 (/= (window-height (selected-window)) (window-height window)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
877 (eq (window-frame window) (window-frame (selected-window))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
878 (let ((sel-edges (window-edges (selected-window))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
879 (win-edges (window-edges window))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
880 (and (= (nth 0 sel-edges) (nth 0 win-edges)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
881 (= (nth 2 sel-edges) (nth 2 win-edges)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
882 (or (= (nth 1 sel-edges) (nth 3 win-edges)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
883 (= (nth 3 sel-edges) (nth 1 win-edges)))))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
884 (let ((window-min-height 1)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
885 ;; Don't throw an error if we can't even window heights for |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
886 ;; whatever reason. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
887 (condition-case nil |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
888 (enlarge-window (/ (- (window-height window) (window-height)) 2)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
889 (error nil))))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
890 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
891 (defun window--display-buffer-1 (window) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
892 "Deiconify the frame containing the window WINDOW. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
893 Do not deiconify the selected frame. Return WINDOW." |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
894 (let* ((frame (window-frame window)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
895 (visible (frame-visible-p frame))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
896 (unless (or (not visible) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
897 ;; Assume the selected frame is already visible enough. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
898 (eq frame (selected-frame)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
899 ;; Assume the frame from which we invoked the minibuffer |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
900 ;; is visible. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
901 (and (minibuffer-window-active-p (selected-window)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
902 (eq frame (window-frame (minibuffer-selected-window))))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
903 (when (eq visible 'icon) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
904 (make-frame-visible frame)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
905 (raise-frame frame)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
906 window)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
907 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
908 (defun window--display-buffer-2 (buffer window) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
909 "Display buffer BUFFER in window WINDOW and make its frame visible. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
910 Return WINDOW." |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
911 (when (and (buffer-live-p buffer) (window-live-p window)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
912 (set-window-buffer window buffer) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
913 (window--display-buffer-1 window))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
914 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
915 (defun display-buffer (buffer-or-name &optional not-this-window frame) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
916 "Make buffer BUFFER-OR-NAME appear in some window but don't select it. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
917 BUFFER-OR-NAME must be a buffer or the name of an existing |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
918 buffer. Return the window chosen to display BUFFER-OR-NAME or |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
919 nil is no such window is found. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
920 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
921 Optional argument NOT-THIS-WINDOW non-nil means display the |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
922 buffer in a window other than the selected one, even if it is |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
923 already displayed in the selected window. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
924 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
925 Optional argument FRAME specifies which frames to investigate |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
926 when the specified buffer is already displayed. If the buffer is |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
927 already displayed in some window on one of these frames simply |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
928 return that window. Possible values of FRAME are: |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
929 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
930 `visible' - consider windows on all visible frames. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
931 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
932 0 - consider windows on all visible or iconified frames. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
933 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
934 `t' - consider windows on all frames. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
935 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
936 A specific frame - consider windows on that frame only. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
937 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
938 `nil' - consider windows on the selected frame \(actually the |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
939 last non-minibuffer frame\) only. If, however, either |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
940 `display-buffer-reuse-frames' or `pop-up-frames' is non-nil, |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
941 consider all visible or iconified frames." |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
942 (interactive "BDisplay buffer:\nP") |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
943 (let* ((can-use-selected-window |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
944 ;; The selected window is usable unless either NOT-THIS-WINDOW |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
945 ;; is non-nil, it is dedicated to its buffer, or it is the |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
946 ;; `minibuffer-window'. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
947 (not (or not-this-window |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
948 (window-dedicated-p (selected-window)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
949 (window-minibuffer-p)))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
950 (buffer (if (bufferp buffer-or-name) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
951 buffer-or-name |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
952 (get-buffer buffer-or-name))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
953 (name-of-buffer (buffer-name buffer)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
954 ;; `frame-to-use' is the frame where to show `buffer' - either |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
955 ;; the selected frame or the last nonminibuffer frame. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
956 (frame-to-use |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
957 (or (window--frame-usable-p (selected-frame)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
958 (window--frame-usable-p (last-nonminibuffer-frame)))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
959 ;; `window-to-use' is the window we use for showing `buffer'. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
960 window-to-use) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
961 (cond |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
962 ((not (buffer-live-p buffer)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
963 (error "No such buffer %s" buffer)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
964 (display-buffer-function |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
965 ;; Let `display-buffer-function' do the job. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
966 (funcall display-buffer-function buffer not-this-window)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
967 ((and (not not-this-window) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
968 (eq (window-buffer (selected-window)) buffer)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
969 ;; The selected window already displays BUFFER and |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
970 ;; `not-this-window' is nil, so use it. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
971 (window--display-buffer-1 (selected-window))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
972 ((and can-use-selected-window (same-window-p name-of-buffer)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
973 ;; If the buffer's name tells us to use the selected window do so. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
974 (window--display-buffer-2 buffer (selected-window))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
975 ((let ((frames (or frame |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
976 (and (or pop-up-frames display-buffer-reuse-frames |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
977 (not (last-nonminibuffer-frame))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
978 0) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
979 (last-nonminibuffer-frame)))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
980 (and (setq window-to-use (get-buffer-window buffer frames)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
981 (or can-use-selected-window |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
982 (not (eq (selected-window) window-to-use))))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
983 ;; If the buffer is already displayed in some window use that. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
984 (window--display-buffer-1 window-to-use)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
985 ((and special-display-function |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
986 ;; `special-display-p' returns either t or a list of frame |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
987 ;; parameters to pass to `special-display-function'. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
988 (let ((pars (special-display-p name-of-buffer))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
989 (when pars |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
990 (funcall special-display-function |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
991 (if (eq pars t) buffer pars)))))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
992 ((or pop-up-frames (not frame-to-use)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
993 ;; We want or need a new frame. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
994 (window--display-buffer-2 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
995 buffer (frame-selected-window (funcall pop-up-frame-function)))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
996 ((and pop-up-windows |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
997 ;; Make a new window. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
998 (or (not (frame-parameter frame-to-use 'unsplittable)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
999 ;; If the selected frame cannot be split look at |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1000 ;; `last-nonminibuffer-frame'. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1001 (and (eq frame-to-use (selected-frame)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1002 (setq frame-to-use (last-nonminibuffer-frame)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1003 (window--frame-usable-p frame-to-use) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1004 (not (frame-parameter frame-to-use 'unsplittable)))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1005 ;; Attempt to split largest or most recently used window. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1006 (setq window-to-use |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1007 (or (window--try-to-split-window |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1008 (get-largest-window frame-to-use t)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1009 (window--try-to-split-window |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1010 (get-lru-window frame-to-use t)))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1011 (window--display-buffer-2 buffer window-to-use))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1012 ((setq window-to-use |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1013 ;; Reuse an existing window. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1014 (or (get-buffer-window buffer 'visible) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1015 (get-largest-window 'visible nil) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1016 (get-buffer-window buffer 0) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1017 (get-largest-window 0 nil) |
95596
b406f55ccc12
(display-buffer): Remove dead call to get-lru-window.
Martin Rudalics <rudalics@gmx.at>
parents:
95590
diff
changeset
|
1018 (frame-selected-window (funcall pop-up-frame-function)))) |
95590
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1019 (window--even-window-heights window-to-use) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1020 (window--display-buffer-2 buffer window-to-use))))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1021 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1022 (defun pop-to-buffer (buffer-or-name &optional other-window norecord) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1023 "Select buffer BUFFER-OR-NAME in some window, preferably a different one. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1024 BUFFER-OR-NAME may be a buffer, a string \(a buffer name), or |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1025 nil. If BUFFER-OR-NAME is a string not naming an existent |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1026 buffer, create a buffer with that name. If BUFFER-OR-NAME is |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1027 nil, choose some other buffer. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1028 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1029 If `pop-up-windows' is non-nil, windows can be split to display |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1030 the buffer. If optional second arg OTHER-WINDOW is non-nil, |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1031 insist on finding another window even if the specified buffer is |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1032 already visible in the selected window, and ignore |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1033 `same-window-regexps' and `same-window-buffer-names'. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1034 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1035 This function returns the buffer it switched to. This uses the |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1036 function `display-buffer' as a subroutine; see the documentation |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1037 of `display-buffer' for additional customization information. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1038 |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1039 Optional third arg NORECORD non-nil means do not put this buffer |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1040 at the front of the list of recently selected ones." |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1041 (let ((buffer |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1042 ;; FIXME: This behavior is carried over from the previous C version |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1043 ;; of pop-to-buffer, but really we should use just |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1044 ;; `get-buffer' here. |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1045 (if (null buffer-or-name) (other-buffer (current-buffer)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1046 (or (get-buffer buffer-or-name) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1047 (let ((buf (get-buffer-create buffer-or-name))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1048 (set-buffer-major-mode buf) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1049 buf))))) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1050 (set-buffer buffer) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1051 (select-window (display-buffer buffer other-window) norecord) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1052 buffer)) |
9a4b27c8feec
* window.el (display-buffer-function, special-display-p)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94725
diff
changeset
|
1053 |
46896
549bdeb52a93
(split-window-save-restore-data): Use push and with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44297
diff
changeset
|
1054 ;; I think this should be the default; I think people will prefer it--rms. |
17665 | 1055 (defcustom split-window-keep-point t |
56391
fa07df089602
(save-selected-window, one-window-p)
Luc Teirlinck <teirllm@auburn.edu>
parents:
55825
diff
changeset
|
1056 "*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
|
1057 in both children. |
3724
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
1058 This is often more convenient for editing. |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
1059 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
|
1060 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
|
1061 |
fa07df089602
(save-selected-window, one-window-p)
Luc Teirlinck <teirllm@auburn.edu>
parents:
55825
diff
changeset
|
1062 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
|
1063 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
|
1064 point in both children." |
17665 | 1065 :type 'boolean |
1066 :group 'windows) | |
382 | 1067 |
36 | 1068 (defun split-window-vertically (&optional arg) |
1069 "Split current window into two windows, one above the other. | |
108 | 1070 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
|
1071 Negative ARG means select the size of the lowermost window instead. |
108 | 1072 With no argument, split equally or close to it. |
1073 Both windows display the same buffer now current. | |
382 | 1074 |
22216
5750539e01e7
(split-window-vertically): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
21970
diff
changeset
|
1075 If the variable `split-window-keep-point' is non-nil, both new windows |
382 | 1076 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
|
1077 more convenient for editing. The upper window is the selected window. |
108 | 1078 |
56391
fa07df089602
(save-selected-window, one-window-p)
Luc Teirlinck <teirllm@auburn.edu>
parents:
55825
diff
changeset
|
1079 Otherwise, we choose window starts so as to minimize the amount of |
382 | 1080 redisplay; this is convenient on slow terminals. The new selected |
1081 window is the one that the current value of point appears in. The | |
1082 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
|
1083 new mode line. |
fa07df089602
(save-selected-window, one-window-p)
Luc Teirlinck <teirllm@auburn.edu>
parents:
55825
diff
changeset
|
1084 |
fa07df089602
(save-selected-window, one-window-p)
Luc Teirlinck <teirllm@auburn.edu>
parents:
55825
diff
changeset
|
1085 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
|
1086 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
|
1087 window." |
36 | 1088 (interactive "P") |
1089 (let ((old-w (selected-window)) | |
108 | 1090 (old-point (point)) |
6670
b2c5fca3c10c
(split-window-vertically): If size is negative, measure from bottom.
Karl Heuer <kwzh@gnu.org>
parents:
6019
diff
changeset
|
1091 (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
|
1092 (window-full-p nil) |
86337
161416156d88
(balance-windows): Remove unused var `counter'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
86159
diff
changeset
|
1093 new-w bottom moved) |
6670
b2c5fca3c10c
(split-window-vertically): If size is negative, measure from bottom.
Karl Heuer <kwzh@gnu.org>
parents:
6019
diff
changeset
|
1094 (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
|
1095 (setq new-w (split-window nil size)) |
419 | 1096 (or split-window-keep-point |
108 | 1097 (progn |
382 | 1098 (save-excursion |
1099 (set-buffer (window-buffer)) | |
1100 (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
|
1101 (setq moved (vertical-motion (window-height))) |
382 | 1102 (set-window-start new-w (point)) |
1103 (if (> (point) (window-point new-w)) | |
1104 (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
|
1105 (and (= moved (window-height)) |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
1106 (progn |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
1107 (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
|
1108 (vertical-motion -1))) |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
1109 (setq bottom (point))) |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
1110 (and window-full-p |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
1111 (<= bottom (point)) |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
1112 (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
|
1113 (and window-full-p |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
1114 (<= (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
|
1115 (progn |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
1116 (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
|
1117 (select-window new-w))))) |
18279
a9c40a80c9b1
(split-window-save-restore-data): New function that
Richard M. Stallman <rms@gnu.org>
parents:
17665
diff
changeset
|
1118 (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
|
1119 |
21118
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1120 ;; This is to avoid compiler warnings. |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1121 (defvar view-return-to-alist) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1122 |
18279
a9c40a80c9b1
(split-window-save-restore-data): New function that
Richard M. Stallman <rms@gnu.org>
parents:
17665
diff
changeset
|
1123 (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
|
1124 (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
|
1125 (if view-mode |
a9c40a80c9b1
(split-window-save-restore-data): New function that
Richard M. Stallman <rms@gnu.org>
parents:
17665
diff
changeset
|
1126 (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
|
1127 (if old-info |
10dc0a48bc2c
(split-window-save-restore-data):
Richard M. Stallman <rms@gnu.org>
parents:
53894
diff
changeset
|
1128 (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
|
1129 view-return-to-alist)))) |
3253
f4d37be94734
(split-window-vertically): Return the new window.
Richard M. Stallman <rms@gnu.org>
parents:
2529
diff
changeset
|
1130 new-w)) |
36 | 1131 |
1132 (defun split-window-horizontally (&optional arg) | |
1133 "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
|
1134 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
|
1135 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
|
1136 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
|
1137 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
|
1138 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
|
1139 |
fa07df089602
(save-selected-window, one-window-p)
Luc Teirlinck <teirllm@auburn.edu>
parents:
55825
diff
changeset
|
1140 The original, leftmost window remains selected. |
fa07df089602
(save-selected-window, one-window-p)
Luc Teirlinck <teirllm@auburn.edu>
parents:
55825
diff
changeset
|
1141 The return value is the new, rightmost window." |
36 | 1142 (interactive "P") |
18279
a9c40a80c9b1
(split-window-save-restore-data): New function that
Richard M. Stallman <rms@gnu.org>
parents:
17665
diff
changeset
|
1143 (let ((old-w (selected-window)) |
a9c40a80c9b1
(split-window-save-restore-data): New function that
Richard M. Stallman <rms@gnu.org>
parents:
17665
diff
changeset
|
1144 (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
|
1145 (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
|
1146 (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
|
1147 (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
|
1148 |
9f29610841ca
(window-text-height, set-window-text-height): New functions.
Miles Bader <miles@gnu.org>
parents:
32684
diff
changeset
|
1149 |
9f29610841ca
(window-text-height, set-window-text-height): New functions.
Miles Bader <miles@gnu.org>
parents:
32684
diff
changeset
|
1150 (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
|
1151 "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
|
1152 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
|
1153 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
|
1154 |
9f29610841ca
(window-text-height, set-window-text-height): New functions.
Miles Bader <miles@gnu.org>
parents:
32684
diff
changeset
|
1155 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
|
1156 |
9f29610841ca
(window-text-height, set-window-text-height): New functions.
Miles Bader <miles@gnu.org>
parents:
32684
diff
changeset
|
1157 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
|
1158 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
|
1159 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
|
1160 (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
|
1161 (unless (zerop delta) |
71557
695dbebf4c20
(set-window-text-height): Only set window-min-height to
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71083
diff
changeset
|
1162 ;; Setting window-min-height to a value like 1 can lead to very |
695dbebf4c20
(set-window-text-height): Only set window-min-height to
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71083
diff
changeset
|
1163 ;; bizarre displays because it also allows Emacs to make *other* |
695dbebf4c20
(set-window-text-height): Only set window-min-height to
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71083
diff
changeset
|
1164 ;; windows 1-line tall, which means that there's no more space for |
695dbebf4c20
(set-window-text-height): Only set window-min-height to
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71083
diff
changeset
|
1165 ;; the modeline. |
695dbebf4c20
(set-window-text-height): Only set window-min-height to
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71083
diff
changeset
|
1166 (let ((window-min-height (min 2 height))) ;One text line plus a modeline. |
32695
5a4f1fbd4ed7
(set-window-text-height): Force window-min-height to 1.
Miles Bader <miles@gnu.org>
parents:
32689
diff
changeset
|
1167 (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
|
1168 (save-selected-window |
5a4f1fbd4ed7
(set-window-text-height): Force window-min-height to 1.
Miles Bader <miles@gnu.org>
parents:
32689
diff
changeset
|
1169 (select-window window) |
5a4f1fbd4ed7
(set-window-text-height): Force window-min-height to 1.
Miles Bader <miles@gnu.org>
parents:
32689
diff
changeset
|
1170 (enlarge-window delta)) |
5a4f1fbd4ed7
(set-window-text-height): Force window-min-height to 1.
Miles Bader <miles@gnu.org>
parents:
32689
diff
changeset
|
1171 (enlarge-window delta)))))) |
32689
9f29610841ca
(window-text-height, set-window-text-height): New functions.
Miles Bader <miles@gnu.org>
parents:
32684
diff
changeset
|
1172 |
32681
569ef1445e17
(mode-line-window-height-fudge): New variable.
Miles Bader <miles@gnu.org>
parents:
31790
diff
changeset
|
1173 |
36 | 1174 (defun enlarge-window-horizontally (arg) |
1175 "Make current window ARG columns wider." | |
1176 (interactive "p") | |
1177 (enlarge-window arg t)) | |
1178 | |
1179 (defun shrink-window-horizontally (arg) | |
1180 "Make current window ARG columns narrower." | |
1181 (interactive "p") | |
1182 (shrink-window arg t)) | |
1183 | |
23748
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
1184 (defun window-buffer-height (window) |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
1185 "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
|
1186 (with-current-buffer (window-buffer window) |
f7f0c6eb075b
(window-buffer-height): Use count-screen-lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59652
diff
changeset
|
1187 (max 1 |
f7f0c6eb075b
(window-buffer-height): Use count-screen-lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59652
diff
changeset
|
1188 (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
|
1189 ;; 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
|
1190 ;; 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
|
1191 (eobp) |
f7f0c6eb075b
(window-buffer-height): Use count-screen-lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59652
diff
changeset
|
1192 window)))) |
23748
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
1193 |
28655
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
1194 (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
|
1195 "Return the number of screen lines in the region. |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
1196 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
|
1197 due to line breaking, display table, etc. |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
1198 |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
1199 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
|
1200 respectively. |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
1201 |
33708
7c2b5397acbc
General comment and spacing fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33537
diff
changeset
|
1202 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
|
1203 COUNT-FINAL-NEWLINE is non-nil. |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
1204 |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
1205 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
|
1206 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
|
1207 to use the selected window's parameters. |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
1208 |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
1209 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
|
1210 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
|
1211 `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
|
1212 in some window." |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
1213 (unless beg |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
1214 (setq beg (point-min))) |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
1215 (unless end |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
1216 (setq end (point-max))) |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
1217 (if (= beg end) |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
1218 0 |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
1219 (save-excursion |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
1220 (save-restriction |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
1221 (widen) |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
1222 (narrow-to-region (min beg end) |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
1223 (if (and (not count-final-newline) |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
1224 (= ?\n (char-before (max beg end)))) |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
1225 (1- (max beg end)) |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
1226 (max beg end))) |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
1227 (goto-char (point-min)) |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
1228 (1+ (vertical-motion (buffer-size) window)))))) |
2ea744c8844a
(count-screen-lines): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26268
diff
changeset
|
1229 |
32705
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
1230 (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
|
1231 "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
|
1232 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
|
1233 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
|
1234 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
|
1235 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
|
1236 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
|
1237 |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
1238 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
|
1239 header-line." |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
1240 (interactive) |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
1241 |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
1242 (when (null window) |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
1243 (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
|
1244 (when (null max-height) |
29a87f28cd51
(fit-window-to-buffer): Change defaulting of MAX-HEIGHT slightly.
Miles Bader <miles@gnu.org>
parents:
32736
diff
changeset
|
1245 (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
|
1246 |
33478
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
1247 (let* ((buf |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
1248 ;; 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
|
1249 (window-buffer window)) |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
1250 (window-height |
32705
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
1251 ;; The current height of WINDOW |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
1252 (window-height window)) |
33478
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
1253 (desired-height |
32705
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
1254 ;; 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
|
1255 ;; (`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
|
1256 (with-current-buffer buf |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
1257 (+ (count-screen-lines) |
33536
035e7b097577
(fit-window-to-buffer): Be sure to acquire at least
Kenichi Handa <handa@m17n.org>
parents:
33478
diff
changeset
|
1258 ;; 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
|
1259 ;; 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
|
1260 ;; for cursor. |
035e7b097577
(fit-window-to-buffer): Be sure to acquire at least
Kenichi Handa <handa@m17n.org>
parents:
33478
diff
changeset
|
1261 (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
|
1262 1 0) |
33478
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
1263 ;; 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
|
1264 (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
|
1265 mode-line-format) |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
1266 1 0) |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
1267 ;; 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
|
1268 (if header-line-format 1 0)))) |
32705
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
1269 (delta |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
1270 ;; 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
|
1271 ;; 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
|
1272 (- (max (min desired-height max-height) |
32705
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
1273 (or min-height window-min-height)) |
81770
ffd64654faa7
(fit-window-to-buffer): Remove setting of window-min-height
Jan Djärv <jan.h.d@swipnet.se>
parents:
75347
diff
changeset
|
1274 window-height))) |
32705
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
1275 |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
1276 ;; 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
|
1277 ;; 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
|
1278 (when (with-current-buffer buf |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
1279 (and (eobp) (bolp) (not (bobp)))) |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
1280 (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
|
1281 |
33478
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
1282 (save-selected-window |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
1283 (select-window window) |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
1284 |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
1285 ;; 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
|
1286 ;; 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
|
1287 (unless (zerop delta) |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
1288 (enlarge-window delta)) |
33475
b18c7c71cf2e
(fit-window-to-buffer): Don't check
Kenichi Handa <handa@m17n.org>
parents:
32811
diff
changeset
|
1289 |
33478
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
1290 ;; 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
|
1291 ;; enlarge the window. |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
1292 (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
|
1293 (save-excursion |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
1294 (goto-char (point-max)) |
34079
6316cacc1e16
(fit-window-to-buffer): Handle non-nil `truncate-lines'.
Miles Bader <miles@gnu.org>
parents:
33708
diff
changeset
|
1295 (when (and (bolp) (not (bobp))) |
6316cacc1e16
(fit-window-to-buffer): Handle non-nil `truncate-lines'.
Miles Bader <miles@gnu.org>
parents:
33708
diff
changeset
|
1296 ;; Don't include final newline |
6316cacc1e16
(fit-window-to-buffer): Handle non-nil `truncate-lines'.
Miles Bader <miles@gnu.org>
parents:
33708
diff
changeset
|
1297 (backward-char 1)) |
6316cacc1e16
(fit-window-to-buffer): Handle non-nil `truncate-lines'.
Miles Bader <miles@gnu.org>
parents:
33708
diff
changeset
|
1298 (when truncate-lines |
6316cacc1e16
(fit-window-to-buffer): Handle non-nil `truncate-lines'.
Miles Bader <miles@gnu.org>
parents:
33708
diff
changeset
|
1299 ;; 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
|
1300 ;; 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
|
1301 ;; 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
|
1302 ;; 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
|
1303 ;; the edge of the window. |
6316cacc1e16
(fit-window-to-buffer): Handle non-nil `truncate-lines'.
Miles Bader <miles@gnu.org>
parents:
33708
diff
changeset
|
1304 (forward-line 0)) |
6316cacc1e16
(fit-window-to-buffer): Handle non-nil `truncate-lines'.
Miles Bader <miles@gnu.org>
parents:
33708
diff
changeset
|
1305 (point))))) |
33478
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
1306 (set-window-vscroll window 0) |
05a649280be2
(fit-window-to-buffer): Handle windows without mode-lines.
Miles Bader <miles@gnu.org>
parents:
33475
diff
changeset
|
1307 (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
|
1308 (= 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
|
1309 (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
|
1310 (enlarge-window 1) |
33537
53c51fd75027
(fit-window-to-buffer): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
33536
diff
changeset
|
1311 (setq desired-height (1+ desired-height))))))) |
32705
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
1312 |
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
|
1313 (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
|
1314 "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
|
1315 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
|
1316 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
|
1317 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
|
1318 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
|
1319 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
|
1320 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
|
1321 (interactive) |
32705
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
1322 (when (null window) |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
1323 (setq window (selected-window))) |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
1324 (let* ((frame (window-frame window)) |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
1325 (mini (frame-parameter frame 'minibuffer)) |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
1326 (edges (window-edges window))) |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
1327 (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
|
1328 (window-safely-shrinkable-p) |
32705
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
1329 (pos-visible-in-window-p (point-min) window) |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
1330 (not (eq mini 'only)) |
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
1331 (or (not mini) |
36666
2b284278da9c
(shrink-window-if-larger-than-buffer): Handle frame
Gerd Moellmann <gerd@gnu.org>
parents:
36366
diff
changeset
|
1332 (let ((mini-window (minibuffer-window frame))) |
2b284278da9c
(shrink-window-if-larger-than-buffer): Handle frame
Gerd Moellmann <gerd@gnu.org>
parents:
36366
diff
changeset
|
1333 (or (null mini-window) |
2b284278da9c
(shrink-window-if-larger-than-buffer): Handle frame
Gerd Moellmann <gerd@gnu.org>
parents:
36366
diff
changeset
|
1334 (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
|
1335 (< (nth 3 edges) |
2b284278da9c
(shrink-window-if-larger-than-buffer): Handle frame
Gerd Moellmann <gerd@gnu.org>
parents:
36366
diff
changeset
|
1336 (nth 1 (window-edges mini-window))) |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48941
diff
changeset
|
1337 (> (nth 1 edges) |
36666
2b284278da9c
(shrink-window-if-larger-than-buffer): Handle frame
Gerd Moellmann <gerd@gnu.org>
parents:
36366
diff
changeset
|
1338 (frame-parameter frame 'menu-bar-lines)))))) |
32705
7d93bad80655
(fit-window-to-buffer): New function.
Miles Bader <miles@gnu.org>
parents:
32695
diff
changeset
|
1339 (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
|
1340 |
479c96f4be3a
(kill-buffer-and-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
15076
diff
changeset
|
1341 (defun kill-buffer-and-window () |
479c96f4be3a
(kill-buffer-and-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
15076
diff
changeset
|
1342 "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
|
1343 (interactive) |
52481
f1cce2846e29
(kill-buffer-and-window): Remove `yes-or-no-p' so that
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
1344 (let ((window-to-delete (selected-window)) |
73447
7c85e65e0464
(kill-buffer-and-window): Fix a bug where an aborted
David Kastrup <dak@gnu.org>
parents:
72737
diff
changeset
|
1345 (buffer-to-kill (current-buffer)) |
52481
f1cce2846e29
(kill-buffer-and-window): Remove `yes-or-no-p' so that
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
1346 (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
|
1347 (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
|
1348 (delete-window) |
f1cce2846e29
(kill-buffer-and-window): Remove `yes-or-no-p' so that
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
1349 (error nil))))) |
73447
7c85e65e0464
(kill-buffer-and-window): Fix a bug where an aborted
David Kastrup <dak@gnu.org>
parents:
72737
diff
changeset
|
1350 (unwind-protect |
7c85e65e0464
(kill-buffer-and-window): Fix a bug where an aborted
David Kastrup <dak@gnu.org>
parents:
72737
diff
changeset
|
1351 (progn |
7c85e65e0464
(kill-buffer-and-window): Fix a bug where an aborted
David Kastrup <dak@gnu.org>
parents:
72737
diff
changeset
|
1352 (add-hook 'kill-buffer-hook delete-window-hook t t) |
7c85e65e0464
(kill-buffer-and-window): Fix a bug where an aborted
David Kastrup <dak@gnu.org>
parents:
72737
diff
changeset
|
1353 (if (kill-buffer (current-buffer)) |
7c85e65e0464
(kill-buffer-and-window): Fix a bug where an aborted
David Kastrup <dak@gnu.org>
parents:
72737
diff
changeset
|
1354 ;; If `delete-window' failed before, we rerun it to regenerate |
7c85e65e0464
(kill-buffer-and-window): Fix a bug where an aborted
David Kastrup <dak@gnu.org>
parents:
72737
diff
changeset
|
1355 ;; the error so it can be seen in the echo area. |
7c85e65e0464
(kill-buffer-and-window): Fix a bug where an aborted
David Kastrup <dak@gnu.org>
parents:
72737
diff
changeset
|
1356 (when (eq (selected-window) window-to-delete) |
7c85e65e0464
(kill-buffer-and-window): Fix a bug where an aborted
David Kastrup <dak@gnu.org>
parents:
72737
diff
changeset
|
1357 (delete-window)))) |
7c85e65e0464
(kill-buffer-and-window): Fix a bug where an aborted
David Kastrup <dak@gnu.org>
parents:
72737
diff
changeset
|
1358 ;; If the buffer is not dead for some reason (probably because |
7c85e65e0464
(kill-buffer-and-window): Fix a bug where an aborted
David Kastrup <dak@gnu.org>
parents:
72737
diff
changeset
|
1359 ;; of a `quit' signal), remove the hook again. |
7c85e65e0464
(kill-buffer-and-window): Fix a bug where an aborted
David Kastrup <dak@gnu.org>
parents:
72737
diff
changeset
|
1360 (condition-case nil |
7c85e65e0464
(kill-buffer-and-window): Fix a bug where an aborted
David Kastrup <dak@gnu.org>
parents:
72737
diff
changeset
|
1361 (with-current-buffer buffer-to-kill |
7c85e65e0464
(kill-buffer-and-window): Fix a bug where an aborted
David Kastrup <dak@gnu.org>
parents:
72737
diff
changeset
|
1362 (remove-hook 'kill-buffer-hook delete-window-hook t)) |
7c85e65e0464
(kill-buffer-and-window): Fix a bug where an aborted
David Kastrup <dak@gnu.org>
parents:
72737
diff
changeset
|
1363 (error nil))))) |
16469
479c96f4be3a
(kill-buffer-and-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
15076
diff
changeset
|
1364 |
21118
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1365 (defun quit-window (&optional kill window) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1366 "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
|
1367 \(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
|
1368 With a prefix argument, kill the buffer instead. |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1369 |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1370 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
|
1371 otherwise bury it. |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1372 |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1373 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
|
1374 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
|
1375 (interactive "P") |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1376 (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
|
1377 (frame (window-frame (or window (selected-window)))) |
21118
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1378 (window-solitary |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1379 (save-selected-window |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1380 (if window |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1381 (select-window window)) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1382 (one-window-p t))) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1383 window-handled) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1384 |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1385 (save-selected-window |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1386 (if window |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1387 (select-window window)) |
21860
58d299618042
(quit-window): Don't try to switch buffers
Richard M. Stallman <rms@gnu.org>
parents:
21118
diff
changeset
|
1388 (or (window-minibuffer-p) |
58d299618042
(quit-window): Don't try to switch buffers
Richard M. Stallman <rms@gnu.org>
parents:
21118
diff
changeset
|
1389 (window-dedicated-p (selected-window)) |
58d299618042
(quit-window): Don't try to switch buffers
Richard M. Stallman <rms@gnu.org>
parents:
21118
diff
changeset
|
1390 (switch-to-buffer (other-buffer)))) |
21118
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1391 |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1392 ;; 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
|
1393 ;; 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
|
1394 (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
|
1395 (delq frame (visible-frame-list)) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1396 window-solitary |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1397 (if (and (eq default-minibuffer-frame frame) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1398 (= 1 (length (minibuffer-frame-list)))) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1399 (setq window nil) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1400 (delete-frame frame) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1401 (setq window-handled t))) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1402 |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1403 ;; Deal with the buffer. |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1404 (if kill |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1405 (kill-buffer buffer) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1406 (bury-buffer buffer)) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1407 |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1408 ;; Maybe get rid of the window. |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1409 (and window (not window-handled) (not window-solitary) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1410 (delete-window window)))) |
86159
c679b91efdfa
(recenter-last-op): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85189
diff
changeset
|
1411 |
c679b91efdfa
(recenter-last-op): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85189
diff
changeset
|
1412 (defvar recenter-last-op nil |
c679b91efdfa
(recenter-last-op): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85189
diff
changeset
|
1413 "Indicates the last recenter operation performed. |
c679b91efdfa
(recenter-last-op): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85189
diff
changeset
|
1414 Possible values: `top', `middle', `bottom'.") |
c679b91efdfa
(recenter-last-op): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85189
diff
changeset
|
1415 |
c679b91efdfa
(recenter-last-op): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85189
diff
changeset
|
1416 (defun recenter-top-bottom (&optional arg) |
c679b91efdfa
(recenter-last-op): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85189
diff
changeset
|
1417 "Move current line to window center, top, and bottom, successively. |
c679b91efdfa
(recenter-last-op): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85189
diff
changeset
|
1418 With a prefix argument, this is the same as `recenter': |
c679b91efdfa
(recenter-last-op): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85189
diff
changeset
|
1419 With numeric prefix ARG, move current line to window-line ARG. |
c679b91efdfa
(recenter-last-op): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85189
diff
changeset
|
1420 With plain `C-u', move current line to window center. |
c679b91efdfa
(recenter-last-op): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85189
diff
changeset
|
1421 |
c679b91efdfa
(recenter-last-op): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85189
diff
changeset
|
1422 Otherwise move current line to window center on first call, and to |
c679b91efdfa
(recenter-last-op): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85189
diff
changeset
|
1423 top, middle, or bottom on successive calls. |
c679b91efdfa
(recenter-last-op): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85189
diff
changeset
|
1424 |
87381 | 1425 The cycling order is: middle -> top -> bottom. |
86159
c679b91efdfa
(recenter-last-op): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85189
diff
changeset
|
1426 |
c679b91efdfa
(recenter-last-op): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85189
diff
changeset
|
1427 Top and bottom destinations are actually `scroll-conservatively' lines |
c679b91efdfa
(recenter-last-op): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85189
diff
changeset
|
1428 from true window top and bottom." |
c679b91efdfa
(recenter-last-op): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85189
diff
changeset
|
1429 (interactive "P") |
c679b91efdfa
(recenter-last-op): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85189
diff
changeset
|
1430 (cond |
c679b91efdfa
(recenter-last-op): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85189
diff
changeset
|
1431 (arg (recenter arg)) ; Always respect ARG. |
c679b91efdfa
(recenter-last-op): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85189
diff
changeset
|
1432 ((not (eq this-command last-command)) |
c679b91efdfa
(recenter-last-op): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85189
diff
changeset
|
1433 ;; First time - save mode and recenter. |
86337
161416156d88
(balance-windows): Remove unused var `counter'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
86159
diff
changeset
|
1434 (setq recenter-last-op 'middle) |
161416156d88
(balance-windows): Remove unused var `counter'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
86159
diff
changeset
|
1435 (recenter)) |
86159
c679b91efdfa
(recenter-last-op): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85189
diff
changeset
|
1436 (t ;; repeat: loop through various options. |
c679b91efdfa
(recenter-last-op): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85189
diff
changeset
|
1437 (setq recenter-last-op |
86999
44a6a92e5396
(recenter-top-bottom): Don't use `ecase'.
Richard M. Stallman <rms@gnu.org>
parents:
86337
diff
changeset
|
1438 (cond ((eq recenter-last-op 'middle) |
44a6a92e5396
(recenter-top-bottom): Don't use `ecase'.
Richard M. Stallman <rms@gnu.org>
parents:
86337
diff
changeset
|
1439 (recenter scroll-conservatively) |
44a6a92e5396
(recenter-top-bottom): Don't use `ecase'.
Richard M. Stallman <rms@gnu.org>
parents:
86337
diff
changeset
|
1440 'top) |
44a6a92e5396
(recenter-top-bottom): Don't use `ecase'.
Richard M. Stallman <rms@gnu.org>
parents:
86337
diff
changeset
|
1441 ((eq recenter-last-op 'top) |
44a6a92e5396
(recenter-top-bottom): Don't use `ecase'.
Richard M. Stallman <rms@gnu.org>
parents:
86337
diff
changeset
|
1442 (recenter (1- (- scroll-conservatively))) |
44a6a92e5396
(recenter-top-bottom): Don't use `ecase'.
Richard M. Stallman <rms@gnu.org>
parents:
86337
diff
changeset
|
1443 'bottom) |
44a6a92e5396
(recenter-top-bottom): Don't use `ecase'.
Richard M. Stallman <rms@gnu.org>
parents:
86337
diff
changeset
|
1444 ((eq recenter-last-op 'bottom) |
44a6a92e5396
(recenter-top-bottom): Don't use `ecase'.
Richard M. Stallman <rms@gnu.org>
parents:
86337
diff
changeset
|
1445 (recenter) |
44a6a92e5396
(recenter-top-bottom): Don't use `ecase'.
Richard M. Stallman <rms@gnu.org>
parents:
86337
diff
changeset
|
1446 'middle)))))) |
86159
c679b91efdfa
(recenter-last-op): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85189
diff
changeset
|
1447 |
c679b91efdfa
(recenter-last-op): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85189
diff
changeset
|
1448 (define-key global-map [?\C-l] 'recenter-top-bottom) |
72737
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1449 |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1450 (defvar mouse-autoselect-window-timer nil |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1451 "Timer used by delayed window autoselection.") |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1452 |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1453 (defvar mouse-autoselect-window-position nil |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1454 "Last mouse position recorded by delayed window autoselection.") |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1455 |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1456 (defvar mouse-autoselect-window-window nil |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1457 "Last window recorded by delayed window autoselection.") |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1458 |
73698
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1459 (defvar mouse-autoselect-window-state nil |
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1460 "When non-nil, special state of delayed window autoselection. |
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1461 Possible values are `suspend' \(suspend autoselection after a menu or |
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1462 scrollbar interaction\) and `select' \(the next invocation of |
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1463 'handle-select-window' shall select the window immediately\).") |
72737
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1464 |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1465 (defun mouse-autoselect-window-cancel (&optional force) |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1466 "Cancel delayed window autoselection. |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1467 Optional argument FORCE means cancel unconditionally." |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1468 (unless (and (not force) |
78994
c864c3573cef
(mouse-autoselect-window-cancel): Don't cancel for
Martin Rudalics <rudalics@gmx.at>
parents:
78492
diff
changeset
|
1469 ;; Don't cancel for select-window or select-frame events |
c864c3573cef
(mouse-autoselect-window-cancel): Don't cancel for
Martin Rudalics <rudalics@gmx.at>
parents:
78492
diff
changeset
|
1470 ;; or when the user drags a scroll bar. |
c864c3573cef
(mouse-autoselect-window-cancel): Don't cancel for
Martin Rudalics <rudalics@gmx.at>
parents:
78492
diff
changeset
|
1471 (or (memq this-command |
c864c3573cef
(mouse-autoselect-window-cancel): Don't cancel for
Martin Rudalics <rudalics@gmx.at>
parents:
78492
diff
changeset
|
1472 '(handle-select-window handle-switch-frame)) |
c864c3573cef
(mouse-autoselect-window-cancel): Don't cancel for
Martin Rudalics <rudalics@gmx.at>
parents:
78492
diff
changeset
|
1473 (and (eq this-command 'scroll-bar-toolkit-scroll) |
c864c3573cef
(mouse-autoselect-window-cancel): Don't cancel for
Martin Rudalics <rudalics@gmx.at>
parents:
78492
diff
changeset
|
1474 (memq (nth 4 (event-end last-input-event)) |
c864c3573cef
(mouse-autoselect-window-cancel): Don't cancel for
Martin Rudalics <rudalics@gmx.at>
parents:
78492
diff
changeset
|
1475 '(handle end-scroll))))) |
73698
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1476 (setq mouse-autoselect-window-state nil) |
72737
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1477 (when (timerp mouse-autoselect-window-timer) |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1478 (cancel-timer mouse-autoselect-window-timer)) |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1479 (remove-hook 'pre-command-hook 'mouse-autoselect-window-cancel))) |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1480 |
73698
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1481 (defun mouse-autoselect-window-start (mouse-position &optional window suspend) |
72737
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1482 "Start delayed window autoselection. |
73698
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1483 MOUSE-POSITION is the last position where the mouse was seen as returned |
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1484 by `mouse-position'. Optional argument WINDOW non-nil denotes the |
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1485 window where the mouse was seen. Optional argument SUSPEND non-nil |
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1486 means suspend autoselection." |
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1487 ;; Record values for MOUSE-POSITION, WINDOW, and SUSPEND. |
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1488 (setq mouse-autoselect-window-position mouse-position) |
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1489 (when window (setq mouse-autoselect-window-window window)) |
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1490 (setq mouse-autoselect-window-state (when suspend 'suspend)) |
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1491 ;; Install timer which runs `mouse-autoselect-window-select' after |
72737
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1492 ;; `mouse-autoselect-window' seconds. |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1493 (setq mouse-autoselect-window-timer |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1494 (run-at-time |
73698
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1495 (abs mouse-autoselect-window) nil 'mouse-autoselect-window-select))) |
72737
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1496 |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1497 (defun mouse-autoselect-window-select () |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1498 "Select window with delayed window autoselection. |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1499 If the mouse position has stabilized in a non-selected window, select |
78492
7c8949dbfa0d
Replace `iff' in doc-strings and comments.
Glenn Morris <rgm@gnu.org>
parents:
78236
diff
changeset
|
1500 that window. The minibuffer window is selected only if the minibuffer is |
72737
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1501 active. This function is run by `mouse-autoselect-window-timer'." |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1502 (condition-case nil |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1503 (let* ((mouse-position (mouse-position)) |
73698
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1504 (window |
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1505 (condition-case nil |
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1506 (window-at (cadr mouse-position) (cddr mouse-position) |
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1507 (car mouse-position)) |
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1508 (error nil)))) |
72737
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1509 (cond |
73698
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1510 ((or (menu-or-popup-active-p) |
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1511 (and window |
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1512 (not (coordinates-in-window-p (cdr mouse-position) window)))) |
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1513 ;; A menu / popup dialog is active or the mouse is on the scroll-bar |
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1514 ;; of WINDOW, temporarily suspend delayed autoselection. |
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1515 (mouse-autoselect-window-start mouse-position nil t)) |
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1516 ((eq mouse-autoselect-window-state 'suspend) |
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1517 ;; Delayed autoselection was temporarily suspended, reenable it. |
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1518 (mouse-autoselect-window-start mouse-position)) |
72737
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1519 ((and window (not (eq window (selected-window))) |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1520 (or (not (numberp mouse-autoselect-window)) |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1521 (and (> mouse-autoselect-window 0) |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1522 ;; If `mouse-autoselect-window' is positive, select |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1523 ;; window if the window is the same as before. |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1524 (eq window mouse-autoselect-window-window)) |
78492
7c8949dbfa0d
Replace `iff' in doc-strings and comments.
Glenn Morris <rgm@gnu.org>
parents:
78236
diff
changeset
|
1525 ;; Otherwise select window if the mouse is at the same |
72737
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1526 ;; position as before. Observe that the first test after |
73698
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1527 ;; starting autoselection usually fails since the value of |
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1528 ;; `mouse-autoselect-window-position' recorded there is the |
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1529 ;; position where the mouse has entered the new window and |
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1530 ;; not necessarily where the mouse has stopped moving. |
72737
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1531 (equal mouse-position mouse-autoselect-window-position)) |
78492
7c8949dbfa0d
Replace `iff' in doc-strings and comments.
Glenn Morris <rgm@gnu.org>
parents:
78236
diff
changeset
|
1532 ;; The minibuffer is a candidate window if it's active. |
72737
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1533 (or (not (window-minibuffer-p window)) |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1534 (eq window (active-minibuffer-window)))) |
73698
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1535 ;; Mouse position has stabilized in non-selected window: Cancel |
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1536 ;; delayed autoselection and try to select that window. |
72737
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1537 (mouse-autoselect-window-cancel t) |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1538 ;; Select window where mouse appears unless the selected window is the |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1539 ;; minibuffer. Use `unread-command-events' in order to execute pre- |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1540 ;; and post-command hooks and trigger idle timers. To avoid delaying |
73698
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1541 ;; autoselection again, set `mouse-autoselect-window-state'." |
72737
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1542 (unless (window-minibuffer-p (selected-window)) |
73698
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1543 (setq mouse-autoselect-window-state 'select) |
72737
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1544 (setq unread-command-events |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1545 (cons (list 'select-window (list window)) |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1546 unread-command-events)))) |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1547 ((or (and window (eq window (selected-window))) |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1548 (not (numberp mouse-autoselect-window)) |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1549 (equal mouse-position mouse-autoselect-window-position)) |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1550 ;; Mouse position has either stabilized in the selected window or at |
73698
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1551 ;; `mouse-autoselect-window-position': Cancel delayed autoselection. |
72737
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1552 (mouse-autoselect-window-cancel t)) |
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1553 (t |
73698
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1554 ;; Mouse position has not stabilized yet, resume delayed |
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1555 ;; autoselection. |
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1556 (mouse-autoselect-window-start mouse-position window)))) |
72737
455031002c62
* window.el (mouse-autoselect-window-timer)
Chong Yidong <cyd@stupidchicken.com>
parents:
72182
diff
changeset
|
1557 (error nil))) |
21118
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
1558 |
44296
915a76139f37
(handle-select-window): New function.
Pavel Janík <Pavel@Janik.cz>
parents:
43095
diff
changeset
|
1559 (defun handle-select-window (event) |
915a76139f37
(handle-select-window): New function.
Pavel Janík <Pavel@Janik.cz>
parents:
43095
diff
changeset
|
1560 "Handle select-window events." |
915a76139f37
(handle-select-window): New function.
Pavel Janík <Pavel@Janik.cz>
parents:
43095
diff
changeset
|
1561 (interactive "e") |
915a76139f37
(handle-select-window): New function.
Pavel Janík <Pavel@Janik.cz>
parents:
43095
diff
changeset
|
1562 (let ((window (posn-window (event-start event)))) |
78994
c864c3573cef
(mouse-autoselect-window-cancel): Don't cancel for
Martin Rudalics <rudalics@gmx.at>
parents:
78492
diff
changeset
|
1563 (unless (or (not (window-live-p window)) |
c864c3573cef
(mouse-autoselect-window-cancel): Don't cancel for
Martin Rudalics <rudalics@gmx.at>
parents:
78492
diff
changeset
|
1564 ;; Don't switch if we're currently in the minibuffer. |
c864c3573cef
(mouse-autoselect-window-cancel): Don't cancel for
Martin Rudalics <rudalics@gmx.at>
parents:
78492
diff
changeset
|
1565 ;; This tries to work around problems where the |
c864c3573cef
(mouse-autoselect-window-cancel): Don't cancel for
Martin Rudalics <rudalics@gmx.at>
parents:
78492
diff
changeset
|
1566 ;; minibuffer gets unselected unexpectedly, and where |
c864c3573cef
(mouse-autoselect-window-cancel): Don't cancel for
Martin Rudalics <rudalics@gmx.at>
parents:
78492
diff
changeset
|
1567 ;; you then have to move your mouse all the way down to |
c864c3573cef
(mouse-autoselect-window-cancel): Don't cancel for
Martin Rudalics <rudalics@gmx.at>
parents:
78492
diff
changeset
|
1568 ;; the minibuffer to select it. |
c864c3573cef
(mouse-autoselect-window-cancel): Don't cancel for
Martin Rudalics <rudalics@gmx.at>
parents:
78492
diff
changeset
|
1569 (window-minibuffer-p (selected-window)) |
c864c3573cef
(mouse-autoselect-window-cancel): Don't cancel for
Martin Rudalics <rudalics@gmx.at>
parents:
78492
diff
changeset
|
1570 ;; Don't switch to minibuffer window unless it's active. |
c864c3573cef
(mouse-autoselect-window-cancel): Don't cancel for
Martin Rudalics <rudalics@gmx.at>
parents:
78492
diff
changeset
|
1571 (and (window-minibuffer-p window) |
c864c3573cef
(mouse-autoselect-window-cancel): Don't cancel for
Martin Rudalics <rudalics@gmx.at>
parents:
78492
diff
changeset
|
1572 (not (minibuffer-window-active-p window))) |
c864c3573cef
(mouse-autoselect-window-cancel): Don't cancel for
Martin Rudalics <rudalics@gmx.at>
parents:
78492
diff
changeset
|
1573 ;; Don't switch when autoselection shall be delayed. |
c864c3573cef
(mouse-autoselect-window-cancel): Don't cancel for
Martin Rudalics <rudalics@gmx.at>
parents:
78492
diff
changeset
|
1574 (and (numberp mouse-autoselect-window) |
c864c3573cef
(mouse-autoselect-window-cancel): Don't cancel for
Martin Rudalics <rudalics@gmx.at>
parents:
78492
diff
changeset
|
1575 (not (zerop mouse-autoselect-window)) |
c864c3573cef
(mouse-autoselect-window-cancel): Don't cancel for
Martin Rudalics <rudalics@gmx.at>
parents:
78492
diff
changeset
|
1576 (not (eq mouse-autoselect-window-state 'select)) |
c864c3573cef
(mouse-autoselect-window-cancel): Don't cancel for
Martin Rudalics <rudalics@gmx.at>
parents:
78492
diff
changeset
|
1577 (progn |
c864c3573cef
(mouse-autoselect-window-cancel): Don't cancel for
Martin Rudalics <rudalics@gmx.at>
parents:
78492
diff
changeset
|
1578 ;; Cancel any delayed autoselection. |
c864c3573cef
(mouse-autoselect-window-cancel): Don't cancel for
Martin Rudalics <rudalics@gmx.at>
parents:
78492
diff
changeset
|
1579 (mouse-autoselect-window-cancel t) |
c864c3573cef
(mouse-autoselect-window-cancel): Don't cancel for
Martin Rudalics <rudalics@gmx.at>
parents:
78492
diff
changeset
|
1580 ;; Start delayed autoselection from current mouse position |
c864c3573cef
(mouse-autoselect-window-cancel): Don't cancel for
Martin Rudalics <rudalics@gmx.at>
parents:
78492
diff
changeset
|
1581 ;; and window. |
c864c3573cef
(mouse-autoselect-window-cancel): Don't cancel for
Martin Rudalics <rudalics@gmx.at>
parents:
78492
diff
changeset
|
1582 (mouse-autoselect-window-start (mouse-position) window) |
c864c3573cef
(mouse-autoselect-window-cancel): Don't cancel for
Martin Rudalics <rudalics@gmx.at>
parents:
78492
diff
changeset
|
1583 ;; Executing a command cancels delayed autoselection. |
c864c3573cef
(mouse-autoselect-window-cancel): Don't cancel for
Martin Rudalics <rudalics@gmx.at>
parents:
78492
diff
changeset
|
1584 (add-hook |
c864c3573cef
(mouse-autoselect-window-cancel): Don't cancel for
Martin Rudalics <rudalics@gmx.at>
parents:
78492
diff
changeset
|
1585 'pre-command-hook 'mouse-autoselect-window-cancel)))) |
c864c3573cef
(mouse-autoselect-window-cancel): Don't cancel for
Martin Rudalics <rudalics@gmx.at>
parents:
78492
diff
changeset
|
1586 (when mouse-autoselect-window |
73698
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1587 ;; Reset state of delayed autoselection. |
97a25a5ed8a9
(mouse-autoselect-window-now): Remove variable.
Eli Zaretskii <eliz@gnu.org>
parents:
73447
diff
changeset
|
1588 (setq mouse-autoselect-window-state nil) |
78994
c864c3573cef
(mouse-autoselect-window-cancel): Don't cancel for
Martin Rudalics <rudalics@gmx.at>
parents:
78492
diff
changeset
|
1589 ;; Run `mouse-leave-buffer-hook' when autoselecting window. |
c864c3573cef
(mouse-autoselect-window-cancel): Don't cancel for
Martin Rudalics <rudalics@gmx.at>
parents:
78492
diff
changeset
|
1590 (run-hooks 'mouse-leave-buffer-hook)) |
c864c3573cef
(mouse-autoselect-window-cancel): Don't cancel for
Martin Rudalics <rudalics@gmx.at>
parents:
78492
diff
changeset
|
1591 (select-window window)))) |
44296
915a76139f37
(handle-select-window): New function.
Pavel Janík <Pavel@Janik.cz>
parents:
43095
diff
changeset
|
1592 |
94641
0280cb8774cc
(delete-other-windows-vertically): New function.
Sam Steingold <sds@gnu.org>
parents:
93404
diff
changeset
|
1593 (defun delete-other-windows-vertically (&optional window) |
0280cb8774cc
(delete-other-windows-vertically): New function.
Sam Steingold <sds@gnu.org>
parents:
93404
diff
changeset
|
1594 "Delete the windows in the same column with WINDOW, but not WINDOW itself. |
0280cb8774cc
(delete-other-windows-vertically): New function.
Sam Steingold <sds@gnu.org>
parents:
93404
diff
changeset
|
1595 This may be a useful alternative binding for \\[delete-other-windows] |
0280cb8774cc
(delete-other-windows-vertically): New function.
Sam Steingold <sds@gnu.org>
parents:
93404
diff
changeset
|
1596 if you often split windows horizontally." |
0280cb8774cc
(delete-other-windows-vertically): New function.
Sam Steingold <sds@gnu.org>
parents:
93404
diff
changeset
|
1597 (interactive) |
0280cb8774cc
(delete-other-windows-vertically): New function.
Sam Steingold <sds@gnu.org>
parents:
93404
diff
changeset
|
1598 (let* ((window (or window (selected-window))) |
0280cb8774cc
(delete-other-windows-vertically): New function.
Sam Steingold <sds@gnu.org>
parents:
93404
diff
changeset
|
1599 (edges (window-edges window)) |
0280cb8774cc
(delete-other-windows-vertically): New function.
Sam Steingold <sds@gnu.org>
parents:
93404
diff
changeset
|
1600 (w window) delenda) |
0280cb8774cc
(delete-other-windows-vertically): New function.
Sam Steingold <sds@gnu.org>
parents:
93404
diff
changeset
|
1601 (while (not (eq (setq w (next-window w 1)) window)) |
0280cb8774cc
(delete-other-windows-vertically): New function.
Sam Steingold <sds@gnu.org>
parents:
93404
diff
changeset
|
1602 (let ((e (window-edges w))) |
0280cb8774cc
(delete-other-windows-vertically): New function.
Sam Steingold <sds@gnu.org>
parents:
93404
diff
changeset
|
1603 (when (and (= (car e) (car edges)) |
0280cb8774cc
(delete-other-windows-vertically): New function.
Sam Steingold <sds@gnu.org>
parents:
93404
diff
changeset
|
1604 (= (caddr e) (caddr edges))) |
0280cb8774cc
(delete-other-windows-vertically): New function.
Sam Steingold <sds@gnu.org>
parents:
93404
diff
changeset
|
1605 (push w delenda)))) |
0280cb8774cc
(delete-other-windows-vertically): New function.
Sam Steingold <sds@gnu.org>
parents:
93404
diff
changeset
|
1606 (mapc 'delete-window delenda))) |
0280cb8774cc
(delete-other-windows-vertically): New function.
Sam Steingold <sds@gnu.org>
parents:
93404
diff
changeset
|
1607 |
36 | 1608 (define-key ctl-x-map "2" 'split-window-vertically) |
707 | 1609 (define-key ctl-x-map "3" 'split-window-horizontally) |
36 | 1610 (define-key ctl-x-map "}" 'enlarge-window-horizontally) |
1611 (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
|
1612 (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
|
1613 (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
|
1614 (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
|
1615 |
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
|
1616 ;; arch-tag: b508dfcc-c353-4c37-89fa-e773fe10cea9 |
33708
7c2b5397acbc
General comment and spacing fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33537
diff
changeset
|
1617 ;;; window.el ends here |