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

  1. ;From ark1!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!moose.crd.ge.com!montnaro Thu Dec 14 11:46:14 1989
  2. ;Article 845 of gnu.emacs:
  3. ;Path: ark1!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!moose.crd.ge.com!montnaro
  4. ;From montnaro@moose.crd.ge.com (Skip Montanaro)
  5. ;Newsgroups: gnu.emacs
  6. ;Subject: Grow and shrink minibuffer window as minibuffer grows and shrinks
  7. ;Message-ID: <8912140405.AA00554@moose.crd.Ge.Com>
  8. ;Date: 14 Dec 89 04:05:25 GMT
  9. ;Sender: daemon@tut.cis.ohio-state.edu
  10. ;Reply-To: <montanaro@crdgw1.ge.com> (Skip Montanaro)
  11. ;Distribution: gnu
  12. ;Organization: GNUs Not Usenet
  13. ;Lines: 128
  14. ;
  15. ;One thing that's always bugged me is that only a single line of a minibuffer
  16. ;is displayed when it is visible in a window. I took the first crude steps
  17. ;toward solving that dilemma this evening. The ELisp code that follows
  18. ;rebinds the keys DEL, C-d, C-k, C-o, C-n, and C-q so that the minibuffer
  19. ;grows or shrinks as necessary (up to at most minibuffer-max-window-height
  20. ;lines) to display the entire minibuffer contents.
  21. ;
  22. ;The code has only been minimally tested, but what's there appears to work.
  23. ;
  24. ;Feedback is appreciated. Note that I left the point positioning commands for
  25. ;another time. Feel free to send me any suggestions, bugs, whatever ...
  26. ;
  27. ;Skip (montanaro@crdgw1.ge.com)
  28. ;
  29. ;------------------------------------------------------------------------------
  30. ;;; minibuf.el - grow/shrink minibuffer window so all lines show
  31. ;;; Skip Montanaro - 12/13/89
  32. ;;; This file is not (yet) part of GNU Emacs, however, GNU copyleft applies
  33.  
  34.  
  35. (defvar minibuffer-max-window-height 1
  36.   "*Maximum number of lines a minibuffer window can normally display.
  37. Defaults to 1.")
  38.  
  39.  
  40. ;;; functions that can grow the minibuffer window
  41.  
  42. (defun minibuffer-open-line (arg)
  43.   "Open line in current minibuffer and enlarge if not all are visible."
  44.   (interactive "P")
  45.   (open-line (or arg 1))
  46.   (minibuffer-enlarge-window))
  47.  
  48.  
  49. (defun minibuffer-next-line (arg)
  50.   "Goto next line in current minibuffer and enlarge if not all are visible."
  51.   (interactive "P")
  52.   (next-line (or arg 1))
  53.   (minibuffer-enlarge-window))
  54.  
  55.  
  56. (defun minibuffer-quoted-insert (c)
  57.   "Read next input char and insert it. If ^J, enlarge window if not all visible."
  58.   (interactive "c")
  59.   (insert c)
  60.   (if (eq c ?\C-j) (minibuffer-enlarge-window)))
  61.  
  62.  
  63. (defun minibuffer-enlarge-window ()
  64.   (if (and (< (window-height) minibuffer-max-window-height)
  65.        (or (not (pos-visible-in-window-p (point-min) nil))
  66.            (not (pos-visible-in-window-p (point-max) nil))))
  67.       (enlarge-window 1))
  68.   (goto-char (prog1 (point) (goto-char (point-min)) (recenter 0))))
  69.  
  70.  
  71. ;;; functions that can shrink the minibuffer window
  72.  
  73. (defun minibuffer-delete-char (arg)
  74.   "Like delete-char, but shrinks minibuffer window if possible."
  75.   (interactive "P")
  76.   (delete-char (or arg 1))
  77.   (minibuffer-shrink-window))
  78.  
  79.  
  80. (defun minibuffer-kill-line (arg)
  81.   "Like kill-line, but shrinks minibuffer window if possible."
  82.   (interactive "P")
  83.   (kill-line arg)
  84.   (minibuffer-shrink-window))
  85.  
  86.  
  87. (defun minibuffer-backward-delete-char (arg)
  88.   "Like backward-delete-char, but may shrink minibuffer window."
  89.   (interactive "P")
  90.   (backward-delete-char (or arg 1))
  91.   (minibuffer-shrink-window))
  92.  
  93.  
  94. (defun minibuffer-shrink-window ()
  95.   "Shrink wrap minibuffer window about (point-min) and (point-max)."
  96.   (if (and (> (window-height) 1)
  97.        (< (count-lines (point-min) (point-max)) (window-height)))
  98.       (shrink-window (- (window-height) (count-lines (point-min) (point-max))))))
  99.  
  100.  
  101. ;;; common functions that move around in the minibuffer
  102.  
  103. ;;; minibuffer replacements for
  104.  
  105. ;;; previous-line
  106. ;;; end-of-buffer
  107. ;;; beginning-of-buffer
  108. ;;; scroll-up
  109. ;;; scroll-down
  110.  
  111. ;;; are left as an exercise to the reader. I'm going to bed.
  112.  
  113.  
  114. ;;; and the key bindings. 
  115. ;;; (should be a loop over the various minibuffer maps)
  116. (define-key minibuffer-local-map "\C-o" 'minibuffer-open-line)
  117. (define-key minibuffer-local-map "\C-n" 'minibuffer-next-line)
  118. (define-key minibuffer-local-map "\C-q" 'minibuffer-quoted-insert)
  119. (define-key minibuffer-local-map "\C-d" 'minibuffer-delete-char)
  120. (define-key minibuffer-local-map "\C-k" 'minibuffer-kill-line)
  121. (define-key minibuffer-local-map "\C-?" 'minibuffer-backward-delete-char)
  122.  
  123. (define-key minibuffer-local-completion-map "\C-o" 'minibuffer-open-line)
  124. (define-key minibuffer-local-completion-map "\C-n" 'minibuffer-next-line)
  125. (define-key minibuffer-local-completion-map "\C-q" 'minibuffer-quoted-insert)
  126. (define-key minibuffer-local-completion-map "\C-d" 'minibuffer-delete-char)
  127. (define-key minibuffer-local-completion-map "\C-k" 'minibuffer-kill-line)
  128. (define-key minibuffer-local-completion-map "\C-?" 'minibuffer-backward-delete-char)
  129.  
  130. (define-key minibuffer-local-must-match-map "\C-o" 'minibuffer-open-line)
  131. (define-key minibuffer-local-must-match-map "\C-n" 'minibuffer-next-line)
  132. (define-key minibuffer-local-must-match-map "\C-q" 'minibuffer-quoted-insert)
  133. (define-key minibuffer-local-must-match-map "\C-d" 'minibuffer-delete-char)
  134. (define-key minibuffer-local-must-match-map "\C-k" 'minibuffer-kill-line)
  135. (define-key minibuffer-local-must-match-map "\C-?" 'minibuffer-backward-delete-char)
  136.  
  137. (define-key minibuffer-local-ns-map "\C-o" 'minibuffer-open-line)
  138. (define-key minibuffer-local-ns-map "\C-n" 'minibuffer-next-line)
  139. (define-key minibuffer-local-ns-map "\C-q" 'minibuffer-quoted-insert)
  140. (define-key minibuffer-local-ns-map "\C-d" 'minibuffer-delete-char)
  141. (define-key minibuffer-local-ns-map "\C-k" 'minibuffer-kill-line)
  142. (define-key minibuffer-local-ns-map "\C-?" 'minibuffer-backward-delete-char)
  143.  
  144.  
  145.