home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / functions / shrink2reg.el < prev    next >
Encoding:
Text File  |  1990-07-22  |  2.2 KB  |  59 lines

  1. ;From utkcs2!emory!swrinde!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!ri.osf.fr!macrakis Wed Jun 20 09:30:18 EDT 1990
  2. ;Article 2111 of gnu.emacs.bug:
  3. ;Path: utkcs2!emory!swrinde!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!ri.osf.fr!macrakis
  4. ;>From: macrakis@ri.osf.fr
  5. ;Newsgroups: gnu.emacs.bug
  6. ;Subject: Window resizing
  7. ;Message-ID: <9006201248.AA22931@.dupuis.gr.osf.org.>
  8. ;Date: 20 Jun 90 12:49:06 GMT
  9. ;Sender: daemon@tut.cis.ohio-state.edu
  10. ;Distribution: gnu
  11. ;Organization: GNUs Not Usenet
  12. ;Lines: 42
  13. ;X-Unparsable-Date: Wed, 20 Jun 90 13:53:11 GMT+0100
  14. ;
  15. ;GNU Emacs 18.53.11 on NeXT 1.0.1
  16. ;
  17. ;Emacs pretends that window size is just a question of proportions.
  18. ;Thus, when a window goes away, its lines get allocated among other
  19. ;windows.  Or if you resize a window, windows below it get smaller.
  20. ;
  21. ;But in practice, some windows logically have a fixed size.  This is
  22. ;the case of windows that are "just the right size" for a piece of
  23. ;information.  (See below for a little command that shrink-wraps a
  24. ;region in a window.)  However, Emacs doesn't understand this.  In
  25. ;particular, if you try to shrink-wrap two windows, the shrinking of
  26. ;the second is likely to change the size of the first, which rather
  27. ;defeats the point....
  28. ;
  29. ;I have no specific suggestions -- and perhaps the problem will go away
  30. ;at the millenium (v19) -- but I thought I'd document the issue.
  31. ;
  32. ;    -s
  33.  
  34.  
  35. ;; Bound to ^X6 (mnemonic is that ^X^ is shrink-window)
  36.  
  37. (defun shrink-window-to-region (beg end)
  38.   "Makes window just small or large enough to hold region.\n\
  39. If only one window on screen, does nothing."
  40.    (interactive "r")
  41.   (if (eq (selected-window) (next-window (selected-window) 0))
  42.       ;;Is there a better way to test whether we have only 1 window?
  43.       nil
  44.     (save-excursion
  45.       ;; Make sure full lines are included on-screen
  46.       (goto-char beg)
  47.       (beginning-of-line 1)
  48.       (setq beg (point))
  49.       (goto-char end)
  50.       (beginning-of-line 2)
  51.       (setq end (point))
  52.       (let ((window-min-height 2))    ;Sometimes 1 line is enough
  53.     (shrink-window (- (window-height (selected-window))
  54.               (count-lines beg end)
  55.               1)))        ;Window height includes mode line
  56.       (set-window-start (selected-window) beg))))
  57.  
  58.  
  59.