Mercurial > emacs
annotate lisp/register.el @ 2262:29579cd51981
Added unlock and relock.
author | Eric S. Raymond <esr@snark.thyrsus.com> |
---|---|
date | Fri, 19 Mar 1993 07:49:20 +0000 |
parents | 12e9bc8a4a7f |
children | 9e7ec92a4fdf |
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 | |
789
71d052f72ac1
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
779
diff
changeset
|
24 ;;; Code: |
47 | 25 |
26 (defvar register-alist nil | |
27 "Alist of elements (NAME . CONTENTS), one for each Emacs register. | |
28 NAME is a character (a number). CONTENTS is a string, number, | |
779 | 29 frame configuration, mark or list. |
141 | 30 A list represents a rectangle; its elements are strings.") |
47 | 31 |
32 (defun get-register (char) | |
33 "Return contents of Emacs register named CHAR, or nil if none." | |
34 (cdr (assq char register-alist))) | |
35 | |
36 (defun set-register (char value) | |
243 | 37 "Set contents of Emacs register named CHAR to VALUE. Returns VALUE." |
47 | 38 (let ((aelt (assq char register-alist))) |
39 (if aelt | |
40 (setcdr aelt value) | |
41 (setq aelt (cons char value)) | |
42 (setq register-alist (cons aelt register-alist))) | |
43 value)) | |
44 | |
1955
8ac912d2d369
(point-to-register): Make arg ARG optional.
Richard M. Stallman <rms@gnu.org>
parents:
845
diff
changeset
|
45 (defun point-to-register (char &optional arg) |
141 | 46 "Store current location of point in register REGISTER. |
779 | 47 With prefix argument, store current frame configuration. |
141 | 48 Use \\[jump-to-register] to go to that location or restore that configuration. |
47 | 49 Argument is a character, naming the register." |
141 | 50 (interactive "cPoint to register: \nP") |
779 | 51 (set-register char (if arg (current-frame-configuration) (point-marker)))) |
47 | 52 |
1955
8ac912d2d369
(point-to-register): Make arg ARG optional.
Richard M. Stallman <rms@gnu.org>
parents:
845
diff
changeset
|
53 (defun window-configuration-to-register (char &optional arg) |
820
cd6b1e1da3fc
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
814
diff
changeset
|
54 "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
|
55 Use \\[jump-to-register] to restore the configuration. |
cd6b1e1da3fc
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
814
diff
changeset
|
56 Argument is a character, naming the register." |
cd6b1e1da3fc
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
814
diff
changeset
|
57 (interactive "cPoint to register: \nP") |
cd6b1e1da3fc
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
814
diff
changeset
|
58 (set-register char (current-window-configuration))) |
cd6b1e1da3fc
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
814
diff
changeset
|
59 |
1955
8ac912d2d369
(point-to-register): Make arg ARG optional.
Richard M. Stallman <rms@gnu.org>
parents:
845
diff
changeset
|
60 (defun frame-configuration-to-register (char &optional arg) |
820
cd6b1e1da3fc
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
814
diff
changeset
|
61 "Store the window configuration of all frames in register REGISTER. |
cd6b1e1da3fc
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
814
diff
changeset
|
62 Use \\[jump-to-register] to restore the configuration. |
cd6b1e1da3fc
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
814
diff
changeset
|
63 Argument is a character, naming the register." |
cd6b1e1da3fc
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
814
diff
changeset
|
64 (interactive "cPoint to register: \nP") |
cd6b1e1da3fc
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
814
diff
changeset
|
65 (set-register char (current-frame-configuration))) |
cd6b1e1da3fc
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
814
diff
changeset
|
66 |
47 | 67 (fset 'register-to-point 'jump-to-register) |
68 (defun jump-to-register (char) | |
69 "Move point to location stored in a register. | |
820
cd6b1e1da3fc
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
814
diff
changeset
|
70 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
|
71 configuration (all frames), restore that frame or all frames accordingly. |
47 | 72 Argument is a character, naming the register." |
73 (interactive "cJump to register: ") | |
74 (let ((val (get-register char))) | |
2202
081afcef5e85
Make frame configurations start with a distinctive symbol.
Jim Blandy <jimb@redhat.com>
parents:
1955
diff
changeset
|
75 (cond |
081afcef5e85
Make frame configurations start with a distinctive symbol.
Jim Blandy <jimb@redhat.com>
parents:
1955
diff
changeset
|
76 ((frame-configuration-p val) |
081afcef5e85
Make frame configurations start with a distinctive symbol.
Jim Blandy <jimb@redhat.com>
parents:
1955
diff
changeset
|
77 (set-frame-configuration val)) |
081afcef5e85
Make frame configurations start with a distinctive symbol.
Jim Blandy <jimb@redhat.com>
parents:
1955
diff
changeset
|
78 ((window-configuration-p val) |
081afcef5e85
Make frame configurations start with a distinctive symbol.
Jim Blandy <jimb@redhat.com>
parents:
1955
diff
changeset
|
79 (set-window-configuration val)) |
081afcef5e85
Make frame configurations start with a distinctive symbol.
Jim Blandy <jimb@redhat.com>
parents:
1955
diff
changeset
|
80 ((markerp val) |
081afcef5e85
Make frame configurations start with a distinctive symbol.
Jim Blandy <jimb@redhat.com>
parents:
1955
diff
changeset
|
81 (switch-to-buffer (marker-buffer val)) |
081afcef5e85
Make frame configurations start with a distinctive symbol.
Jim Blandy <jimb@redhat.com>
parents:
1955
diff
changeset
|
82 (goto-char val)) |
081afcef5e85
Make frame configurations start with a distinctive symbol.
Jim Blandy <jimb@redhat.com>
parents:
1955
diff
changeset
|
83 (t |
081afcef5e85
Make frame configurations start with a distinctive symbol.
Jim Blandy <jimb@redhat.com>
parents:
1955
diff
changeset
|
84 (error "Register doesn't contain a buffer position or configuration"))))) |
47 | 85 |
86 ;(defun number-to-register (arg char) | |
87 ; "Store a number in a register. | |
88 ;Two args, NUMBER and REGISTER (a character, naming the register). | |
89 ;If NUMBER is nil, digits in the buffer following point are read | |
90 ;to get the number to store. | |
91 ;Interactively, NUMBER is the prefix arg (none means nil)." | |
92 ; (interactive "P\ncNumber to register: ") | |
93 ; (set-register char | |
94 ; (if arg | |
95 ; (prefix-numeric-value arg) | |
96 ; (if (looking-at "[0-9][0-9]*") | |
97 ; (save-excursion | |
98 ; (save-restriction | |
99 ; (narrow-to-region (point) | |
100 ; (progn (skip-chars-forward "0-9") | |
101 ; (point))) | |
102 ; (goto-char (point-min)) | |
103 ; (read (current-buffer)))) | |
104 ; 0)))) | |
105 | |
106 ;(defun increment-register (arg char) | |
107 ; "Add NUMBER to the contents of register REGISTER. | |
108 ;Interactively, NUMBER is the prefix arg (none means nil)." | |
109 ; (interactive "p\ncNumber to register: ") | |
110 ; (or (integerp (get-register char)) | |
111 ; (error "Register does not contain a number")) | |
112 ; (set-register char (+ arg (get-register char)))) | |
113 | |
114 (defun view-register (char) | |
115 "Display what is contained in register named REGISTER. | |
116 REGISTER is a character." | |
117 (interactive "cView register: ") | |
118 (let ((val (get-register char))) | |
119 (if (null val) | |
120 (message "Register %s is empty" (single-key-description char)) | |
121 (with-output-to-temp-buffer "*Output*" | |
122 (princ "Register ") | |
123 (princ (single-key-description char)) | |
124 (princ " contains ") | |
2203
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
125 (cond |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
126 ((integerp val) |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
127 (princ val)) |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
128 |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
129 ((markerp val) |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
130 (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
|
131 (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
|
132 (princ ", position ") |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
133 (princ (+ 0 val))) |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
134 |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
135 ((window-configuration-p val) |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
136 (princ "a window configuration.")) |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
137 |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
138 ((frame-configuration-p val) |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
139 (princ "a frame configuration.")) |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
140 |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
141 ((consp val) |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
142 (princ "the rectangle:\n") |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
143 (while val |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
144 (princ (car val)) |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
145 (terpri) |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
146 (setq val (cdr val)))) |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
147 |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
148 ((stringp val) |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
149 (princ "the text:\n") |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
150 (princ val)) |
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 (t |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
153 (princ "Garbage:\n") |
12e9bc8a4a7f
* register.el (view-register): Neglect not to avoid failing to
Jim Blandy <jimb@redhat.com>
parents:
2202
diff
changeset
|
154 (prin1 val))))))) |
47 | 155 |
156 (defun insert-register (char &optional arg) | |
157 "Insert contents of register REG. REG is a character. | |
158 Normally puts point before and mark after the inserted text. | |
159 If optional second arg is non-nil, puts mark before and point after. | |
160 Interactively, second arg is non-nil if prefix arg is supplied." | |
161 (interactive "cInsert register: \nP") | |
162 (push-mark) | |
163 (let ((val (get-register char))) | |
164 (if (consp val) | |
165 (insert-rectangle val) | |
166 (if (stringp val) | |
167 (insert val) | |
168 (if (or (integerp val) (markerp val)) | |
169 (princ (+ 0 val) (current-buffer)) | |
170 (error "Register does not contain text"))))) | |
171 (if (not arg) (exchange-point-and-mark))) | |
172 | |
173 (defun copy-to-register (char start end &optional delete-flag) | |
243 | 174 "Copy region into register REG. With prefix arg, delete as well. |
175 Called from program, takes four args: REG, START, END and DELETE-FLAG. | |
47 | 176 START and END are buffer positions indicating what to copy." |
177 (interactive "cCopy to register: \nr\nP") | |
178 (set-register char (buffer-substring start end)) | |
179 (if delete-flag (delete-region start end))) | |
180 | |
181 (defun append-to-register (char start end &optional delete-flag) | |
243 | 182 "Append region to text in register REG. With prefix arg, delete as well. |
183 Called from program, takes four args: REG, START, END and DELETE-FLAG. | |
47 | 184 START and END are buffer positions indicating what to append." |
185 (interactive "cAppend to register: \nr\nP") | |
186 (or (stringp (get-register char)) | |
187 (error "Register does not contain text")) | |
188 (set-register char (concat (get-register char) | |
189 (buffer-substring start end))) | |
190 (if delete-flag (delete-region start end))) | |
191 | |
192 (defun prepend-to-register (char start end &optional delete-flag) | |
243 | 193 "Prepend region to text in register REG. With prefix arg, delete as well. |
194 Called from program, takes four args: REG, START, END and DELETE-FLAG. | |
47 | 195 START and END are buffer positions indicating what to prepend." |
196 (interactive "cPrepend to register: \nr\nP") | |
197 (or (stringp (get-register char)) | |
198 (error "Register does not contain text")) | |
199 (set-register char (concat (buffer-substring start end) | |
200 (get-register char))) | |
201 (if delete-flag (delete-region start end))) | |
202 | |
203 (defun copy-rectangle-to-register (char start end &optional delete-flag) | |
243 | 204 "Copy rectangular region into register REG. With prefix arg, delete as well. |
205 Called from program, takes four args: REG, START, END and DELETE-FLAG. | |
47 | 206 START and END are buffer positions giving two corners of rectangle." |
207 (interactive "cCopy rectangle to register: \nr\nP") | |
208 (set-register char | |
209 (if delete-flag | |
210 (delete-extract-rectangle start end) | |
211 (extract-rectangle start end)))) | |
658
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
243
diff
changeset
|
212 |
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
243
diff
changeset
|
213 ;;; register.el ends here |