diff options
| author | Stefan Monnier | 2000-11-21 21:44:25 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2000-11-21 21:44:25 +0000 |
| commit | fe7a0e7dfda8647fda72facc6c9e582629d368e8 (patch) | |
| tree | fb16aaee3d6569417205eba7d08e3e347d7a0075 | |
| parent | c344cf32d5529c14a5bb15095bfbeb7680abe306 (diff) | |
| download | emacs-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.el | 51 |
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). |
| 31 | Optional arg NOMINI non-nil means don't count the minibuffer | 34 | Optional arg NOMINI non-nil means don't count the minibuffer |
| 32 | even if it is active. | 35 | even if it is active. |
| 33 | 36 | ||
| 34 | The optional arg ALL-FRAMES t means count windows on all frames. | 37 | The optional arg ALL-FRAMES t means count windows on all frames. |
| 35 | If it is `visible', count windows on all visible frames. | 38 | If it is `visible', count windows on all visible frames. |
| 36 | ALL-FRAMES nil or omitted means count only the selected frame, | 39 | ALL-FRAMES nil or omitted means count only the selected frame, |
| 37 | plus the minibuffer it uses (which may be on another frame). | 40 | plus the minibuffer it uses (which may be on another frame). |
| 38 | If ALL-FRAMES is neither nil nor t, count only the selected frame." | 41 | If 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. | |||
| 110 | If ALL-FRAMES is a frame, it means include windows on that frame. | 113 | If ALL-FRAMES is a frame, it means include windows on that frame. |
| 111 | Anything else means restrict to the selected frame." | 114 | Anything 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. |
| 133 | This counts the windows in the selected frame and (if the minibuffer is | 135 | This counts the windows in the selected frame and (if the minibuffer is |
| 134 | to be counted) its minibuffer frame (if that's not the same frame). | 136 | to be counted) its minibuffer frame (if that's not the same frame). |
| 135 | The optional arg MINIBUF non-nil means count the minibuffer | 137 | The 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. | |||
| 401 | Optional arguments BEG and END default to `point-min' and `point-max' | 413 | Optional arguments BEG and END default to `point-min' and `point-max' |
| 402 | respectively. | 414 | respectively. |
| 403 | 415 | ||
| 404 | If region ends with a newline, ignore it unless optinal third argument | 416 | If region ends with a newline, ignore it unless optional third argument |
| 405 | COUNT-FINAL-NEWLINE is non-nil. | 417 | COUNT-FINAL-NEWLINE is non-nil. |
| 406 | 418 | ||
| 407 | The optional fourth argument WINDOW specifies the window used for obtaining | 419 | The optional fourth argument WINDOW specifies the window used for obtaining |
| 408 | parameters such as width, horizontal scrolling, and so on. The default is | 420 | parameters such as width, horizontal scrolling, and so on. The default is |
| 409 | to use the selected window's parameters. | 421 | to use the selected window's parameters. |
| 410 | 422 | ||
| 411 | Like `vertical-motion', `count-screen-lines' always uses the current buffer, | 423 | Like `vertical-motion', `count-screen-lines' always uses the current buffer, |
| 412 | regardless of which buffer is displayed in WINDOW. This makes possible to use | 424 | regardless 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 |
| 414 | in some window." | 426 | in some window." |
| 415 | (unless beg | 427 | (unless beg |
| @@ -511,8 +523,9 @@ header-line." | |||
| 511 | Do not shrink to less than `window-min-height' lines. | 523 | Do not shrink to less than `window-min-height' lines. |
| 512 | Do nothing if the buffer contains more lines than the present window height, | 524 | Do nothing if the buffer contains more lines than the present window height, |
| 513 | or if some of the window's contents are scrolled out of view, | 525 | or if some of the window's contents are scrolled out of view, |
| 514 | or if the window is not the full width of the frame, | 526 | or if shrinking this window would also shrink another window. |
| 515 | or if the window is the only window of its frame." | 527 | or if the window is the only window of its frame. |
| 528 | Return 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 |