Mercurial > emacs
comparison lisp/window.el @ 36:9697c13298e5
Initial revision
author | Joseph Arceneaux <jla@gnu.org> |
---|---|
date | Tue, 31 Oct 1989 16:00:07 +0000 |
parents | |
children | 8644955999f0 |
comparison
equal
deleted
inserted
replaced
35:63b375f17a65 | 36:9697c13298e5 |
---|---|
1 ;; GNU Emacs window commands aside from those written in C. | |
2 ;; Copyright (C) 1985, 1989 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 1, 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) | |
45 "Split current window into two windows, one above the other. | |
46 This window becomes the uppermost of the two, and gets | |
47 ARG lines. No arg means split equally." | |
48 (interactive "P") | |
49 (let ((old-w (selected-window)) | |
50 new-w bottom) | |
51 (setq new-w (split-window nil (and arg (prefix-numeric-value arg)))) | |
52 (save-excursion | |
53 (set-buffer (window-buffer)) | |
54 (goto-char (window-start)) | |
55 (vertical-motion (window-height)) | |
56 (set-window-start new-w (point)) | |
57 (if (> (point) (window-point new-w)) | |
58 (set-window-point new-w (point))) | |
59 (vertical-motion -1) | |
60 (setq bottom (point))) | |
61 (if (<= bottom (point)) | |
62 (set-window-point old-w (1- bottom))))) | |
63 | |
64 (defun split-window-horizontally (&optional arg) | |
65 "Split current window into two windows side by side. | |
66 This window becomes the leftmost of the two, and gets | |
67 ARG columns. No arg means split equally." | |
68 (interactive "P") | |
69 (split-window nil (and arg (prefix-numeric-value arg)) t)) | |
70 | |
71 (defun enlarge-window-horizontally (arg) | |
72 "Make current window ARG columns wider." | |
73 (interactive "p") | |
74 (enlarge-window arg t)) | |
75 | |
76 (defun shrink-window-horizontally (arg) | |
77 "Make current window ARG columns narrower." | |
78 (interactive "p") | |
79 (shrink-window arg t)) | |
80 | |
81 (defun window-config-to-register (name) | |
82 "Save the current window configuration in register REG (a letter). | |
83 It can be later retrieved using \\[M-x register-to-window-config]." | |
84 (interactive "cSave window configuration in register: ") | |
85 (set-register name (current-window-configuration))) | |
86 | |
87 (defun register-to-window-config (name) | |
88 "Restore (make current) the window configuration in register REG (a letter). | |
89 Use with a register previously set with \\[window-config-to-register]." | |
90 (interactive "cRestore window configuration from register: ") | |
91 (set-window-configuration (get-register name))) | |
92 | |
93 (define-key ctl-x-map "2" 'split-window-vertically) | |
94 (define-key ctl-x-map "5" 'split-window-horizontally) | |
95 (define-key ctl-x-map "6" 'window-config-to-register) | |
96 (define-key ctl-x-map "7" 'register-to-window-config) | |
97 (define-key ctl-x-map "}" 'enlarge-window-horizontally) | |
98 (define-key ctl-x-map "{" 'shrink-window-horizontally) |