comparison lisp/electric.el @ 2540:0c20256f752d

(shrink-window-if-larger-than-buffer): Moved to window.el.
author Eric S. Raymond <esr@snark.thyrsus.com>
date Fri, 16 Apr 1993 19:23:21 +0000
parents 0d9cbf4b25c8
children 13660e63d8f0
comparison
equal deleted inserted replaced
2539:577c77cfd199 2540:0c20256f752d
26 26
27 ; zaaaaaaap 27 ; zaaaaaaap
28 28
29 ;;; Code: 29 ;;; Code:
30 30
31 ;; perhaps this should be in subr.el...
32 (defun shrink-window-if-larger-than-buffer (&optional window)
33 "Shrink the WINDOW to be as small as possible to display its contents. Do
34 nothing if only one window is displayed or if the buffer contains more lines
35 than the present window height."
36 (save-excursion
37 (set-buffer (window-buffer window))
38 (let ((w (selected-window)) ;save-window-excursion can't win
39 (buffer-file-name buffer-file-name)
40 (p (point))
41 (n 0)
42 (window-min-height 0)
43 (buffer-read-only nil)
44 (modified (buffer-modified-p))
45 (buffer (current-buffer)))
46 (unwind-protect
47 (progn
48 (select-window window)
49 (goto-char (point-min))
50 (while (pos-visible-in-window-p (point-max))
51 ;; defeat file locking... don't try this at home, kids!
52 (setq buffer-file-name nil)
53 (insert ?\n) (setq n (1+ n)))
54 (if (> n 0) (shrink-window (1- n))))
55 (delete-region (point-min) (point))
56 (set-buffer-modified-p modified)
57 (goto-char p)
58 (select-window w)
59 ;; Make sure we unbind buffer-read-only
60 ;; with the proper current buffer.
61 (set-buffer buffer)))))
62
63 ;; This loop is the guts for non-standard modes which retain control 31 ;; This loop is the guts for non-standard modes which retain control
64 ;; until some event occurs. It is a `do-forever', the only way out is to 32 ;; until some event occurs. It is a `do-forever', the only way out is to
65 ;; throw. It assumes that you have set up the keymap, window, and 33 ;; throw. It assumes that you have set up the keymap, window, and
66 ;; everything else: all it does is read commands and execute them - 34 ;; everything else: all it does is read commands and execute them -
67 ;; providing error messages should one occur (if there is no loop 35 ;; providing error messages should one occur (if there is no loop