comparison lisp/window.el @ 3342:ce8aa0ba8b08

(shrink-window-if-larger-than-buffer): Add `interactive'. Do nothing if window contents not entirely visible.
author Richard M. Stallman <rms@gnu.org>
date Mon, 31 May 1993 04:56:19 +0000
parents f4d37be94734
children 13ddc81f0b43
comparison
equal deleted inserted replaced
3341:79657d6d8843 3342:ce8aa0ba8b08
109 "Make current window ARG columns narrower." 109 "Make current window ARG columns narrower."
110 (interactive "p") 110 (interactive "p")
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.
115 nothing if only one window is displayed or if the buffer contains more lines 115 Do nothing if the buffer contains more lines than the present window height,
116 than the present window height." 116 or 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
120 (buffer-file-name buffer-file-name) 121 (buffer-file-name buffer-file-name)
121 (p (point)) 122 (p (point))
122 (n 0) 123 (n 0)
123 (window-min-height 0) 124 (window-min-height 0)
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)
146 (define-key ctl-x-map "}" 'enlarge-window-horizontally) 148 (define-key ctl-x-map "}" 'enlarge-window-horizontally)
147 (define-key ctl-x-map "{" 'shrink-window-horizontally) 149 (define-key ctl-x-map "{" 'shrink-window-horizontally)