Mercurial > emacs
annotate lisp/register.el @ 3591:507f64624555
Apply typo patches from Paul Eggert.
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Wed, 09 Jun 1993 11:59:12 +0000 |
parents | 7520bbbe9100 |
children | c57aec7e822b |
rev | line source |
---|---|
658
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
243
diff
changeset
|
1 ;;; register.el --- register commands for Emacs. |
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
243
diff
changeset
|
2 |
845 | 3 ;; Copyright (C) 1985 Free Software Foundation, Inc. |
4 | |
789
71d052f72ac1
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
779
diff
changeset
|
5 ;; Maintainer: FSF |
814
38b2499cb3e9
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
807
diff
changeset
|
6 ;; Keywords: internal |
789
71d052f72ac1
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
779
diff
changeset
|
7 |
47 | 8 ;; This file is part of GNU Emacs. |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
789
diff
changeset
|
12 ;; the Free Software Foundation; either version 2, or (at your option) |
47 | 13 ;; any later version. |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
23 | |
2315
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2203
diff
changeset
|
24 ;;; Commentary: |
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2203
diff
changeset
|
25 |
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2203
diff
changeset
|
26 ;; This package of functions emulates and somewhat extends the venerable |
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2203
diff
changeset
|
27 ;; TECO's `register' feature, which permits you to save various useful |
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2203
diff
changeset
|
28 ;; pieces of buffer state to named variables. The entry points are |
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2203
diff
changeset
|
29 ;; documented in the Emacs user's manual. |
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2203
diff
changeset
|
30 |
789
71d052f72ac1
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
779
diff
changeset
|
31 ;;; Code: |
47 | 32 |
33 (defvar register-alist nil | |
34 "Alist of elements (NAME . CONTENTS), one for each Emacs register. | |
35 NAME is a character (a number). CONTENTS is a string, number, | |
779 | 36 frame configuration, mark or list. |
2699
83fee0378e0e
(jump-to-register): Allow file name "in" a register.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
37 A list of strings represents a rectangle. |
83fee0378e0e
(jump-to-register): Allow file name "in" a register.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
38 A list of the form (file . NAME) represents the file named NAME.") |
47 | 39 |
40 (defun get-register (char) | |
41 "Return contents of Emacs register named CHAR, or nil if none." | |
42 (cdr (assq char register-alist))) | |
43 | |
44 (defun set-register (char value) | |
2699
83fee0378e0e
(jump-to-register): Allow file name "in" a register.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
45 "Set contents of Emacs register named CHAR to VALUE. Returns VALUE. |
83fee0378e0e
(jump-to-register): Allow file name "in" a register.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
46 See the documentation of the variable `register-alist' for possible VALUE." |
47 | 47 (let ((aelt (assq char register-alist))) |
48 (if aelt | |
49 (setcdr aelt value) | |
50 (setq aelt (cons char value)) | |
51 (setq register-alist (cons aelt register-alist))) | |
52 value)) | |
53 | |
1955
8ac912d2d369
(point-to-register): Make arg ARG optional.
Richard M. Stallman <rms@gnu.org>
parents:
845
diff
changeset
|
54 (defun point-to-register (char &optional arg) |
141 | 55 "Store current location of point in register REGISTER. |
779 | 56 With prefix argument, store current frame configuration. |
141 | 57 Use \\[jump-to-register] to go to that location or restore that configuration. |
47 | 58 Argument is a character, naming the register." |
141 | 59 (interactive "cPoint to register: \nP") |
779 | 60 (set-register char (if arg (current-frame-configuration) (point-marker)))) |
47 | 61 |
1955
8ac912d2d369
(point-to-register): Make arg ARG optional.
Richard M. Stallman <rms@gnu.org>
parents:
845
diff
changeset
|
62 (defun window-configuration-to-register (char &optional arg) |
820
cd6b1e1da3fc
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
814
diff
changeset
|
63 "Store the window configuration of the selected frame in register REGISTER. |
cd6b1e1da3fc
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
814
diff
changeset
|
64 Use \\[jump-to-register] to restore the configuration. |
cd6b1e1da3fc
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
814
diff
changeset
|
65 Argument is a character, naming the register." |
cd6b1e1da3fc
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
814
diff
changeset
|
66 (interactive "cPoint to register: \nP") |
cd6b1e1da3fc
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
814
diff
changeset
|
67 (set-register char (current-window-configuration))) |
cd6b1e1da3fc
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
814
diff
changeset
|
68 |
1955
8ac912d2d369
(point-to-register): Make arg ARG optional.
Richard M. Stallman <rms@gnu.org>
parents:
845
diff
changeset
|
69 (defun frame-configuration-to-register (char &optional arg) |
820
cd6b1e1da3fc
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
814
diff
changeset
|
70 "Store the window configuration of all frames in register REGISTER. |
cd6b1e1da3fc
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
814
diff
changeset
|
71 Use \\[jump-to-register] to restore the configuration. |
cd6b1e1da3fc
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
814
diff
changeset
|
72 Argument is a character, naming the register." |
cd6b1e1da3fc
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
814
diff
changeset
|
73 (interactive "cPoint to register: \nP") |
cd6b1e1da3fc
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
814
diff
changeset
|
74 (set-register char (current-frame-configuration))) |
cd6b1e1da3fc
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
814
diff
changeset
|
75 |
2571
b65cf676a09b
All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2315
diff
changeset
|
76 (defalias 'register-to-point 'jump-to-register) |
47 | 77 (defun jump-to-register (char) |
78 "Move point to location stored in a register. | |
2699
83fee0378e0e
(jump-to-register): Allow file name "in" a register.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
79 If the register contains a file name, find that file. |
83fee0378e0e
(jump-to-register): Allow file name "in" a register.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
80 \(To put a file name in a register, you must use `set-register'.) |
820
cd6b1e1da3fc
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
814
diff
changeset
|
81 If the register contains a window configuration (one frame) or a frame |
cd6b1e1da3fc
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
814
diff
changeset
|
82 configuration (all frames), restore that frame or all frames accordingly. |
47 | 83 Argument is a character, naming the register." |
84 (interactive "cJump to register: ") | |
85 (let ((val (get-register char))) | |
2202
081afcef5e85
Make frame configurations start with a distinctive symbol.
Jim Blandy <jimb@redhat.com>
parents:
1955
diff
changeset
|
86 (cond |
3039
7520bbbe9100
(jump-to-register): Don't fail if frame-configuration-p is unbound.
Richard M. Stallman <rms@gnu.org>
parents:
2699
diff
changeset
|
87 ((and (fboundp 'frame-configuration-p) |
7520bbbe9100
(jump-to-register): Don't fail if frame-configuration-p is unbound.
Richard M. Stallman <rms@gnu.org>
parents:
2699
diff
changeset
|
88 (frame-configuration-p val)) |
2202
081afcef5e85
Make frame configurations start with a distinctive symbol.
Jim Blandy <jimb@redhat.com>
parents:
1955
diff
changeset
|
89 (set-frame-configuration val)) |
081afcef5e85
Make frame configurations start with a distinctive symbol.
Jim Blandy <jimb@redhat.com>
parents:
1955
diff
changeset
|
90 ((window-configuration-p val) |
081afcef5e85
Make frame configurations start with a distinctive symbol.
Jim Blandy <jimb@redhat.com>
parents:
1955
diff
changeset
|
91 (set-window-configuration val)) |
081afcef5e85
Make frame configurations start with a distinctive symbol.
Jim Blandy <jimb@redhat.com>
parents:
1955
diff
changeset
|
92 ((markerp val) |
081afcef5e85
Make frame configurations start with a distinctive symbol.
Jim Blandy <jimb@redhat.com>
parents:
1955
diff
changeset
|
93 (switch-to-buffer (marker-buffer val)) |
081afcef5e85
Make frame configurations start with a distinctive symbol.
Jim Blandy <jimb@redhat.com>
parents:
1955
diff
changeset
|
94 (goto-char val)) |
2699
83fee0378e0e
(jump-to-register): Allow file name "in" a register.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
95 ((and (consp val) (eq (car val) 'file)) |
83fee0378e0e
(jump-to-register): Allow file name "in" a register.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
96 (find-file (cdr val))) |
2202
081afcef5e85
Make frame configurations start with a distinctive symbol.
Jim Blandy <jimb@redhat.com>
parents:
1955
diff
changeset
|
97 (t |
081afcef5e85
Make frame configurations start with a distinctive symbol.
Jim Blandy <jimb@redhat.com>
parents:
1955
diff
changeset
|
98 (error "Register doesn't contain a buffer position or configuration"))))) |
47 | 99 |
100 ;(defun number-to-register (arg char) | |
101 ; "Store a number in a register. | |
102 ;Two args, NUMBER and REGISTER (a character, naming the register). | |
103 ;If NUMBER is nil, digits in the buffer following point are read | |
104 ;to get the number to store. | |
105 ;Interactively, NUMBER is the prefix arg (none means nil)." | |
106 ; (interactive "P\ncNumber to register: ") | |
107 ; (set-register char | |
108 ; (if arg | |
109 ; (prefix-numeric-value arg) | |
110 ; (if (looking-at "[0-9][0-9]*") | |
111 ; (save-excursion | |
112 ; (save-restriction | |
113 ; (narrow-to-region (point) | |
114 ; (progn (skip-chars-forward "0-9") | |
115 ; (point))) | |
116 ; (goto-char (point-min)) | |
117 ; (read (current-buffer)))) | |
118 ; 0)))) | |
119 | |
120 ;(defun increment-register (arg char) | |
121 ; "Add NUMBER to the contents of register REGISTER. | |
122 ;Interactively, NUMBER is the prefix arg (none means nil)." | |
123 ; (interactive "p\ncNumber to register: ") | |
124 ; (or (integerp (get-register char)) | |
125 ; (error "Register does not contain a number")) | |
126 ; (set-register char (+ arg (get-register char)))) | |
127 | |
128 (defun view-register (char) | |
129 "Display what is contained in register named REGISTER. | |
130 REGISTER is a character." | |
131 (interactive "cView register: ") | |
132 (let ((val (get-register char))) | |
133 (if (null val) | |
134 (message "Register %s is empty" (single-key-description char)) | |
135 (with-output-to-temp-buffer "*Output*" | |
136 (princ "Register ") | |
137 (princ (single-key-description char)) | |
138 (princ " contains ") | |
2203
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
139 (cond |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
140 ((integerp val) |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
141 (princ val)) |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
142 |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
143 ((markerp val) |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
144 (princ "a buffer position:\nbuffer ") |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
145 (princ (buffer-name (marker-buffer val))) |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
146 (princ ", position ") |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
147 (princ (+ 0 val))) |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
148 |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
149 ((window-configuration-p val) |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
150 (princ "a window configuration.")) |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
151 |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
152 ((frame-configuration-p val) |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
153 (princ "a frame configuration.")) |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
154 |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
155 ((consp val) |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
156 (princ "the rectangle:\n") |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
157 (while val |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
158 (princ (car val)) |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
159 (terpri) |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
160 (setq val (cdr val)))) |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
161 |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
162 ((stringp val) |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
163 (princ "the text:\n") |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
164 (princ val)) |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
165 |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
166 (t |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
167 (princ "Garbage:\n") |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
168 (prin1 val))))))) |
47 | 169 |
170 (defun insert-register (char &optional arg) | |
171 "Insert contents of register REG. REG is a character. | |
172 Normally puts point before and mark after the inserted text. | |
173 If optional second arg is non-nil, puts mark before and point after. | |
174 Interactively, second arg is non-nil if prefix arg is supplied." | |
175 (interactive "cInsert register: \nP") | |
176 (push-mark) | |
177 (let ((val (get-register char))) | |
178 (if (consp val) | |
179 (insert-rectangle val) | |
180 (if (stringp val) | |
181 (insert val) | |
182 (if (or (integerp val) (markerp val)) | |
183 (princ (+ 0 val) (current-buffer)) | |
184 (error "Register does not contain text"))))) | |
185 (if (not arg) (exchange-point-and-mark))) | |
186 | |
187 (defun copy-to-register (char start end &optional delete-flag) | |
243 | 188 "Copy region into register REG. With prefix arg, delete as well. |
189 Called from program, takes four args: REG, START, END and DELETE-FLAG. | |
47 | 190 START and END are buffer positions indicating what to copy." |
191 (interactive "cCopy to register: \nr\nP") | |
192 (set-register char (buffer-substring start end)) | |
193 (if delete-flag (delete-region start end))) | |
194 | |
195 (defun append-to-register (char start end &optional delete-flag) | |
243 | 196 "Append region to text in register REG. With prefix arg, delete as well. |
197 Called from program, takes four args: REG, START, END and DELETE-FLAG. | |
47 | 198 START and END are buffer positions indicating what to append." |
199 (interactive "cAppend to register: \nr\nP") | |
200 (or (stringp (get-register char)) | |
201 (error "Register does not contain text")) | |
202 (set-register char (concat (get-register char) | |
203 (buffer-substring start end))) | |
204 (if delete-flag (delete-region start end))) | |
205 | |
206 (defun prepend-to-register (char start end &optional delete-flag) | |
243 | 207 "Prepend region to text in register REG. With prefix arg, delete as well. |
208 Called from program, takes four args: REG, START, END and DELETE-FLAG. | |
47 | 209 START and END are buffer positions indicating what to prepend." |
210 (interactive "cPrepend to register: \nr\nP") | |
211 (or (stringp (get-register char)) | |
212 (error "Register does not contain text")) | |
213 (set-register char (concat (buffer-substring start end) | |
214 (get-register char))) | |
215 (if delete-flag (delete-region start end))) | |
216 | |
217 (defun copy-rectangle-to-register (char start end &optional delete-flag) | |
243 | 218 "Copy rectangular region into register REG. With prefix arg, delete as well. |
219 Called from program, takes four args: REG, START, END and DELETE-FLAG. | |
47 | 220 START and END are buffer positions giving two corners of rectangle." |
221 (interactive "cCopy rectangle to register: \nr\nP") | |
222 (set-register char | |
223 (if delete-flag | |
224 (delete-extract-rectangle start end) | |
225 (extract-rectangle start end)))) | |
658
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
243
diff
changeset
|
226 |
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
243
diff
changeset
|
227 ;;; register.el ends here |