aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2000-11-21 21:44:25 +0000
committerStefan Monnier2000-11-21 21:44:25 +0000
commitfe7a0e7dfda8647fda72facc6c9e582629d368e8 (patch)
treefb16aaee3d6569417205eba7d08e3e347d7a0075
parentc344cf32d5529c14a5bb15095bfbeb7680abe306 (diff)
downloademacs-fe7a0e7dfda8647fda72facc6c9e582629d368e8.tar.gz
emacs-fe7a0e7dfda8647fda72facc6c9e582629d368e8.zip
General comment and spacing fixes.
(save-selected-window): Use backquotes. (window-safely-shrinkable-p): New function. (shrink-window-if-larger-than-buffer): Use it.
-rw-r--r--lisp/window.el51
1 files changed, 32 insertions, 19 deletions
diff --git a/lisp/window.el b/lisp/window.el
index 8d646ca3113..86cb45f92e5 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -22,18 +22,21 @@
22;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 22;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23;; Boston, MA 02111-1307, USA. 23;; Boston, MA 02111-1307, USA.
24 24
25;;; Code:
26 25
27;;;; Window tree functions. 26;;; Commentary:
27
28;; Window tree functions.
29
30;;; Code:
28 31
29(defun one-window-p (&optional nomini all-frames) 32(defun one-window-p (&optional nomini all-frames)
30 "Returns non-nil if the selected window is the only window (in its frame). 33 "Return non-nil if the selected window is the only window (in its frame).
31Optional arg NOMINI non-nil means don't count the minibuffer 34Optional arg NOMINI non-nil means don't count the minibuffer
32even if it is active. 35even if it is active.
33 36
34The optional arg ALL-FRAMES t means count windows on all frames. 37The optional arg ALL-FRAMES t means count windows on all frames.
35If it is `visible', count windows on all visible frames. 38If it is `visible', count windows on all visible frames.
36ALL-FRAMES nil or omitted means count only the selected frame, 39ALL-FRAMES nil or omitted means count only the selected frame,
37plus the minibuffer it uses (which may be on another frame). 40plus the minibuffer it uses (which may be on another frame).
38If ALL-FRAMES is neither nil nor t, count only the selected frame." 41If ALL-FRAMES is neither nil nor t, count only the selected frame."
39 (let ((base-window (selected-window))) 42 (let ((base-window (selected-window)))
@@ -110,7 +113,7 @@ ALL-FRAMES = t means include windows on all frames including invisible frames.
110If ALL-FRAMES is a frame, it means include windows on that frame. 113If ALL-FRAMES is a frame, it means include windows on that frame.
111Anything else means restrict to the selected frame." 114Anything else means restrict to the selected frame."
112 (catch 'found 115 (catch 'found
113 (walk-windows #'(lambda (window) 116 (walk-windows #'(lambda (window)
114 (when (funcall predicate window) 117 (when (funcall predicate window)
115 (throw 'found window))) 118 (throw 'found window)))
116 minibuf all-frames) 119 minibuf all-frames)
@@ -122,14 +125,13 @@ Anything else means restrict to the selected frame."
122 125
123(defmacro save-selected-window (&rest body) 126(defmacro save-selected-window (&rest body)
124 "Execute BODY, then select the window that was selected before BODY." 127 "Execute BODY, then select the window that was selected before BODY."
125 (list 'let 128 `(let ((save-selected-window-window (selected-window)))
126 '((save-selected-window-window (selected-window))) 129 (unwind-protect
127 (list 'unwind-protect 130 (progn ,@body)
128 (cons 'progn body) 131 (select-window save-selected-window-window))))
129 (list 'select-window 'save-selected-window-window))))
130 132
131(defun count-windows (&optional minibuf) 133(defun count-windows (&optional minibuf)
132 "Returns the number of visible windows. 134 "Return the number of visible windows.
133This counts the windows in the selected frame and (if the minibuffer is 135This counts the windows in the selected frame and (if the minibuffer is
134to be counted) its minibuffer frame (if that's not the same frame). 136to be counted) its minibuffer frame (if that's not the same frame).
135The optional arg MINIBUF non-nil means count the minibuffer 137The optional arg MINIBUF non-nil means count the minibuffer
@@ -140,8 +142,18 @@ even if it is inactive."
140 minibuf) 142 minibuf)
141 count)) 143 count))
142 144
145(defun window-safely-shrinkable-p (&optional window)
146 "Non-nil if the WINDOW can be shrunk without shrinking other windows."
147 (save-selected-window
148 (when window (select-window window))
149 (or (and (not (eq window (frame-first-window)))
150 (= (car (window-edges))
151 (car (window-edges (previous-window)))))
152 (= (car (window-edges))
153 (car (window-edges (next-window)))))))
154
143(defun balance-windows () 155(defun balance-windows ()
144 "Makes all visible windows the same height (approximately)." 156 "Make all visible windows the same height (approximately)."
145 (interactive) 157 (interactive)
146 (let ((count -1) levels newsizes size 158 (let ((count -1) levels newsizes size
147 ;; Don't count the lines that are above the uppermost windows. 159 ;; Don't count the lines that are above the uppermost windows.
@@ -401,15 +413,15 @@ due to line breaking, display table, etc.
401Optional arguments BEG and END default to `point-min' and `point-max' 413Optional arguments BEG and END default to `point-min' and `point-max'
402respectively. 414respectively.
403 415
404If region ends with a newline, ignore it unless optinal third argument 416If region ends with a newline, ignore it unless optional third argument
405COUNT-FINAL-NEWLINE is non-nil. 417COUNT-FINAL-NEWLINE is non-nil.
406 418
407The optional fourth argument WINDOW specifies the window used for obtaining 419The optional fourth argument WINDOW specifies the window used for obtaining
408parameters such as width, horizontal scrolling, and so on. The default is 420parameters such as width, horizontal scrolling, and so on. The default is
409to use the selected window's parameters. 421to use the selected window's parameters.
410 422
411Like `vertical-motion', `count-screen-lines' always uses the current buffer, 423Like `vertical-motion', `count-screen-lines' always uses the current buffer,
412regardless of which buffer is displayed in WINDOW. This makes possible to use 424regardless of which buffer is displayed in WINDOW. This makes possible to use
413`count-screen-lines' in any buffer, whether or not it is currently displayed 425`count-screen-lines' in any buffer, whether or not it is currently displayed
414in some window." 426in some window."
415 (unless beg 427 (unless beg
@@ -511,8 +523,9 @@ header-line."
511Do not shrink to less than `window-min-height' lines. 523Do not shrink to less than `window-min-height' lines.
512Do nothing if the buffer contains more lines than the present window height, 524Do nothing if the buffer contains more lines than the present window height,
513or if some of the window's contents are scrolled out of view, 525or if some of the window's contents are scrolled out of view,
514or if the window is not the full width of the frame, 526or if shrinking this window would also shrink another window.
515or if the window is the only window of its frame." 527or if the window is the only window of its frame.
528Return non-nil if the window was shrunk."
516 (interactive) 529 (interactive)
517 (when (null window) 530 (when (null window)
518 (setq window (selected-window))) 531 (setq window (selected-window)))
@@ -520,7 +533,7 @@ or if the window is the only window of its frame."
520 (mini (frame-parameter frame 'minibuffer)) 533 (mini (frame-parameter frame 'minibuffer))
521 (edges (window-edges window))) 534 (edges (window-edges window)))
522 (if (and (not (eq window (frame-root-window frame))) 535 (if (and (not (eq window (frame-root-window frame)))
523 (= (window-width) (frame-width)) 536 (window-safely-shrinkable-p)
524 (pos-visible-in-window-p (point-min) window) 537 (pos-visible-in-window-p (point-min) window)
525 (not (eq mini 'only)) 538 (not (eq mini 'only))
526 (or (not mini) 539 (or (not mini)
@@ -592,4 +605,4 @@ and the buffer that is killed or buried is the one in that window."
592(define-key ctl-x-map "+" 'balance-windows) 605(define-key ctl-x-map "+" 'balance-windows)
593(define-key ctl-x-4-map "0" 'kill-buffer-and-window) 606(define-key ctl-x-4-map "0" 'kill-buffer-and-window)
594 607
595;;; windows.el ends here 608;;; window.el ends here