home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / lucid / lemacs-19.6 / lisp / prim / window.el < prev    next >
Encoding:
Text File  |  1993-01-17  |  4.0 KB  |  108 lines

  1. ;; GNU Emacs window commands aside from those written in C.
  2. ;; Copyright (C) 1985-1993 Free Software Foundation, Inc.
  3.  
  4. ;; This file is part of GNU Emacs.
  5.  
  6. ;; GNU Emacs is free software; you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation; either version 2, or (at your option)
  9. ;; any later version.
  10.  
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. ;; GNU General Public License for more details.
  15.  
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  18. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20.  
  21. (defun count-windows (&optional minibuf)
  22.    "Returns the number of visible windows.
  23. Optional arg NO-MINI non-nil means don't count the minibuffer
  24. even if it is active."
  25.    (let ((count 0))
  26.      (walk-windows (function (lambda ()
  27.                    (setq count (+ count 1))))
  28.            minibuf)
  29.      count))
  30.  
  31. (defun balance-windows ()
  32.   "Makes all visible windows the same size (approximately)."
  33.   (interactive)
  34.   (let ((count 0))
  35.     (walk-windows (function (lambda (w)
  36.                   (setq count (+ count 1))))
  37.           'nomini)
  38.     (let ((size (/ (screen-height) count)))
  39.       (walk-windows (function (lambda (w)
  40.                 (select-window w)
  41.                 (enlarge-window (- size (window-height)))))
  42.             'nomini))))
  43.  
  44. (defun split-window-vertically (&optional arg hack-display)
  45.   "Split current window into two windows, one above the other.
  46. The top window gets ARG lines.  No arg means split equally.
  47.  
  48. The two windows will be displaying the same text as before: both windows will
  49. be displaying the current buffer, but the second window will be scrolled such
  50. that little redisplay will happen - the lines that were on the screen before
  51. the split will still be on the screen, in the same places.  
  52.  
  53. An effort is made to keep the cursor in the same place relative to the text on
  54. the screen as well.  If the cursor is below the split-point before the split,
  55. then the bottom window will be selected; otherwise the top window will be
  56. selected."
  57.   (interactive (list current-prefix-arg t))
  58.   (let ((old-w (selected-window))
  59.     new-w)
  60.     (setq new-w (split-window nil (and arg (prefix-numeric-value arg))))
  61.     (if hack-display
  62.     (let (bottom)
  63.       (save-excursion
  64.         (set-buffer (window-buffer))
  65.         (goto-char (window-start))
  66.         (vertical-motion (window-height))
  67.         (set-window-start new-w (point))
  68.         (if (>= (point) (window-point new-w))
  69.         (set-window-point new-w (point)))
  70.         (vertical-motion -1)
  71.         (if (pos-visible-in-window-p (point) new-w)
  72.         (set-window-start new-w (point)))
  73.         (setq bottom (point)))
  74.       (if (<= bottom (point))
  75.           (progn
  76.         (set-window-point old-w (1- bottom))
  77.         (select-window new-w)))))
  78.     new-w))
  79.  
  80. (defun split-window-horizontally (&optional arg)
  81.   "Split current window into two windows side by side.
  82. This window becomes the leftmost of the two, and gets
  83. ARG columns.  No arg means split equally."
  84.   (interactive "P")
  85.   (split-window nil (and arg (prefix-numeric-value arg)) t))
  86.  
  87. (defun enlarge-window-horizontally (arg)
  88.   "Make current window ARG columns wider."
  89.   (interactive "p")
  90.   (enlarge-window arg t))
  91.  
  92. (defun shrink-window-horizontally (arg)
  93.   "Make current window ARG columns narrower."
  94.   (interactive "p")
  95.   (shrink-window arg t))
  96.  
  97. (defun window-config-to-register (name)
  98.   "Save the current window configuration in register REG (a letter).
  99. It can be later retrieved using \\[M-x register-to-window-config]."
  100.   (interactive "cSave window configuration in register: ")
  101.   (set-register name (current-window-configuration)))
  102.  
  103. (defun register-to-window-config (name)
  104.   "Restore (make current) the window configuration in register REG (a letter).
  105. Use with a register previously set with \\[window-config-to-register]."
  106.   (interactive "cRestore window configuration from register: ")
  107.   (set-window-configuration (get-register name)))
  108.