home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / gnu / epoch / misc / 1229 < prev    next >
Encoding:
Text File  |  1992-12-31  |  3.5 KB  |  109 lines

  1. Newsgroups: gnu.epoch.misc
  2. Path: sparky!uunet!cis.ohio-state.edu!ims.COM!gerdh
  3. From: gerdh@ims.COM (Gerd Hoeren)
  4. Subject: Window shrink ELISP function
  5. Message-ID: <9212311651.AA01961@ente.ims.com>
  6. Sender: romig@cis.ohio-state.edu (Steve Romig)
  7. Organization: Gnus Not Usenet
  8. Distribution: gnu
  9. Date: Thu, 31 Dec 1992 16:51:35 GMT
  10. Lines: 97
  11.  
  12. Here is some Epoch ELISP code that changes the size of a window to fit
  13. the current buffer.  This is useful for taking up less screen space
  14. when working with small files.
  15.  
  16. You can assign shrink-to-fit to a function key and/or connect it to
  17. the DIRED display hook.
  18.  
  19. ;;
  20. ;; Reduce the window to fit small buffers.  The following global variables
  21. ;;  can be set to control how the (shrink-to-fit) function behaves.
  22. ;;
  23. (defvar shrink-max-lines 50
  24.   "*Maximum number of lines that (shrink-to-fit) puts in a window.")
  25. (defvar shrink-min-lines 3
  26.   "*Minimum number of lines that (shrink-to-fit) puts in a window.")
  27. (defvar shrink-max-columns 150
  28.   "*Maximum number of columns that (shrink-to-fit) puts in a window.")
  29. (defvar shrink-min-columns 40
  30.   "*Minimum number of columns that (shrink-to-fit) puts in a window.")
  31.  
  32. (defun shrink-to-fit ()
  33.   "Shrink the current window to fit around the current buffer.  Variables
  34. SHRINK-MAX-LINES, SHRINK-MIN-LINES, SHRINK-MAX-COLUMNS and SHRINK-MIN-COLUMNS
  35. set bounds on the largest and smallest resulting window."
  36.  
  37.   (let ((max-width shrink-min-columns) ; Longest line in the file
  38.     (num-lines 0)                  ; Number of lines in file
  39.     (off-screen))                  ; Number of lines to scroll down
  40.     (save-excursion
  41.  
  42.       ;; Calculate the number of lines and the longest line
  43.       (goto-char (point-min))
  44.       (while (search-forward "\n" (point-max) t)
  45.     (backward-char 1)
  46.     (setq max-width (max (1+ (current-column)) max-width))
  47.     (forward-char 1)
  48.     (setq num-lines (1+ num-lines)))
  49.  
  50.       ;; Change the screen size to fit around the text.  Note that the height
  51.       ;;  of the window is the size of the file plus one for the mode line
  52.       ;;  plus one for the local mini-buffer (if present).
  53.       (setq num-lines (1+ (max
  54.                (min num-lines shrink-max-lines)
  55.                shrink-min-lines)))
  56.       (setq max-width (min max-width shrink-max-columns))
  57.       (change-screen-size
  58.        max-width
  59.        (if epoch::nonlocal-minibuffer num-lines (1+ num-lines))
  60.        (current-screen))
  61.  
  62.       ;; See if we have white space beyond the last line of the file.
  63.       (goto-char (window-start))
  64.       (setq off-screen (forward-line (1- num-lines))))
  65.     (if (not (eq 0 off-screen))
  66.     ;; Put the last line of the file on the bottom of the window.
  67.     (scroll-down off-screen))))
  68.  
  69.  
  70. -----
  71.  
  72. You can assign shrink-to-fit to a function key with something like:
  73.  
  74. (define-function-key "KP_Add"       ;; Shrink window around buffer
  75.   '(lambda () (interactive)
  76.      (shrink-to-fit)))
  77.  
  78.  
  79. -----
  80.  
  81. The following connects shrink-to-fit to the DIRED display hook so that
  82. all DIRED windows automatically are fit to the size of their buffers.
  83. (dired-version's value is "5.257 from
  84. ftp.cs.buffalo.edu:pub/Emacs/diredall.tar.Z)
  85.  
  86. ;; The following shrinks all DIRED windows around the size of the text.
  87. (setq dired-after-readin-hook
  88.       (append dired-after-readin-hook '(shrink-to-fit)))
  89.  
  90.  
  91. If you start Epoch in DIRED, put the following in your startup file to
  92. shrink the initial DIRED display:
  93.  
  94. (shrink-to-fit)            ;; Shrink our current (Home) dired window
  95.  
  96.  
  97. -----
  98.  
  99. Happy Epoching!
  100.  
  101. --------------------------------------
  102. Gerd Hoeren
  103.   Integrated Measurement Systems, Inc.
  104.   Voice: (503) 626-7117
  105.   Fax:   (503) 644-6969
  106.   Email: gerdh@ims.com
  107. --------------------------------------
  108.  
  109.