aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1993-05-31 04:56:19 +0000
committerRichard M. Stallman1993-05-31 04:56:19 +0000
commitd0bee390ddc6377470005d83b17680dcd3391773 (patch)
treedb2ee0813ea1a563378034eacc60c88368bebd4a
parentf2d5c40e658384f14279e5cef0acd952c43cd86e (diff)
downloademacs-d0bee390ddc6377470005d83b17680dcd3391773.tar.gz
emacs-d0bee390ddc6377470005d83b17680dcd3391773.zip
(shrink-window-if-larger-than-buffer): Add `interactive'.
Do nothing if window contents not entirely visible.
-rw-r--r--lisp/window.el40
1 files changed, 21 insertions, 19 deletions
diff --git a/lisp/window.el b/lisp/window.el
index d9ad3a2e1a6..621e0706efa 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -111,9 +111,10 @@ ARG columns. No arg means split equally."
111 (shrink-window arg t)) 111 (shrink-window arg t))
112 112
113(defun shrink-window-if-larger-than-buffer (&optional window) 113(defun shrink-window-if-larger-than-buffer (&optional window)
114 "Shrink the WINDOW to be as small as possible to display its contents. Do 114 "Shrink the WINDOW to be as small as possible to display its contents.
115nothing if only one window is displayed or if the buffer contains more lines 115Do nothing if the buffer contains more lines than the present window height,
116than the present window height." 116or if some of the window's contents are scrolled out of view."
117 (interactive)
117 (save-excursion 118 (save-excursion
118 (set-buffer (window-buffer window)) 119 (set-buffer (window-buffer window))
119 (let ((w (selected-window)) ;save-window-excursion can't win 120 (let ((w (selected-window)) ;save-window-excursion can't win
@@ -124,22 +125,23 @@ than the present window height."
124 (buffer-read-only nil) 125 (buffer-read-only nil)
125 (modified (buffer-modified-p)) 126 (modified (buffer-modified-p))
126 (buffer (current-buffer))) 127 (buffer (current-buffer)))
127 (unwind-protect 128 (if (pos-visible-in-window-p (point-min))
128 (progn 129 (unwind-protect
129 (select-window (or window w)) 130 (progn
130 (goto-char (point-min)) 131 (select-window (or window w))
131 (while (pos-visible-in-window-p (point-max)) 132 (goto-char (point-min))
132 ;; defeat file locking... don't try this at home, kids! 133 (while (pos-visible-in-window-p (point-max))
133 (setq buffer-file-name nil) 134 ;; defeat file locking... don't try this at home, kids!
134 (insert ?\n) (setq n (1+ n))) 135 (setq buffer-file-name nil)
135 (if (> n 0) (shrink-window (1- n)))) 136 (insert ?\n) (setq n (1+ n)))
136 (delete-region (point-min) (point)) 137 (if (> n 0) (shrink-window (1- n))))
137 (set-buffer-modified-p modified) 138 (delete-region (point-min) (point))
138 (goto-char p) 139 (set-buffer-modified-p modified)
139 (select-window w) 140 (goto-char p)
140 ;; Make sure we unbind buffer-read-only 141 (select-window w)
141 ;; with the proper current buffer. 142 ;; Make sure we unbind buffer-read-only
142 (set-buffer buffer))))) 143 ;; with the proper current buffer.
144 (set-buffer buffer))))))
143 145
144(define-key ctl-x-map "2" 'split-window-vertically) 146(define-key ctl-x-map "2" 'split-window-vertically)
145(define-key ctl-x-map "3" 'split-window-horizontally) 147(define-key ctl-x-map "3" 'split-window-horizontally)