Mercurial > emacs
annotate lisp/window.el @ 98659:f19f5a4863df
(x-create-frame-with-faces): Don't call tool-bar-setup.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Sun, 12 Oct 2008 13:45:58 +0000 |
parents | 234a18b5c81e |
children | 49a2b54dc78a |
rev | line source |
---|---|
98135
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1 ;;; window.el --- GNU Emacs window commands aside from those written in C |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
2 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
3 ;; Copyright (C) 1985, 1989, 1992, 1993, 1994, 2000, 2001, 2002, |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
4 ;; 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
5 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
6 ;; Maintainer: FSF |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
7 ;; Keywords: internal |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
8 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
9 ;; This file is part of GNU Emacs. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
10 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
11 ;; GNU Emacs is free software: you can redistribute it and/or modify |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
12 ;; it under the terms of the GNU General Public License as published by |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
13 ;; the Free Software Foundation, either version 3 of the License, or |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
14 ;; (at your option) any later version. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
15 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
16 ;; GNU Emacs is distributed in the hope that it will be useful, |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
19 ;; GNU General Public License for more details. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
20 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
21 ;; You should have received a copy of the GNU General Public License |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
23 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
24 ;;; Commentary: |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
25 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
26 ;; Window tree functions. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
27 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
28 ;;; Code: |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
29 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
30 (eval-when-compile (require 'cl)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
31 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
32 (defvar window-size-fixed nil |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
33 "*Non-nil in a buffer means windows displaying the buffer are fixed-size. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
34 If the value is `height', then only the window's height is fixed. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
35 If the value is `width', then only the window's width is fixed. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
36 Any other non-nil value fixes both the width and the height. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
37 Emacs won't change the size of any window displaying that buffer, |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
38 unless you explicitly change the size, or Emacs has no other choice.") |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
39 (make-variable-buffer-local 'window-size-fixed) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
40 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
41 (defmacro save-selected-window (&rest body) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
42 "Execute BODY, then select the window that was selected before BODY. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
43 The value returned is the value of the last form in BODY. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
44 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
45 This macro saves and restores the current buffer, since otherwise |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
46 its normal operation could potentially make a different |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
47 buffer current. It does not alter the buffer list ordering. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
48 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
49 This macro saves and restores the selected window, as well as |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
50 the selected window in each frame. If the previously selected |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
51 window of some frame is no longer live at the end of BODY, that |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
52 frame's selected window is left alone. If the selected window is |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
53 no longer live, then whatever window is selected at the end of |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
54 BODY remains selected." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
55 `(let ((save-selected-window-window (selected-window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
56 ;; It is necessary to save all of these, because calling |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
57 ;; select-window changes frame-selected-window for whatever |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
58 ;; frame that window is in. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
59 (save-selected-window-alist |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
60 (mapcar (lambda (frame) (cons frame (frame-selected-window frame))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
61 (frame-list)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
62 (save-current-buffer |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
63 (unwind-protect |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
64 (progn ,@body) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
65 (dolist (elt save-selected-window-alist) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
66 (and (frame-live-p (car elt)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
67 (window-live-p (cdr elt)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
68 (set-frame-selected-window (car elt) (cdr elt)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
69 (if (window-live-p save-selected-window-window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
70 (select-window save-selected-window-window)))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
71 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
72 (defun window-body-height (&optional window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
73 "Return number of lines in window WINDOW for actual buffer text. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
74 This does not include the mode line (if any) or the header line (if any)." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
75 (or window (setq window (selected-window))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
76 (if (window-minibuffer-p window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
77 (window-height window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
78 (with-current-buffer (window-buffer window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
79 (max 1 (- (window-height window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
80 (if mode-line-format 1 0) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
81 (if header-line-format 1 0)))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
82 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
83 (defun one-window-p (&optional nomini all-frames) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
84 "Return non-nil if the selected window is the only window. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
85 Optional arg NOMINI non-nil means don't count the minibuffer |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
86 even if it is active. Otherwise, the minibuffer is counted |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
87 when it is active. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
88 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
89 The optional arg ALL-FRAMES t means count windows on all frames. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
90 If it is `visible', count windows on all visible frames. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
91 ALL-FRAMES nil or omitted means count only the selected frame, |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
92 plus the minibuffer it uses (which may be on another frame). |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
93 ALL-FRAMES 0 means count all windows in all visible or iconified frames. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
94 If ALL-FRAMES is anything else, count only the selected frame." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
95 (let ((base-window (selected-window))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
96 (if (and nomini (eq base-window (minibuffer-window))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
97 (setq base-window (next-window base-window))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
98 (eq base-window |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
99 (next-window base-window (if nomini 'arg) all-frames)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
100 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
101 (defun window-current-scroll-bars (&optional window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
102 "Return the current scroll-bar settings in window WINDOW. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
103 Value is a cons (VERTICAL . HORIZONTAL) where VERTICAL specifies the |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
104 current location of the vertical scroll-bars (left, right, or nil), |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
105 and HORIZONTAL specifies the current location of the horizontal scroll |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
106 bars (top, bottom, or nil)." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
107 (let ((vert (nth 2 (window-scroll-bars window))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
108 (hor nil)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
109 (when (or (eq vert t) (eq hor t)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
110 (let ((fcsb (frame-current-scroll-bars |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
111 (window-frame (or window (selected-window)))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
112 (if (eq vert t) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
113 (setq vert (car fcsb))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
114 (if (eq hor t) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
115 (setq hor (cdr fcsb))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
116 (cons vert hor))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
117 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
118 (defun walk-windows (proc &optional minibuf all-frames) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
119 "Cycle through all visible windows, calling PROC for each one. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
120 PROC is called with a window as argument. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
121 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
122 Optional second arg MINIBUF t means count the minibuffer window even |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
123 if not active. MINIBUF nil or omitted means count the minibuffer only if |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
124 it is active. MINIBUF neither t nor nil means not to count the |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
125 minibuffer even if it is active. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
126 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
127 Several frames may share a single minibuffer; if the minibuffer |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
128 counts, all windows on all frames that share that minibuffer count |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
129 too. Therefore, if you are using a separate minibuffer frame |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
130 and the minibuffer is active and MINIBUF says it counts, |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
131 `walk-windows' includes the windows in the frame from which you |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
132 entered the minibuffer, as well as the minibuffer window. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
133 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
134 ALL-FRAMES is the optional third argument. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
135 ALL-FRAMES nil or omitted means cycle within the frames as specified above. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
136 ALL-FRAMES = `visible' means include windows on all visible frames. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
137 ALL-FRAMES = 0 means include windows on all visible and iconified frames. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
138 ALL-FRAMES = t means include windows on all frames including invisible frames. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
139 If ALL-FRAMES is a frame, it means include windows on that frame. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
140 Anything else means restrict to the selected frame." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
141 ;; If we start from the minibuffer window, don't fail to come back to it. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
142 (if (window-minibuffer-p (selected-window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
143 (setq minibuf t)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
144 (save-selected-window |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
145 (if (framep all-frames) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
146 (select-window (frame-first-window all-frames))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
147 (let* (walk-windows-already-seen |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
148 (walk-windows-current (selected-window))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
149 (while (progn |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
150 (setq walk-windows-current |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
151 (next-window walk-windows-current minibuf all-frames)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
152 (not (memq walk-windows-current walk-windows-already-seen))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
153 (setq walk-windows-already-seen |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
154 (cons walk-windows-current walk-windows-already-seen)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
155 (funcall proc walk-windows-current))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
156 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
157 (defun get-window-with-predicate (predicate &optional minibuf |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
158 all-frames default) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
159 "Return a window satisfying PREDICATE. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
160 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
161 This function cycles through all visible windows using `walk-windows', |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
162 calling PREDICATE on each one. PREDICATE is called with a window as |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
163 argument. The first window for which PREDICATE returns a non-nil |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
164 value is returned. If no window satisfies PREDICATE, DEFAULT is |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
165 returned. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
166 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
167 Optional second arg MINIBUF t means count the minibuffer window even |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
168 if not active. MINIBUF nil or omitted means count the minibuffer only if |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
169 it is active. MINIBUF neither t nor nil means not to count the |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
170 minibuffer even if it is active. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
171 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
172 Several frames may share a single minibuffer; if the minibuffer |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
173 counts, all windows on all frames that share that minibuffer count |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
174 too. Therefore, if you are using a separate minibuffer frame |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
175 and the minibuffer is active and MINIBUF says it counts, |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
176 `walk-windows' includes the windows in the frame from which you |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
177 entered the minibuffer, as well as the minibuffer window. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
178 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
179 ALL-FRAMES is the optional third argument. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
180 ALL-FRAMES nil or omitted means cycle within the frames as specified above. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
181 ALL-FRAMES = `visible' means include windows on all visible frames. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
182 ALL-FRAMES = 0 means include windows on all visible and iconified frames. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
183 ALL-FRAMES = t means include windows on all frames including invisible frames. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
184 If ALL-FRAMES is a frame, it means include windows on that frame. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
185 Anything else means restrict to the selected frame." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
186 (catch 'found |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
187 (walk-windows #'(lambda (window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
188 (when (funcall predicate window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
189 (throw 'found window))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
190 minibuf all-frames) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
191 default)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
192 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
193 (defalias 'some-window 'get-window-with-predicate) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
194 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
195 ;; This should probably be written in C (i.e., without using `walk-windows'). |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
196 (defun get-buffer-window-list (buffer &optional minibuf all-frames) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
197 "Return list of all windows displaying BUFFER, or nil if none. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
198 BUFFER can be a buffer or a buffer name. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
199 See `walk-windows' for the meaning of MINIBUF and ALL-FRAMES." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
200 (let ((buffer (if (bufferp buffer) buffer (get-buffer buffer))) windows) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
201 (walk-windows (function (lambda (window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
202 (if (eq (window-buffer window) buffer) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
203 (setq windows (cons window windows))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
204 minibuf all-frames) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
205 windows)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
206 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
207 (defun minibuffer-window-active-p (window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
208 "Return t if WINDOW (a minibuffer window) is now active." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
209 (eq window (active-minibuffer-window))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
210 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
211 (defun count-windows (&optional minibuf) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
212 "Return the number of visible windows. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
213 This counts the windows in the selected frame and (if the minibuffer is |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
214 to be counted) its minibuffer frame (if that's not the same frame). |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
215 The optional arg MINIBUF non-nil means count the minibuffer |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
216 even if it is inactive." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
217 (let ((count 0)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
218 (walk-windows (lambda (w) (setq count (+ count 1))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
219 minibuf) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
220 count)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
221 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
222 (defun window-safely-shrinkable-p (&optional window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
223 "Non-nil if the WINDOW can be shrunk without shrinking other windows. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
224 If WINDOW is nil or omitted, it defaults to the currently selected window." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
225 (with-selected-window (or window (selected-window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
226 (let ((edges (window-edges))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
227 (or (= (nth 2 edges) (nth 2 (window-edges (previous-window)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
228 (= (nth 0 edges) (nth 0 (window-edges (next-window)))))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
229 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
230 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
231 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
232 ;;; `balance-windows' subroutines using `window-tree' |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
233 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
234 ;;; Translate from internal window tree format |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
235 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
236 (defun bw-get-tree (&optional window-or-frame) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
237 "Get a window split tree in our format. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
238 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
239 WINDOW-OR-FRAME must be nil, a frame, or a window. If it is nil, |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
240 then the whole window split tree for `selected-frame' is returned. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
241 If it is a frame, then this is used instead. If it is a window, |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
242 then the smallest tree containing that window is returned." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
243 (when window-or-frame |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
244 (unless (or (framep window-or-frame) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
245 (windowp window-or-frame)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
246 (error "Not a frame or window: %s" window-or-frame))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
247 (let ((subtree (bw-find-tree-sub window-or-frame))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
248 (when subtree |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
249 (if (integerp subtree) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
250 nil |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
251 (bw-get-tree-1 subtree))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
252 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
253 (defun bw-get-tree-1 (split) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
254 (if (windowp split) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
255 split |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
256 (let ((dir (car split)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
257 (edges (car (cdr split))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
258 (childs (cdr (cdr split)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
259 (list |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
260 (cons 'dir (if dir 'ver 'hor)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
261 (cons 'b (nth 3 edges)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
262 (cons 'r (nth 2 edges)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
263 (cons 't (nth 1 edges)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
264 (cons 'l (nth 0 edges)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
265 (cons 'childs (mapcar #'bw-get-tree-1 childs)))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
266 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
267 (defun bw-find-tree-sub (window-or-frame &optional get-parent) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
268 (let* ((window (when (windowp window-or-frame) window-or-frame)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
269 (frame (when (windowp window) (window-frame window))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
270 (wt (car (window-tree frame)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
271 (when (< 1 (length (window-list frame 0))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
272 (if window |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
273 (bw-find-tree-sub-1 wt window get-parent) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
274 wt)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
275 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
276 (defun bw-find-tree-sub-1 (tree win &optional get-parent) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
277 (unless (windowp win) (error "Not a window: %s" win)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
278 (if (memq win tree) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
279 (if get-parent |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
280 get-parent |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
281 tree) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
282 (let ((childs (cdr (cdr tree))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
283 child |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
284 subtree) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
285 (while (and childs (not subtree)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
286 (setq child (car childs)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
287 (setq childs (cdr childs)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
288 (when (and child (listp child)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
289 (setq subtree (bw-find-tree-sub-1 child win get-parent)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
290 (if (integerp subtree) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
291 (progn |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
292 (if (= 1 subtree) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
293 tree |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
294 (1- subtree))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
295 subtree |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
296 )))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
297 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
298 ;;; Window or object edges |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
299 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
300 (defun bw-l (obj) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
301 "Left edge of OBJ." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
302 (if (windowp obj) (nth 0 (window-edges obj)) (cdr (assq 'l obj)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
303 (defun bw-t (obj) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
304 "Top edge of OBJ." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
305 (if (windowp obj) (nth 1 (window-edges obj)) (cdr (assq 't obj)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
306 (defun bw-r (obj) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
307 "Right edge of OBJ." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
308 (if (windowp obj) (nth 2 (window-edges obj)) (cdr (assq 'r obj)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
309 (defun bw-b (obj) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
310 "Bottom edge of OBJ." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
311 (if (windowp obj) (nth 3 (window-edges obj)) (cdr (assq 'b obj)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
312 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
313 ;;; Split directions |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
314 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
315 (defun bw-dir (obj) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
316 "Return window split tree direction if OBJ. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
317 If OBJ is a window return 'both. If it is a window split tree |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
318 then return its direction." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
319 (if (symbolp obj) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
320 obj |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
321 (if (windowp obj) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
322 'both |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
323 (let ((dir (cdr (assq 'dir obj)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
324 (unless (memq dir '(hor ver both)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
325 (error "Can't find dir in %s" obj)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
326 dir)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
327 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
328 (defun bw-eqdir (obj1 obj2) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
329 "Return t if window split tree directions are equal. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
330 OBJ1 and OBJ2 should be either windows or window split trees in |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
331 our format. The directions returned by `bw-dir' are compared and |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
332 t is returned if they are `eq' or one of them is 'both." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
333 (let ((dir1 (bw-dir obj1)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
334 (dir2 (bw-dir obj2))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
335 (or (eq dir1 dir2) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
336 (eq dir1 'both) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
337 (eq dir2 'both)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
338 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
339 ;;; Building split tree |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
340 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
341 (defun bw-refresh-edges (obj) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
342 "Refresh the edge information of OBJ and return OBJ." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
343 (unless (windowp obj) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
344 (let ((childs (cdr (assq 'childs obj))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
345 (ol 1000) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
346 (ot 1000) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
347 (or -1) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
348 (ob -1)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
349 (dolist (o childs) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
350 (when (> ol (bw-l o)) (setq ol (bw-l o))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
351 (when (> ot (bw-t o)) (setq ot (bw-t o))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
352 (when (< or (bw-r o)) (setq or (bw-r o))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
353 (when (< ob (bw-b o)) (setq ob (bw-b o)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
354 (setq obj (delq 'l obj)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
355 (setq obj (delq 't obj)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
356 (setq obj (delq 'r obj)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
357 (setq obj (delq 'b obj)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
358 (add-to-list 'obj (cons 'l ol)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
359 (add-to-list 'obj (cons 't ot)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
360 (add-to-list 'obj (cons 'r or)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
361 (add-to-list 'obj (cons 'b ob)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
362 )) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
363 obj) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
364 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
365 ;;; Balance windows |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
366 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
367 (defun balance-windows (&optional window-or-frame) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
368 "Make windows the same heights or widths in window split subtrees. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
369 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
370 When called non-interactively WINDOW-OR-FRAME may be either a |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
371 window or a frame. It then balances the windows on the implied |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
372 frame. If the parameter is a window only the corresponding window |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
373 subtree is balanced." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
374 (interactive) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
375 (let ( |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
376 (wt (bw-get-tree window-or-frame)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
377 (w) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
378 (h) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
379 (tried-sizes) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
380 (last-sizes) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
381 (windows (window-list nil 0))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
382 (when wt |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
383 (while (not (member last-sizes tried-sizes)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
384 (when last-sizes (setq tried-sizes (cons last-sizes tried-sizes))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
385 (setq last-sizes (mapcar (lambda (w) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
386 (window-edges w)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
387 windows)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
388 (when (eq 'hor (bw-dir wt)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
389 (setq w (- (bw-r wt) (bw-l wt)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
390 (when (eq 'ver (bw-dir wt)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
391 (setq h (- (bw-b wt) (bw-t wt)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
392 (bw-balance-sub wt w h))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
393 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
394 (defun bw-adjust-window (window delta horizontal) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
395 "Wrapper around `adjust-window-trailing-edge' with error checking. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
396 Arguments WINDOW, DELTA and HORIZONTAL are passed on to that function." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
397 ;; `adjust-window-trailing-edge' may fail if delta is too large. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
398 (while (>= (abs delta) 1) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
399 (condition-case err |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
400 (progn |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
401 (adjust-window-trailing-edge window delta horizontal) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
402 (setq delta 0)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
403 (error |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
404 ;;(message "adjust: %s" (error-message-string err)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
405 (setq delta (/ delta 2)))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
406 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
407 (defun bw-balance-sub (wt w h) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
408 (setq wt (bw-refresh-edges wt)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
409 (unless w (setq w (- (bw-r wt) (bw-l wt)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
410 (unless h (setq h (- (bw-b wt) (bw-t wt)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
411 (if (windowp wt) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
412 (progn |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
413 (when w |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
414 (let ((dw (- w (- (bw-r wt) (bw-l wt))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
415 (when (/= 0 dw) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
416 (bw-adjust-window wt dw t)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
417 (when h |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
418 (let ((dh (- h (- (bw-b wt) (bw-t wt))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
419 (when (/= 0 dh) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
420 (bw-adjust-window wt dh nil))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
421 (let* ((childs (cdr (assq 'childs wt))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
422 (cw (when w (/ w (if (bw-eqdir 'hor wt) (length childs) 1)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
423 (ch (when h (/ h (if (bw-eqdir 'ver wt) (length childs) 1))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
424 (dolist (c childs) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
425 (bw-balance-sub c cw ch))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
426 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
427 ;;; A different solution to balance-windows |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
428 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
429 (defun window-fixed-size-p (&optional window direction) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
430 "Non-nil if WINDOW cannot be resized in DIRECTION. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
431 DIRECTION can be nil (i.e. any), `height' or `width'." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
432 (with-current-buffer (window-buffer window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
433 (let ((fixed (and (boundp 'window-size-fixed) window-size-fixed))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
434 (when fixed |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
435 (not (and direction |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
436 (member (cons direction window-size-fixed) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
437 '((height . width) (width . height))))))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
438 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
439 (defvar window-area-factor 1 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
440 "Factor by which the window area should be over-estimated. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
441 This is used by `balance-windows-area'. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
442 Changing this globally has no effect.") |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
443 (make-variable-buffer-local 'window-area-factor) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
444 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
445 (defun balance-windows-area () |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
446 "Make all visible windows the same area (approximately). |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
447 See also `window-area-factor' to change the relative size of specific buffers." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
448 (interactive) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
449 (let* ((unchanged 0) (carry 0) (round 0) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
450 ;; Remove fixed-size windows. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
451 (wins (delq nil (mapcar (lambda (win) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
452 (if (not (window-fixed-size-p win)) win)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
453 (window-list nil 'nomini)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
454 (changelog nil) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
455 next) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
456 ;; Resizing a window changes the size of surrounding windows in complex |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
457 ;; ways, so it's difficult to balance them all. The introduction of |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
458 ;; `adjust-window-trailing-edge' made it a bit easier, but it is still |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
459 ;; very difficult to do. `balance-window' above takes an off-line |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
460 ;; approach: get the whole window tree, then balance it, then try to |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
461 ;; adjust the windows so they fit the result. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
462 ;; Here, instead, we take a "local optimization" approach, where we just |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
463 ;; go through all the windows several times until nothing needs to be |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
464 ;; changed. The main problem with this approach is that it's difficult |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
465 ;; to make sure it terminates, so we use some heuristic to try and break |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
466 ;; off infinite loops. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
467 ;; After a round without any change, we allow a second, to give a chance |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
468 ;; to the carry to propagate a minor imbalance from the end back to |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
469 ;; the beginning. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
470 (while (< unchanged 2) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
471 ;; (message "New round") |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
472 (setq unchanged (1+ unchanged) round (1+ round)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
473 (dolist (win wins) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
474 (setq next win) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
475 (while (progn (setq next (next-window next)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
476 (window-fixed-size-p next))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
477 ;; (assert (eq next (or (cadr (member win wins)) (car wins)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
478 (let* ((horiz |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
479 (< (car (window-edges win)) (car (window-edges next)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
480 (areadiff (/ (- (* (window-height next) (window-width next) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
481 (buffer-local-value 'window-area-factor |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
482 (window-buffer next))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
483 (* (window-height win) (window-width win) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
484 (buffer-local-value 'window-area-factor |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
485 (window-buffer win)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
486 (max (buffer-local-value 'window-area-factor |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
487 (window-buffer win)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
488 (buffer-local-value 'window-area-factor |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
489 (window-buffer next))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
490 (edgesize (if horiz |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
491 (+ (window-height win) (window-height next)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
492 (+ (window-width win) (window-width next)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
493 (diff (/ areadiff edgesize))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
494 (when (zerop diff) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
495 ;; Maybe diff is actually closer to 1 than to 0. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
496 (setq diff (/ (* 3 areadiff) (* 2 edgesize)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
497 (when (and (zerop diff) (not (zerop areadiff))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
498 (setq diff (/ (+ areadiff carry) edgesize)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
499 ;; Change things smoothly. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
500 (if (or (> diff 1) (< diff -1)) (setq diff (/ diff 2)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
501 (if (zerop diff) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
502 ;; Make sure negligible differences don't accumulate to |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
503 ;; become significant. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
504 (setq carry (+ carry areadiff)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
505 (bw-adjust-window win diff horiz) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
506 ;; (sit-for 0.5) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
507 (let ((change (cons win (window-edges win)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
508 ;; If the same change has been seen already for this window, |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
509 ;; we're most likely in an endless loop, so don't count it as |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
510 ;; a change. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
511 (unless (member change changelog) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
512 (push change changelog) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
513 (setq unchanged 0 carry 0))))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
514 ;; We've now basically balanced all the windows. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
515 ;; But there may be some minor off-by-one imbalance left over, |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
516 ;; so let's do some fine tuning. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
517 ;; (bw-finetune wins) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
518 ;; (message "Done in %d rounds" round) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
519 )) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
520 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
521 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
522 (defcustom display-buffer-function nil |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
523 "If non-nil, function to call to handle `display-buffer'. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
524 It will receive two args, the buffer and a flag which if non-nil |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
525 means that the currently selected window is not acceptable. It |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
526 should choose or create a window, display the specified buffer in |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
527 it, and return the window. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
528 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
529 Commands such as `switch-to-buffer-other-window' and |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
530 `find-file-other-window' work using this function." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
531 :type '(choice |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
532 (const nil) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
533 (function :tag "function")) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
534 :group 'windows) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
535 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
536 (defun special-display-p (buffer-name) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
537 "Return non-nil if a buffer named BUFFER-NAME gets a special frame. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
538 If the value is t, `display-buffer' or `pop-to-buffer' would |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
539 create a special frame for that buffer using the default frame |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
540 parameters. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
541 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
542 If the value is a list, it is a list of frame parameters that |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
543 would be used to make a frame for that buffer. The variables |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
544 `special-display-buffer-names' and `special-display-regexps' |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
545 control this." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
546 (let (tmp) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
547 (cond |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
548 ((not (stringp buffer-name))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
549 ;; Make sure to return t in the following two cases. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
550 ((member buffer-name special-display-buffer-names) t) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
551 ((setq tmp (assoc buffer-name special-display-buffer-names)) (cdr tmp)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
552 ((catch 'found |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
553 (dolist (regexp special-display-regexps) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
554 (cond |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
555 ((stringp regexp) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
556 (when (string-match-p regexp buffer-name) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
557 (throw 'found t))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
558 ((and (consp regexp) (stringp (car regexp)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
559 (string-match-p (car regexp) buffer-name)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
560 (throw 'found (cdr regexp)))))))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
561 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
562 (defcustom special-display-buffer-names nil |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
563 "List of buffer names that should have their own special frames. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
564 Displaying a buffer with `display-buffer' or `pop-to-buffer', if |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
565 its name is in this list, makes a special frame for it using |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
566 `special-display-function'. See also `special-display-regexps'. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
567 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
568 An element of the list can be a list instead of just a string. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
569 There are two ways to use a list as an element: |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
570 (BUFFER FRAME-PARAMETERS...) (BUFFER FUNCTION OTHER-ARGS...) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
571 In the first case, the FRAME-PARAMETERS are pairs of the form |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
572 \(PARAMETER . VALUE); these parameter values are used to create |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
573 the frame. In the second case, FUNCTION is called with BUFFER as |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
574 the first argument, followed by the OTHER-ARGS--it can display |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
575 BUFFER in any way it likes. All this is done by the function |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
576 found in `special-display-function'. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
577 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
578 If the specified frame parameters include (same-buffer . t), the |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
579 buffer is displayed in the currently selected window. Otherwise, if |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
580 they include (same-frame . t), the buffer is displayed in a new window |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
581 in the currently selected frame. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
582 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
583 If this variable appears \"not to work\", because you add a name to it |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
584 but that buffer still appears in the selected window, look at the |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
585 values of `same-window-buffer-names' and `same-window-regexps'. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
586 Those variables take precedence over this one." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
587 :type '(repeat (choice :tag "Buffer" |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
588 :value "" |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
589 (string :format "%v") |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
590 (cons :tag "With attributes" |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
591 :format "%v" |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
592 :value ("" . nil) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
593 (string :format "%v") |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
594 (repeat :tag "Attributes" |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
595 (cons :format "%v" |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
596 (symbol :tag "Parameter") |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
597 (sexp :tag "Value")))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
598 :group 'frames) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
599 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
600 (defcustom special-display-regexps nil |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
601 "List of regexps saying which buffers should have their own special frames. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
602 When displaying a buffer with `display-buffer' or |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
603 `pop-to-buffer', if any regexp in this list matches the buffer |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
604 name, it makes a special frame for the buffer by calling |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
605 `special-display-function'. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
606 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
607 An element of the list can be a list instead of just a string. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
608 There are two ways to use a list as an element: |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
609 (REGEXP FRAME-PARAMETERS...) (REGEXP FUNCTION OTHER-ARGS...) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
610 In the first case, the FRAME-PARAMETERS are pairs of the form |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
611 \(PARAMETER . VALUE); these parameter values are used to create |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
612 the frame. In the second case, FUNCTION is called with BUFFER as |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
613 the first argument, followed by the OTHER-ARGS--it can display |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
614 the buffer in any way it likes. All this is done by the function |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
615 found in `special-display-function'. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
616 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
617 If the specified frame parameters include (same-buffer . t), the |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
618 buffer is displayed in the currently selected window. Otherwise, |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
619 if they include (same-frame . t), the buffer is displayed in a |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
620 new window in the currently selected frame. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
621 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
622 If this variable appears \"not to work\", because you add a |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
623 regexp to it but the matching buffers still appear in the |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
624 selected window, look at the values of `same-window-buffer-names' |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
625 and `same-window-regexps'. Those variables take precedence over |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
626 this one." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
627 :type '(repeat (choice :tag "Buffer" |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
628 :value "" |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
629 (regexp :format "%v") |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
630 (cons :tag "With attributes" |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
631 :format "%v" |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
632 :value ("" . nil) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
633 (regexp :format "%v") |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
634 (repeat :tag "Attributes" |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
635 (cons :format "%v" |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
636 (symbol :tag "Parameter") |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
637 (sexp :tag "Value")))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
638 :group 'frames) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
639 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
640 (defcustom special-display-function 'special-display-popup-frame |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
641 "Function to call to make a new frame for a special buffer. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
642 It is called with two arguments, the buffer and optional buffer |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
643 specific data, and should return a window displaying that buffer. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
644 The default value normally makes a separate frame for the buffer, |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
645 using `special-display-frame-alist' to specify the frame |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
646 parameters. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
647 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
648 But if the buffer specific data includes (same-buffer . t) then |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
649 the buffer is displayed in the current selected window. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
650 Otherwise if it includes (same-frame . t) then the buffer is |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
651 displayed in a new window in the currently selected frame. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
652 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
653 A buffer is special if it is listed in |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
654 `special-display-buffer-names' or matches a regexp in |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
655 `special-display-regexps'." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
656 :type 'function |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
657 :group 'frames) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
658 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
659 (defun same-window-p (buffer-name) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
660 "Return non-nil if a buffer named BUFFER-NAME would be shown in the \"same\" window. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
661 This function returns non-nil if `display-buffer' or |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
662 `pop-to-buffer' would show a buffer named BUFFER-NAME in the |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
663 selected rather than \(as usual\) some other window. See |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
664 `same-window-buffer-names' and `same-window-regexps'." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
665 (cond |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
666 ((not (stringp buffer-name))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
667 ;; The elements of `same-window-buffer-names' can be buffer |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
668 ;; names or cons cells whose cars are buffer names. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
669 ((member buffer-name same-window-buffer-names)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
670 ((assoc buffer-name same-window-buffer-names)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
671 ((catch 'found |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
672 (dolist (regexp same-window-regexps) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
673 ;; The elements of `same-window-regexps' can be regexps |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
674 ;; or cons cells whose cars are regexps. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
675 (when (or (and (stringp regexp) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
676 (string-match regexp buffer-name)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
677 (and (consp regexp) (stringp (car regexp)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
678 (string-match-p (car regexp) buffer-name))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
679 (throw 'found t))))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
680 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
681 (defcustom same-window-buffer-names nil |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
682 "List of names of buffers that should appear in the \"same\" window. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
683 `display-buffer' and `pop-to-buffer' show a buffer whose name is |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
684 on this list in the selected rather than some other window. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
685 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
686 An element of this list can be a cons cell instead of just a |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
687 string. In that case the car must be a string specifying the |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
688 buffer name. This is for compatibility with |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
689 `special-display-buffer-names'; the cdr of the cons cell is |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
690 ignored. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
691 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
692 See also `same-window-regexps'." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
693 :type '(repeat (string :format "%v")) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
694 :group 'windows) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
695 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
696 (defcustom same-window-regexps nil |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
697 "List of regexps saying which buffers should appear in the \"same\" window. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
698 `display-buffer' and `pop-to-buffer' show a buffer whose name |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
699 matches a regexp on this list in the selected rather than some |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
700 other window. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
701 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
702 An element of this list can be a cons cell instead of just a |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
703 string. In that case the car must be a string, which specifies |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
704 the buffer name. This is for compatibility with |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
705 `special-display-buffer-names'; the cdr of the cons cell is |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
706 ignored. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
707 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
708 See also `same-window-buffer-names'." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
709 :type '(repeat (regexp :format "%v")) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
710 :group 'windows) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
711 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
712 (defcustom pop-up-frames nil |
98577
457b5cef3f44
(pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents:
98487
diff
changeset
|
713 "Whether `display-buffer' should make a separate frame. |
457b5cef3f44
(pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents:
98487
diff
changeset
|
714 If nil, never make a seperate frame. |
457b5cef3f44
(pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents:
98487
diff
changeset
|
715 If the value is `graphic-only', make a separate frame |
457b5cef3f44
(pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents:
98487
diff
changeset
|
716 on graphic displays only. |
457b5cef3f44
(pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents:
98487
diff
changeset
|
717 Any other non-nil value means always make a separate frame." |
457b5cef3f44
(pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents:
98487
diff
changeset
|
718 :type '(choice |
457b5cef3f44
(pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents:
98487
diff
changeset
|
719 (const :tag "Never" nil) |
457b5cef3f44
(pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents:
98487
diff
changeset
|
720 (const :tag "On graphic displays only" graphic-only) |
457b5cef3f44
(pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents:
98487
diff
changeset
|
721 (const :tag "Always" t)) |
98135
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
722 :group 'windows) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
723 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
724 (defcustom display-buffer-reuse-frames nil |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
725 "Non-nil means `display-buffer' should reuse frames. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
726 If the buffer in question is already displayed in a frame, raise |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
727 that frame." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
728 :type 'boolean |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
729 :version "21.1" |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
730 :group 'windows) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
731 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
732 (defcustom pop-up-windows t |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
733 "Non-nil means `display-buffer' should make a new window." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
734 :type 'boolean |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
735 :group 'windows) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
736 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
737 (defcustom split-height-threshold 80 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
738 "Minimum height of window to be split vertically. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
739 If the value is a number, `display-buffer' can split a window |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
740 only if it has at least as many lines. If the value is nil, |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
741 `display-buffer' cannot split a window vertically. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
742 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
743 If the window is the only window on its frame, `display-buffer' |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
744 can split it regardless of this value." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
745 :type '(choice (const nil) (number :tag "lines")) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
746 :version "23.1" |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
747 :group 'windows) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
748 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
749 (defcustom split-width-threshold 160 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
750 "Minimum width of window to be split horizontally. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
751 If the value is a number, `display-buffer' can split a window |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
752 only if it has at least as many columns. If the value is nil, |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
753 `display-buffer' cannot split a window horizontally." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
754 :type '(choice (const nil) (number :tag "columns")) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
755 :version "23.1" |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
756 :group 'windows) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
757 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
758 (defcustom split-window-preferred-function nil |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
759 "Function used by `display-buffer' to split windows. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
760 If non-nil, a function called with a window as single argument |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
761 supposed to split that window and return the new window. If the |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
762 function returns nil the window is not split. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
763 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
764 If nil, `display-buffer' will split the window respecting the |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
765 values of `split-height-threshold' and `split-width-threshold'." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
766 :type '(choice (const nil) (function :tag "Function")) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
767 :version "23.1" |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
768 :group 'windows) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
769 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
770 (defun window--splittable-p (window &optional horizontal) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
771 "Return non-nil if window WINDOW can be split evenly. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
772 Optional argument HORIZONTAL non-nil means check whether WINDOW |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
773 can be split horizontally. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
774 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
775 WINDOW can be split vertically when the following conditions |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
776 hold: |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
777 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
778 - `window-size-fixed' is either nil or equals `width' for the |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
779 buffer of WINDOW. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
780 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
781 - `split-height-threshold' is a number and WINDOW is at least as |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
782 high as `split-height-threshold'. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
783 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
784 - When WINDOW is split evenly, the emanating windows are at least |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
785 `window-min-height' lines tall and can accommodate at least one |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
786 line plus - if WINDOW has one - a modeline. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
787 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
788 WINDOW can be split horizontally when the following conditions |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
789 hold: |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
790 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
791 - `window-size-fixed' is either nil or equals `height' for the |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
792 buffer of WINDOW. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
793 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
794 - `split-width-threshold' is a number and WINDOW is at least as |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
795 wide as `split-width-threshold'. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
796 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
797 - When WINDOW is split evenly, the emanating windows are at least |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
798 `window-min-width' or two (whichever is larger) columns wide." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
799 (when (window-live-p window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
800 (with-current-buffer (window-buffer window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
801 (if horizontal |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
802 ;; A window can be split horizontally when its width is not |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
803 ;; fixed, it is at least `split-width-threshold' columns wide |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
804 ;; and at least twice as wide as `window-min-width' and 2 (the |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
805 ;; latter value is hardcoded). |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
806 (and (memq window-size-fixed '(nil height)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
807 ;; Testing `window-full-width-p' here hardly makes any |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
808 ;; sense nowadays. This can be done more intuitively by |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
809 ;; setting up `split-width-threshold' appropriately. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
810 (numberp split-width-threshold) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
811 (>= (window-width window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
812 (max split-width-threshold |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
813 (* 2 (max window-min-width 2))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
814 ;; A window can be split vertically when its height is not |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
815 ;; fixed, it is at least `split-height-threshold' lines high, |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
816 ;; and it is at least twice as high as `window-min-height' and 2 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
817 ;; if it has a modeline or 1. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
818 (and (memq window-size-fixed '(nil width)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
819 (numberp split-height-threshold) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
820 (>= (window-height window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
821 (max split-height-threshold |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
822 (* 2 (max window-min-height |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
823 (if mode-line-format 2 1)))))))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
824 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
825 (defun window--try-to-split-window (window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
826 "Split window WINDOW if it is splittable. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
827 See `window--splittable-p' for how to determine whether a window |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
828 is splittable. If WINDOW can be split, return the value returned |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
829 by `split-window' or `split-window-preferred-function'." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
830 (when (and (window-live-p window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
831 (not (frame-parameter (window-frame window) 'unsplittable))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
832 (if (functionp split-window-preferred-function) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
833 ;; `split-window-preferred-function' is specified, so use it. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
834 (funcall split-window-preferred-function window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
835 (or (and (window--splittable-p window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
836 ;; Split window vertically. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
837 (split-window window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
838 (and (window--splittable-p window t) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
839 ;; Split window horizontally. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
840 (split-window window nil t)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
841 (and (eq window (frame-root-window (window-frame window))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
842 (not (window-minibuffer-p window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
843 ;; If WINDOW is the only window on its frame and not the |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
844 ;; minibuffer window, attempt to split it vertically |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
845 ;; disregarding the value of `split-height-threshold'. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
846 (let ((split-height-threshold 0)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
847 (and (window--splittable-p window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
848 (split-window window)))))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
849 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
850 (defun window--frame-usable-p (frame) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
851 "Return frame FRAME if it can be used to display another buffer." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
852 (when (framep frame) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
853 (let ((window (frame-root-window frame))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
854 ;; `frame-root-window' may be an internal window which is considered |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
855 ;; "dead" by `window-live-p'. Hence if `window' is not live we |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
856 ;; implicitly know that `frame' has a visible window we can use. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
857 (when (or (not (window-live-p window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
858 (and (not (window-minibuffer-p window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
859 (not (window-dedicated-p window)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
860 frame)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
861 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
862 (defcustom even-window-heights t |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
863 "If non-nil `display-buffer' will try to even window heights. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
864 Otherwise `display-buffer' will leave the window configuration |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
865 alone. Heights are evened only when `display-buffer' chooses a |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
866 window that appears above or below the selected window." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
867 :type 'boolean |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
868 :group 'windows) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
869 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
870 (defun window--even-window-heights (window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
871 "Even heights of window WINDOW and selected window. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
872 Do this only if these windows are vertically adjacent to each |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
873 other, `even-window-heights' is non-nil, and the selected window |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
874 is higher than WINDOW." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
875 (when (and even-window-heights |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
876 (not (eq window (selected-window))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
877 ;; Don't resize minibuffer windows. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
878 (not (window-minibuffer-p (selected-window))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
879 (> (window-height (selected-window)) (window-height window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
880 (eq (window-frame window) (window-frame (selected-window))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
881 (let ((sel-edges (window-edges (selected-window))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
882 (win-edges (window-edges window))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
883 (and (= (nth 0 sel-edges) (nth 0 win-edges)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
884 (= (nth 2 sel-edges) (nth 2 win-edges)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
885 (or (= (nth 1 sel-edges) (nth 3 win-edges)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
886 (= (nth 3 sel-edges) (nth 1 win-edges)))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
887 (let ((window-min-height 1)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
888 ;; Don't throw an error if we can't even window heights for |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
889 ;; whatever reason. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
890 (condition-case nil |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
891 (enlarge-window (/ (- (window-height window) (window-height)) 2)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
892 (error nil))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
893 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
894 (defun window--display-buffer-1 (window) |
98487
93f3b87e5666
(window--display-buffer-1): Don't care about
Martin Rudalics <rudalics@gmx.at>
parents:
98165
diff
changeset
|
895 "Raise the frame containing the window WINDOW. |
93f3b87e5666
(window--display-buffer-1): Don't care about
Martin Rudalics <rudalics@gmx.at>
parents:
98165
diff
changeset
|
896 Do not raise the selected frame. Return WINDOW." |
98135
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
897 (let* ((frame (window-frame window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
898 (visible (frame-visible-p frame))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
899 (unless (or (not visible) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
900 ;; Assume the selected frame is already visible enough. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
901 (eq frame (selected-frame)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
902 ;; Assume the frame from which we invoked the minibuffer |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
903 ;; is visible. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
904 (and (minibuffer-window-active-p (selected-window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
905 (eq frame (window-frame (minibuffer-selected-window))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
906 (raise-frame frame)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
907 window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
908 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
909 (defun window--display-buffer-2 (buffer window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
910 "Display buffer BUFFER in window WINDOW and make its frame visible. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
911 Return WINDOW." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
912 (when (and (buffer-live-p buffer) (window-live-p window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
913 (set-window-buffer window buffer) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
914 (window--display-buffer-1 window))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
915 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
916 (defun display-buffer (buffer-or-name &optional not-this-window frame) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
917 "Make buffer BUFFER-OR-NAME appear in some window but don't select it. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
918 BUFFER-OR-NAME must be a buffer or the name of an existing |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
919 buffer. Return the window chosen to display BUFFER-OR-NAME or |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
920 nil if no such window is found. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
921 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
922 Optional argument NOT-THIS-WINDOW non-nil means display the |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
923 buffer in a window other than the selected one, even if it is |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
924 already displayed in the selected window. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
925 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
926 Optional argument FRAME specifies which frames to investigate |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
927 when the specified buffer is already displayed. If the buffer is |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
928 already displayed in some window on one of these frames simply |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
929 return that window. Possible values of FRAME are: |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
930 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
931 `visible' - consider windows on all visible frames. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
932 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
933 0 - consider windows on all visible or iconified frames. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
934 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
935 t - consider windows on all frames. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
936 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
937 A specific frame - consider windows on that frame only. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
938 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
939 nil - consider windows on the selected frame \(actually the |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
940 last non-minibuffer frame\) only. If, however, either |
98577
457b5cef3f44
(pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents:
98487
diff
changeset
|
941 `display-buffer-reuse-frames' or `pop-up-frames' is non-nil |
457b5cef3f44
(pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents:
98487
diff
changeset
|
942 \(non-nil and not graphic-only on a text-only terminal), |
98135
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
943 consider all visible or iconified frames." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
944 (interactive "BDisplay buffer:\nP") |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
945 (let* ((can-use-selected-window |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
946 ;; The selected window is usable unless either NOT-THIS-WINDOW |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
947 ;; is non-nil, it is dedicated to its buffer, or it is the |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
948 ;; `minibuffer-window'. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
949 (not (or not-this-window |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
950 (window-dedicated-p (selected-window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
951 (window-minibuffer-p)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
952 (buffer (if (bufferp buffer-or-name) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
953 buffer-or-name |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
954 (get-buffer buffer-or-name))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
955 (name-of-buffer (buffer-name buffer)) |
98577
457b5cef3f44
(pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents:
98487
diff
changeset
|
956 ;; On text-only terminals do not pop up a new frame when |
457b5cef3f44
(pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents:
98487
diff
changeset
|
957 ;; `pop-up-frames' equals graphic-only. |
457b5cef3f44
(pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents:
98487
diff
changeset
|
958 (use-pop-up-frames (if (eq pop-up-frames 'graphic-only) |
457b5cef3f44
(pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents:
98487
diff
changeset
|
959 (display-graphic-p) |
457b5cef3f44
(pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents:
98487
diff
changeset
|
960 pop-up-frames)) |
98135
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
961 ;; `frame-to-use' is the frame where to show `buffer' - either |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
962 ;; the selected frame or the last nonminibuffer frame. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
963 (frame-to-use |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
964 (or (window--frame-usable-p (selected-frame)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
965 (window--frame-usable-p (last-nonminibuffer-frame)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
966 ;; `window-to-use' is the window we use for showing `buffer'. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
967 window-to-use) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
968 (cond |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
969 ((not (buffer-live-p buffer)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
970 (error "No such buffer %s" buffer)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
971 (display-buffer-function |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
972 ;; Let `display-buffer-function' do the job. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
973 (funcall display-buffer-function buffer not-this-window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
974 ((and (not not-this-window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
975 (eq (window-buffer (selected-window)) buffer)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
976 ;; The selected window already displays BUFFER and |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
977 ;; `not-this-window' is nil, so use it. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
978 (window--display-buffer-1 (selected-window))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
979 ((and can-use-selected-window (same-window-p name-of-buffer)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
980 ;; If the buffer's name tells us to use the selected window do so. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
981 (window--display-buffer-2 buffer (selected-window))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
982 ((let ((frames (or frame |
98577
457b5cef3f44
(pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents:
98487
diff
changeset
|
983 (and (or use-pop-up-frames |
457b5cef3f44
(pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents:
98487
diff
changeset
|
984 display-buffer-reuse-frames |
98135
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
985 (not (last-nonminibuffer-frame))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
986 0) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
987 (last-nonminibuffer-frame)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
988 (and (setq window-to-use (get-buffer-window buffer frames)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
989 (or can-use-selected-window |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
990 (not (eq (selected-window) window-to-use))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
991 ;; If the buffer is already displayed in some window use that. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
992 (window--display-buffer-1 window-to-use)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
993 ((and special-display-function |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
994 ;; `special-display-p' returns either t or a list of frame |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
995 ;; parameters to pass to `special-display-function'. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
996 (let ((pars (special-display-p name-of-buffer))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
997 (when pars |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
998 (funcall special-display-function |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
999 buffer (if (listp pars) pars)))))) |
98577
457b5cef3f44
(pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents:
98487
diff
changeset
|
1000 ((or use-pop-up-frames (not frame-to-use)) |
98135
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1001 ;; We want or need a new frame. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1002 (window--display-buffer-2 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1003 buffer (frame-selected-window (funcall pop-up-frame-function)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1004 ((and pop-up-windows |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1005 ;; Make a new window. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1006 (or (not (frame-parameter frame-to-use 'unsplittable)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1007 ;; If the selected frame cannot be split look at |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1008 ;; `last-nonminibuffer-frame'. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1009 (and (eq frame-to-use (selected-frame)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1010 (setq frame-to-use (last-nonminibuffer-frame)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1011 (window--frame-usable-p frame-to-use) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1012 (not (frame-parameter frame-to-use 'unsplittable)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1013 ;; Attempt to split largest or least recently used window. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1014 (setq window-to-use |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1015 (or (window--try-to-split-window |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1016 (get-largest-window frame-to-use t)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1017 (window--try-to-split-window |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1018 (get-lru-window frame-to-use t)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1019 (window--display-buffer-2 buffer window-to-use))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1020 ((setq window-to-use |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1021 ;; Reuse an existing window. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1022 (or (get-lru-window frame-to-use) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1023 (get-buffer-window buffer 'visible) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1024 (get-largest-window 'visible nil) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1025 (get-buffer-window buffer 0) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1026 (get-largest-window 0 nil) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1027 (frame-selected-window (funcall pop-up-frame-function)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1028 (window--even-window-heights window-to-use) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1029 (window--display-buffer-2 buffer window-to-use))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1030 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1031 (defun pop-to-buffer (buffer-or-name &optional other-window norecord) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1032 "Select buffer BUFFER-OR-NAME in some window, preferably a different one. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1033 BUFFER-OR-NAME may be a buffer, a string \(a buffer name), or |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1034 nil. If BUFFER-OR-NAME is a string not naming an existent |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1035 buffer, create a buffer with that name. If BUFFER-OR-NAME is |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1036 nil, choose some other buffer. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1037 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1038 If `pop-up-windows' is non-nil, windows can be split to display |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1039 the buffer. If optional second arg OTHER-WINDOW is non-nil, |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1040 insist on finding another window even if the specified buffer is |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1041 already visible in the selected window, and ignore |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1042 `same-window-regexps' and `same-window-buffer-names'. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1043 |
98141
2184b626a9cc
(pop-to-buffer): If the window for buffer-or-name is
Martin Rudalics <rudalics@gmx.at>
parents:
98135
diff
changeset
|
1044 If the window to show BUFFER-OR-NAME is not on the selected |
2184b626a9cc
(pop-to-buffer): If the window for buffer-or-name is
Martin Rudalics <rudalics@gmx.at>
parents:
98135
diff
changeset
|
1045 frame, raise that window's frame and give it input focus. |
2184b626a9cc
(pop-to-buffer): If the window for buffer-or-name is
Martin Rudalics <rudalics@gmx.at>
parents:
98135
diff
changeset
|
1046 |
98135
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1047 This function returns the buffer it switched to. This uses the |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1048 function `display-buffer' as a subroutine; see the documentation |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1049 of `display-buffer' for additional customization information. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1050 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1051 Optional third arg NORECORD non-nil means do not put this buffer |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1052 at the front of the list of recently selected ones." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1053 (let ((buffer |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1054 ;; FIXME: This behavior is carried over from the previous C version |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1055 ;; of pop-to-buffer, but really we should use just |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1056 ;; `get-buffer' here. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1057 (if (null buffer-or-name) (other-buffer (current-buffer)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1058 (or (get-buffer buffer-or-name) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1059 (let ((buf (get-buffer-create buffer-or-name))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1060 (set-buffer-major-mode buf) |
98141
2184b626a9cc
(pop-to-buffer): If the window for buffer-or-name is
Martin Rudalics <rudalics@gmx.at>
parents:
98135
diff
changeset
|
1061 buf)))) |
2184b626a9cc
(pop-to-buffer): If the window for buffer-or-name is
Martin Rudalics <rudalics@gmx.at>
parents:
98135
diff
changeset
|
1062 (old-window (selected-window)) |
2184b626a9cc
(pop-to-buffer): If the window for buffer-or-name is
Martin Rudalics <rudalics@gmx.at>
parents:
98135
diff
changeset
|
1063 (old-frame (selected-frame)) |
2184b626a9cc
(pop-to-buffer): If the window for buffer-or-name is
Martin Rudalics <rudalics@gmx.at>
parents:
98135
diff
changeset
|
1064 new-window new-frame) |
98135
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1065 (set-buffer buffer) |
98607
234a18b5c81e
(pop-to-buffer): Fix misplacement of arg norecord in
Martin Rudalics <rudalics@gmx.at>
parents:
98577
diff
changeset
|
1066 (setq new-window (display-buffer buffer other-window)) |
98141
2184b626a9cc
(pop-to-buffer): If the window for buffer-or-name is
Martin Rudalics <rudalics@gmx.at>
parents:
98135
diff
changeset
|
1067 (unless (eq new-window old-window) |
98165
8b39b6502384
(pop-to-buffer): Select window before calling
Martin Rudalics <rudalics@gmx.at>
parents:
98141
diff
changeset
|
1068 ;; `display-buffer' has chosen another window, select it. |
98607
234a18b5c81e
(pop-to-buffer): Fix misplacement of arg norecord in
Martin Rudalics <rudalics@gmx.at>
parents:
98577
diff
changeset
|
1069 (select-window new-window norecord) |
98141
2184b626a9cc
(pop-to-buffer): If the window for buffer-or-name is
Martin Rudalics <rudalics@gmx.at>
parents:
98135
diff
changeset
|
1070 (setq new-frame (window-frame new-window)) |
2184b626a9cc
(pop-to-buffer): If the window for buffer-or-name is
Martin Rudalics <rudalics@gmx.at>
parents:
98135
diff
changeset
|
1071 (unless (eq new-frame old-frame) |
2184b626a9cc
(pop-to-buffer): If the window for buffer-or-name is
Martin Rudalics <rudalics@gmx.at>
parents:
98135
diff
changeset
|
1072 ;; `display-buffer' has chosen another frame, make sure it gets |
2184b626a9cc
(pop-to-buffer): If the window for buffer-or-name is
Martin Rudalics <rudalics@gmx.at>
parents:
98135
diff
changeset
|
1073 ;; input focus and is risen. |
98165
8b39b6502384
(pop-to-buffer): Select window before calling
Martin Rudalics <rudalics@gmx.at>
parents:
98141
diff
changeset
|
1074 (select-frame-set-input-focus new-frame))) |
98135
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1075 buffer)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1076 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1077 ;; I think this should be the default; I think people will prefer it--rms. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1078 (defcustom split-window-keep-point t |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1079 "If non-nil, \\[split-window-vertically] keeps the original point \ |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1080 in both children. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1081 This is often more convenient for editing. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1082 If nil, adjust point in each of the two windows to minimize redisplay. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1083 This is convenient on slow terminals, but point can move strangely. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1084 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1085 This option applies only to `split-window-vertically' and |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1086 functions that call it. `split-window' always keeps the original |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1087 point in both children." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1088 :type 'boolean |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1089 :group 'windows) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1090 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1091 (defun split-window-vertically (&optional arg) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1092 "Split current window into two windows, one above the other. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1093 The uppermost window gets ARG lines and the other gets the rest. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1094 Negative ARG means select the size of the lowermost window instead. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1095 With no argument, split equally or close to it. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1096 Both windows display the same buffer now current. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1097 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1098 If the variable `split-window-keep-point' is non-nil, both new windows |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1099 will get the same value of point as the current window. This is often |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1100 more convenient for editing. The upper window is the selected window. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1101 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1102 Otherwise, we choose window starts so as to minimize the amount of |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1103 redisplay; this is convenient on slow terminals. The new selected |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1104 window is the one that the current value of point appears in. The |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1105 value of point can change if the text around point is hidden by the |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1106 new mode line. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1107 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1108 Regardless of the value of `split-window-keep-point', the upper |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1109 window is the original one and the return value is the new, lower |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1110 window." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1111 (interactive "P") |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1112 (let ((old-w (selected-window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1113 (old-point (point)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1114 (size (and arg (prefix-numeric-value arg))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1115 (window-full-p nil) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1116 new-w bottom moved) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1117 (and size (< size 0) (setq size (+ (window-height) size))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1118 (setq new-w (split-window nil size)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1119 (or split-window-keep-point |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1120 (progn |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1121 (save-excursion |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1122 (set-buffer (window-buffer)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1123 (goto-char (window-start)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1124 (setq moved (vertical-motion (window-height))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1125 (set-window-start new-w (point)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1126 (if (> (point) (window-point new-w)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1127 (set-window-point new-w (point))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1128 (and (= moved (window-height)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1129 (progn |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1130 (setq window-full-p t) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1131 (vertical-motion -1))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1132 (setq bottom (point))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1133 (and window-full-p |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1134 (<= bottom (point)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1135 (set-window-point old-w (1- bottom))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1136 (and window-full-p |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1137 (<= (window-start new-w) old-point) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1138 (progn |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1139 (set-window-point new-w old-point) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1140 (select-window new-w))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1141 (split-window-save-restore-data new-w old-w))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1142 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1143 ;; This is to avoid compiler warnings. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1144 (defvar view-return-to-alist) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1145 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1146 (defun split-window-save-restore-data (new-w old-w) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1147 (with-current-buffer (window-buffer) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1148 (if view-mode |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1149 (let ((old-info (assq old-w view-return-to-alist))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1150 (if old-info |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1151 (push (cons new-w (cons (car (cdr old-info)) t)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1152 view-return-to-alist)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1153 new-w)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1154 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1155 (defun split-window-horizontally (&optional arg) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1156 "Split current window into two windows side by side. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1157 This window becomes the leftmost of the two, and gets ARG columns. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1158 Negative ARG means select the size of the rightmost window instead. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1159 The argument includes the width of the window's scroll bar; if there |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1160 are no scroll bars, it includes the width of the divider column |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1161 to the window's right, if any. No ARG means split equally. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1162 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1163 The original, leftmost window remains selected. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1164 The return value is the new, rightmost window." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1165 (interactive "P") |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1166 (let ((old-w (selected-window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1167 (size (and arg (prefix-numeric-value arg)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1168 (and size (< size 0) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1169 (setq size (+ (window-width) size))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1170 (split-window-save-restore-data (split-window nil size t) old-w))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1171 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1172 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1173 (defun set-window-text-height (window height) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1174 "Sets the height in lines of the text display area of WINDOW to HEIGHT. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1175 This doesn't include the mode-line (or header-line if any) or any |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1176 partial-height lines in the text display area. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1177 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1178 If WINDOW is nil, the selected window is used. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1179 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1180 Note that the current implementation of this function cannot always set |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1181 the height exactly, but attempts to be conservative, by allocating more |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1182 lines than are actually needed in the case where some error may be present." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1183 (let ((delta (- height (window-text-height window)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1184 (unless (zerop delta) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1185 ;; Setting window-min-height to a value like 1 can lead to very |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1186 ;; bizarre displays because it also allows Emacs to make *other* |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1187 ;; windows 1-line tall, which means that there's no more space for |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1188 ;; the modeline. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1189 (let ((window-min-height (min 2 height))) ;One text line plus a modeline. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1190 (if (and window (not (eq window (selected-window)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1191 (save-selected-window |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1192 (select-window window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1193 (enlarge-window delta)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1194 (enlarge-window delta)))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1195 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1196 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1197 (defun enlarge-window-horizontally (arg) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1198 "Make current window ARG columns wider." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1199 (interactive "p") |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1200 (enlarge-window arg t)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1201 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1202 (defun shrink-window-horizontally (arg) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1203 "Make current window ARG columns narrower." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1204 (interactive "p") |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1205 (shrink-window arg t)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1206 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1207 (defun window-buffer-height (window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1208 "Return the height (in screen lines) of the buffer that WINDOW is displaying." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1209 (with-current-buffer (window-buffer window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1210 (max 1 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1211 (count-screen-lines (point-min) (point-max) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1212 ;; If buffer ends with a newline, ignore it when |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1213 ;; counting height unless point is after it. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1214 (eobp) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1215 window)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1216 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1217 (defun count-screen-lines (&optional beg end count-final-newline window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1218 "Return the number of screen lines in the region. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1219 The number of screen lines may be different from the number of actual lines, |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1220 due to line breaking, display table, etc. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1221 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1222 Optional arguments BEG and END default to `point-min' and `point-max' |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1223 respectively. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1224 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1225 If region ends with a newline, ignore it unless optional third argument |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1226 COUNT-FINAL-NEWLINE is non-nil. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1227 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1228 The optional fourth argument WINDOW specifies the window used for obtaining |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1229 parameters such as width, horizontal scrolling, and so on. The default is |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1230 to use the selected window's parameters. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1231 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1232 Like `vertical-motion', `count-screen-lines' always uses the current buffer, |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1233 regardless of which buffer is displayed in WINDOW. This makes possible to use |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1234 `count-screen-lines' in any buffer, whether or not it is currently displayed |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1235 in some window." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1236 (unless beg |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1237 (setq beg (point-min))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1238 (unless end |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1239 (setq end (point-max))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1240 (if (= beg end) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1241 0 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1242 (save-excursion |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1243 (save-restriction |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1244 (widen) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1245 (narrow-to-region (min beg end) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1246 (if (and (not count-final-newline) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1247 (= ?\n (char-before (max beg end)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1248 (1- (max beg end)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1249 (max beg end))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1250 (goto-char (point-min)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1251 (1+ (vertical-motion (buffer-size) window)))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1252 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1253 (defun fit-window-to-buffer (&optional window max-height min-height) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1254 "Make WINDOW the right height to display its contents exactly. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1255 If WINDOW is omitted or nil, it defaults to the selected window. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1256 If the optional argument MAX-HEIGHT is supplied, it is the maximum height |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1257 the window is allowed to be, defaulting to the frame height. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1258 If the optional argument MIN-HEIGHT is supplied, it is the minimum |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1259 height the window is allowed to be, defaulting to `window-min-height'. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1260 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1261 The heights in MAX-HEIGHT and MIN-HEIGHT include the mode-line and/or |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1262 header-line." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1263 (interactive) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1264 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1265 (when (null window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1266 (setq window (selected-window))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1267 (when (null max-height) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1268 (setq max-height (frame-height (window-frame window)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1269 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1270 (let* ((buf |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1271 ;; Buffer that is displayed in WINDOW |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1272 (window-buffer window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1273 (window-height |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1274 ;; The current height of WINDOW |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1275 (window-height window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1276 (desired-height |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1277 ;; The height necessary to show the buffer displayed by WINDOW |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1278 ;; (`count-screen-lines' always works on the current buffer). |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1279 (with-current-buffer buf |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1280 (+ (count-screen-lines) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1281 ;; If the buffer is empty, (count-screen-lines) is |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1282 ;; zero. But, even in that case, we need one text line |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1283 ;; for cursor. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1284 (if (= (point-min) (point-max)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1285 1 0) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1286 ;; For non-minibuffers, count the mode-line, if any |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1287 (if (and (not (window-minibuffer-p window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1288 mode-line-format) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1289 1 0) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1290 ;; Count the header-line, if any |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1291 (if header-line-format 1 0)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1292 (delta |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1293 ;; Calculate how much the window height has to change to show |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1294 ;; desired-height lines, constrained by MIN-HEIGHT and MAX-HEIGHT. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1295 (- (max (min desired-height max-height) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1296 (or min-height window-min-height)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1297 window-height))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1298 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1299 ;; Don't try to redisplay with the cursor at the end |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1300 ;; on its own line--that would force a scroll and spoil things. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1301 (when (with-current-buffer buf |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1302 (and (eobp) (bolp) (not (bobp)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1303 (set-window-point window (1- (window-point window)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1304 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1305 (save-selected-window |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1306 (select-window window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1307 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1308 ;; Adjust WINDOW to the nominally correct size (which may actually |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1309 ;; be slightly off because of variable height text, etc). |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1310 (unless (zerop delta) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1311 (enlarge-window delta)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1312 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1313 ;; Check if the last line is surely fully visible. If not, |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1314 ;; enlarge the window. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1315 (let ((end (with-current-buffer buf |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1316 (save-excursion |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1317 (goto-char (point-max)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1318 (when (and (bolp) (not (bobp))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1319 ;; Don't include final newline |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1320 (backward-char 1)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1321 (when truncate-lines |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1322 ;; If line-wrapping is turned off, test the |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1323 ;; beginning of the last line for visibility |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1324 ;; instead of the end, as the end of the line |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1325 ;; could be invisible by virtue of extending past |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1326 ;; the edge of the window. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1327 (forward-line 0)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1328 (point))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1329 (set-window-vscroll window 0) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1330 (while (and (< desired-height max-height) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1331 (= desired-height (window-height window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1332 (not (pos-visible-in-window-p end window))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1333 (enlarge-window 1) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1334 (setq desired-height (1+ desired-height))))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1335 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1336 (defun shrink-window-if-larger-than-buffer (&optional window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1337 "Shrink the WINDOW to be as small as possible to display its contents. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1338 If WINDOW is omitted or nil, it defaults to the selected window. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1339 Do not shrink to less than `window-min-height' lines. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1340 Do nothing if the buffer contains more lines than the present window height, |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1341 or if some of the window's contents are scrolled out of view, |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1342 or if shrinking this window would also shrink another window, |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1343 or if the window is the only window of its frame." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1344 (interactive) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1345 (when (null window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1346 (setq window (selected-window))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1347 (let* ((frame (window-frame window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1348 (mini (frame-parameter frame 'minibuffer)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1349 (edges (window-edges window))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1350 (if (and (not (eq window (frame-root-window frame))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1351 (window-safely-shrinkable-p) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1352 (pos-visible-in-window-p (point-min) window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1353 (not (eq mini 'only)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1354 (or (not mini) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1355 (let ((mini-window (minibuffer-window frame))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1356 (or (null mini-window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1357 (not (eq frame (window-frame mini-window))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1358 (< (nth 3 edges) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1359 (nth 1 (window-edges mini-window))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1360 (> (nth 1 edges) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1361 (frame-parameter frame 'menu-bar-lines)))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1362 (fit-window-to-buffer window (window-height window))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1363 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1364 (defun kill-buffer-and-window () |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1365 "Kill the current buffer and delete the selected window." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1366 (interactive) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1367 (let ((window-to-delete (selected-window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1368 (buffer-to-kill (current-buffer)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1369 (delete-window-hook (lambda () |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1370 (condition-case nil |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1371 (delete-window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1372 (error nil))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1373 (unwind-protect |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1374 (progn |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1375 (add-hook 'kill-buffer-hook delete-window-hook t t) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1376 (if (kill-buffer (current-buffer)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1377 ;; If `delete-window' failed before, we rerun it to regenerate |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1378 ;; the error so it can be seen in the echo area. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1379 (when (eq (selected-window) window-to-delete) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1380 (delete-window)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1381 ;; If the buffer is not dead for some reason (probably because |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1382 ;; of a `quit' signal), remove the hook again. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1383 (condition-case nil |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1384 (with-current-buffer buffer-to-kill |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1385 (remove-hook 'kill-buffer-hook delete-window-hook t)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1386 (error nil))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1387 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1388 (defun quit-window (&optional kill window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1389 "Quit the current buffer. Bury it, and maybe delete the selected frame. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1390 \(The frame is deleted if it contains a dedicated window for the buffer.) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1391 With a prefix argument, kill the buffer instead. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1392 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1393 Noninteractively, if KILL is non-nil, then kill the current buffer, |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1394 otherwise bury it. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1395 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1396 If WINDOW is non-nil, it specifies a window; we delete that window, |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1397 and the buffer that is killed or buried is the one in that window." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1398 (interactive "P") |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1399 (let ((buffer (window-buffer window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1400 (frame (window-frame (or window (selected-window)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1401 (window-solitary |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1402 (save-selected-window |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1403 (if window |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1404 (select-window window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1405 (one-window-p t))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1406 window-handled) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1407 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1408 (save-selected-window |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1409 (if window |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1410 (select-window window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1411 (or (window-minibuffer-p) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1412 (window-dedicated-p (selected-window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1413 (switch-to-buffer (other-buffer)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1414 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1415 ;; Get rid of the frame, if it has just one dedicated window |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1416 ;; and other visible frames exist. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1417 (and (or (window-minibuffer-p) (window-dedicated-p window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1418 (delq frame (visible-frame-list)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1419 window-solitary |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1420 (if (and (eq default-minibuffer-frame frame) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1421 (= 1 (length (minibuffer-frame-list)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1422 (setq window nil) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1423 (delete-frame frame) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1424 (setq window-handled t))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1425 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1426 ;; Deal with the buffer. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1427 (if kill |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1428 (kill-buffer buffer) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1429 (bury-buffer buffer)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1430 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1431 ;; Maybe get rid of the window. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1432 (and window (not window-handled) (not window-solitary) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1433 (delete-window window)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1434 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1435 (defvar recenter-last-op nil |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1436 "Indicates the last recenter operation performed. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1437 Possible values: `top', `middle', `bottom'.") |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1438 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1439 (defun recenter-top-bottom (&optional arg) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1440 "Move current line to window center, top, and bottom, successively. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1441 With no prefix argument, the first call redraws the frame and |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1442 centers point vertically within the window. Successive calls |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1443 scroll the window, placing point on the top, bottom, and middle |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1444 consecutively. The cycling order is middle -> top -> bottom. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1445 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1446 A prefix argument is handled like `recenter': |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1447 With numeric prefix ARG, move current line to window-line ARG. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1448 With plain `C-u', move current line to window center. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1449 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1450 Top and bottom destinations are actually `scroll-margin' lines |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1451 the from true window top and bottom." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1452 (interactive "P") |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1453 (cond |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1454 (arg (recenter arg)) ; Always respect ARG. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1455 ((or (not (eq this-command last-command)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1456 (eq recenter-last-op 'bottom)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1457 (setq recenter-last-op 'middle) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1458 (recenter)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1459 (t |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1460 (let ((this-scroll-margin |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1461 (min (max 0 scroll-margin) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1462 (truncate (/ (window-body-height) 4.0))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1463 (cond ((eq recenter-last-op 'middle) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1464 (setq recenter-last-op 'top) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1465 (recenter this-scroll-margin)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1466 ((eq recenter-last-op 'top) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1467 (setq recenter-last-op 'bottom) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1468 (recenter (- -1 this-scroll-margin)))))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1469 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1470 (define-key global-map [?\C-l] 'recenter-top-bottom) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1471 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1472 (defvar mouse-autoselect-window-timer nil |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1473 "Timer used by delayed window autoselection.") |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1474 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1475 (defvar mouse-autoselect-window-position nil |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1476 "Last mouse position recorded by delayed window autoselection.") |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1477 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1478 (defvar mouse-autoselect-window-window nil |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1479 "Last window recorded by delayed window autoselection.") |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1480 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1481 (defvar mouse-autoselect-window-state nil |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1482 "When non-nil, special state of delayed window autoselection. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1483 Possible values are `suspend' \(suspend autoselection after a menu or |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1484 scrollbar interaction\) and `select' \(the next invocation of |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1485 'handle-select-window' shall select the window immediately\).") |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1486 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1487 (defun mouse-autoselect-window-cancel (&optional force) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1488 "Cancel delayed window autoselection. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1489 Optional argument FORCE means cancel unconditionally." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1490 (unless (and (not force) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1491 ;; Don't cancel for select-window or select-frame events |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1492 ;; or when the user drags a scroll bar. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1493 (or (memq this-command |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1494 '(handle-select-window handle-switch-frame)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1495 (and (eq this-command 'scroll-bar-toolkit-scroll) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1496 (memq (nth 4 (event-end last-input-event)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1497 '(handle end-scroll))))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1498 (setq mouse-autoselect-window-state nil) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1499 (when (timerp mouse-autoselect-window-timer) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1500 (cancel-timer mouse-autoselect-window-timer)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1501 (remove-hook 'pre-command-hook 'mouse-autoselect-window-cancel))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1502 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1503 (defun mouse-autoselect-window-start (mouse-position &optional window suspend) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1504 "Start delayed window autoselection. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1505 MOUSE-POSITION is the last position where the mouse was seen as returned |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1506 by `mouse-position'. Optional argument WINDOW non-nil denotes the |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1507 window where the mouse was seen. Optional argument SUSPEND non-nil |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1508 means suspend autoselection." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1509 ;; Record values for MOUSE-POSITION, WINDOW, and SUSPEND. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1510 (setq mouse-autoselect-window-position mouse-position) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1511 (when window (setq mouse-autoselect-window-window window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1512 (setq mouse-autoselect-window-state (when suspend 'suspend)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1513 ;; Install timer which runs `mouse-autoselect-window-select' after |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1514 ;; `mouse-autoselect-window' seconds. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1515 (setq mouse-autoselect-window-timer |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1516 (run-at-time |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1517 (abs mouse-autoselect-window) nil 'mouse-autoselect-window-select))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1518 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1519 (defun mouse-autoselect-window-select () |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1520 "Select window with delayed window autoselection. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1521 If the mouse position has stabilized in a non-selected window, select |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1522 that window. The minibuffer window is selected only if the minibuffer is |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1523 active. This function is run by `mouse-autoselect-window-timer'." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1524 (condition-case nil |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1525 (let* ((mouse-position (mouse-position)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1526 (window |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1527 (condition-case nil |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1528 (window-at (cadr mouse-position) (cddr mouse-position) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1529 (car mouse-position)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1530 (error nil)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1531 (cond |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1532 ((or (menu-or-popup-active-p) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1533 (and window |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1534 (not (coordinates-in-window-p (cdr mouse-position) window)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1535 ;; A menu / popup dialog is active or the mouse is on the scroll-bar |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1536 ;; of WINDOW, temporarily suspend delayed autoselection. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1537 (mouse-autoselect-window-start mouse-position nil t)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1538 ((eq mouse-autoselect-window-state 'suspend) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1539 ;; Delayed autoselection was temporarily suspended, reenable it. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1540 (mouse-autoselect-window-start mouse-position)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1541 ((and window (not (eq window (selected-window))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1542 (or (not (numberp mouse-autoselect-window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1543 (and (> mouse-autoselect-window 0) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1544 ;; If `mouse-autoselect-window' is positive, select |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1545 ;; window if the window is the same as before. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1546 (eq window mouse-autoselect-window-window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1547 ;; Otherwise select window if the mouse is at the same |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1548 ;; position as before. Observe that the first test after |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1549 ;; starting autoselection usually fails since the value of |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1550 ;; `mouse-autoselect-window-position' recorded there is the |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1551 ;; position where the mouse has entered the new window and |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1552 ;; not necessarily where the mouse has stopped moving. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1553 (equal mouse-position mouse-autoselect-window-position)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1554 ;; The minibuffer is a candidate window if it's active. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1555 (or (not (window-minibuffer-p window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1556 (eq window (active-minibuffer-window)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1557 ;; Mouse position has stabilized in non-selected window: Cancel |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1558 ;; delayed autoselection and try to select that window. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1559 (mouse-autoselect-window-cancel t) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1560 ;; Select window where mouse appears unless the selected window is the |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1561 ;; minibuffer. Use `unread-command-events' in order to execute pre- |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1562 ;; and post-command hooks and trigger idle timers. To avoid delaying |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1563 ;; autoselection again, set `mouse-autoselect-window-state'." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1564 (unless (window-minibuffer-p (selected-window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1565 (setq mouse-autoselect-window-state 'select) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1566 (setq unread-command-events |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1567 (cons (list 'select-window (list window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1568 unread-command-events)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1569 ((or (and window (eq window (selected-window))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1570 (not (numberp mouse-autoselect-window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1571 (equal mouse-position mouse-autoselect-window-position)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1572 ;; Mouse position has either stabilized in the selected window or at |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1573 ;; `mouse-autoselect-window-position': Cancel delayed autoselection. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1574 (mouse-autoselect-window-cancel t)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1575 (t |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1576 ;; Mouse position has not stabilized yet, resume delayed |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1577 ;; autoselection. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1578 (mouse-autoselect-window-start mouse-position window)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1579 (error nil))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1580 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1581 (defun handle-select-window (event) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1582 "Handle select-window events." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1583 (interactive "e") |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1584 (let ((window (posn-window (event-start event)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1585 (unless (or (not (window-live-p window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1586 ;; Don't switch if we're currently in the minibuffer. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1587 ;; This tries to work around problems where the |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1588 ;; minibuffer gets unselected unexpectedly, and where |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1589 ;; you then have to move your mouse all the way down to |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1590 ;; the minibuffer to select it. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1591 (window-minibuffer-p (selected-window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1592 ;; Don't switch to minibuffer window unless it's active. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1593 (and (window-minibuffer-p window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1594 (not (minibuffer-window-active-p window))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1595 ;; Don't switch when autoselection shall be delayed. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1596 (and (numberp mouse-autoselect-window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1597 (not (zerop mouse-autoselect-window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1598 (not (eq mouse-autoselect-window-state 'select)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1599 (progn |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1600 ;; Cancel any delayed autoselection. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1601 (mouse-autoselect-window-cancel t) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1602 ;; Start delayed autoselection from current mouse |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1603 ;; position and window. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1604 (mouse-autoselect-window-start (mouse-position) window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1605 ;; Executing a command cancels delayed autoselection. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1606 (add-hook |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1607 'pre-command-hook 'mouse-autoselect-window-cancel)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1608 (when mouse-autoselect-window |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1609 ;; Reset state of delayed autoselection. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1610 (setq mouse-autoselect-window-state nil) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1611 ;; Run `mouse-leave-buffer-hook' when autoselecting window. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1612 (run-hooks 'mouse-leave-buffer-hook)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1613 (select-window window)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1614 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1615 (defun delete-other-windows-vertically (&optional window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1616 "Delete the windows in the same column with WINDOW, but not WINDOW itself. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1617 This may be a useful alternative binding for \\[delete-other-windows] |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1618 if you often split windows horizontally." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1619 (interactive) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1620 (let* ((window (or window (selected-window))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1621 (edges (window-edges window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1622 (w window) delenda) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1623 (while (not (eq (setq w (next-window w 1)) window)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1624 (let ((e (window-edges w))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1625 (when (and (= (car e) (car edges)) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1626 (= (caddr e) (caddr edges))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1627 (push w delenda)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1628 (mapc 'delete-window delenda))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1629 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1630 (defun truncated-partial-width-window-p (&optional window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1631 "Non-nil if lines in WINDOW are specifically truncated due to its width. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1632 This returns nil if WINDOW is not a partial-width window |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1633 (regardless of the value of `truncate-lines'). |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1634 Otherwise, consult the value of `truncate-partial-width-windows' |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1635 for the buffer shown in WINDOW. |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1636 If WINDOW is nil, use the selected window." |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1637 (unless window |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1638 (setq window (selected-window))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1639 (unless (window-full-width-p window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1640 (let ((t-p-w-w (buffer-local-value 'truncate-partial-width-windows |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1641 (window-buffer window)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1642 (if (integerp t-p-w-w) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1643 (< (window-width window) t-p-w-w) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1644 t-p-w-w)))) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1645 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1646 (define-key ctl-x-map "2" 'split-window-vertically) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1647 (define-key ctl-x-map "3" 'split-window-horizontally) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1648 (define-key ctl-x-map "}" 'enlarge-window-horizontally) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1649 (define-key ctl-x-map "{" 'shrink-window-horizontally) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1650 (define-key ctl-x-map "-" 'shrink-window-if-larger-than-buffer) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1651 (define-key ctl-x-map "+" 'balance-windows) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1652 (define-key ctl-x-4-map "0" 'kill-buffer-and-window) |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1653 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1654 ;; arch-tag: b508dfcc-c353-4c37-89fa-e773fe10cea9 |
d4db403fda8d
Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents:
98126
diff
changeset
|
1655 ;;; window.el ends here |