diff options
| author | Eric S. Raymond | 1993-04-14 03:34:44 +0000 |
|---|---|---|
| committer | Eric S. Raymond | 1993-04-14 03:34:44 +0000 |
| commit | a0900d9fca611b2a4fe0cc9fe97abdf77b81d8e5 (patch) | |
| tree | 7673056e5660595cc7f9625673f4020a956451ea | |
| parent | 64e07c7ba74f179fab08694c5dd6d5633ebb1d5a (diff) | |
| download | emacs-a0900d9fca611b2a4fe0cc9fe97abdf77b81d8e5.tar.gz emacs-a0900d9fca611b2a4fe0cc9fe97abdf77b81d8e5.zip | |
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
minor bug fix. This is to avoid code duplication between vc.el,
electric.el, and finder.el.
(ctl-x-map): Added C-x - and C-x + as bindings for
shrink-window-if-larger-than-buffer and balance-windows respectively.
Since shrink-window-if-larger-than-buffer has to live here anyhow, let
users use it to manage screen space.
| -rw-r--r-- | lisp/window.el | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lisp/window.el b/lisp/window.el index 089b4f3b4ff..840035a4af8 100644 --- a/lisp/window.el +++ b/lisp/window.el | |||
| @@ -109,9 +109,42 @@ ARG columns. No arg means split equally." | |||
| 109 | (interactive "p") | 109 | (interactive "p") |
| 110 | (shrink-window arg t)) | 110 | (shrink-window arg t)) |
| 111 | 111 | ||
| 112 | (defun shrink-window-if-larger-than-buffer (&optional window) | ||
| 113 | "Shrink the WINDOW to be as small as possible to display its contents. Do | ||
| 114 | nothing if only one window is displayed or if the buffer contains more lines | ||
| 115 | than the present window height." | ||
| 116 | (save-excursion | ||
| 117 | (set-buffer (window-buffer window)) | ||
| 118 | (let ((w (selected-window)) ;save-window-excursion can't win | ||
| 119 | (buffer-file-name buffer-file-name) | ||
| 120 | (p (point)) | ||
| 121 | (n 0) | ||
| 122 | (window-min-height 0) | ||
| 123 | (buffer-read-only nil) | ||
| 124 | (modified (buffer-modified-p)) | ||
| 125 | (buffer (current-buffer))) | ||
| 126 | (unwind-protect | ||
| 127 | (progn | ||
| 128 | (select-window (or window w)) | ||
| 129 | (goto-char (point-min)) | ||
| 130 | (while (pos-visible-in-window-p (point-max)) | ||
| 131 | ;; defeat file locking... don't try this at home, kids! | ||
| 132 | (setq buffer-file-name nil) | ||
| 133 | (insert ?\n) (setq n (1+ n))) | ||
| 134 | (if (> n 0) (shrink-window (1- n)))) | ||
| 135 | (delete-region (point-min) (point)) | ||
| 136 | (set-buffer-modified-p modified) | ||
| 137 | (goto-char p) | ||
| 138 | (select-window w) | ||
| 139 | ;; Make sure we unbind buffer-read-only | ||
| 140 | ;; with the proper current buffer. | ||
| 141 | (set-buffer buffer))))) | ||
| 142 | |||
| 112 | (define-key ctl-x-map "2" 'split-window-vertically) | 143 | (define-key ctl-x-map "2" 'split-window-vertically) |
| 113 | (define-key ctl-x-map "3" 'split-window-horizontally) | 144 | (define-key ctl-x-map "3" 'split-window-horizontally) |
| 114 | (define-key ctl-x-map "}" 'enlarge-window-horizontally) | 145 | (define-key ctl-x-map "}" 'enlarge-window-horizontally) |
| 115 | (define-key ctl-x-map "{" 'shrink-window-horizontally) | 146 | (define-key ctl-x-map "{" 'shrink-window-horizontally) |
| 147 | (define-key ctl-x-map "-" 'shrink-window-if-larger-than-buffer) | ||
| 148 | (define-key ctl-x-map "+" 'balance-windows) | ||
| 116 | 149 | ||
| 117 | ;;; windows.el ends here | 150 | ;;; windows.el ends here |