Mercurial > emacs
annotate lisp/register.el @ 658:7cbd4fcd8b0f
*** empty log message ***
author | Eric S. Raymond <esr@snark.thyrsus.com> |
---|---|
date | Sat, 30 May 1992 21:11:25 +0000 |
parents | 6155e428f077 |
children | c2dbf1fe0506 |
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 |
47 | 3 ;; Copyright (C) 1985 Free Software Foundation, Inc. |
4 | |
5 ;; This file is part of GNU Emacs. | |
6 | |
7 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
8 ;; it under the terms of the GNU General Public License as published by | |
9 ;; the Free Software Foundation; either version 1, or (at your option) | |
10 ;; any later version. | |
11 | |
12 ;; GNU Emacs is distributed in the hope that it will be useful, | |
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 ;; GNU General Public License for more details. | |
16 | |
17 ;; You should have received a copy of the GNU General Public License | |
18 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
19 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
20 | |
21 | |
22 (defvar register-alist nil | |
23 "Alist of elements (NAME . CONTENTS), one for each Emacs register. | |
24 NAME is a character (a number). CONTENTS is a string, number, | |
141 | 25 screen configuration, mark or list. |
26 A list represents a rectangle; its elements are strings.") | |
47 | 27 |
28 (defun get-register (char) | |
29 "Return contents of Emacs register named CHAR, or nil if none." | |
30 (cdr (assq char register-alist))) | |
31 | |
32 (defun set-register (char value) | |
243 | 33 "Set contents of Emacs register named CHAR to VALUE. Returns VALUE." |
47 | 34 (let ((aelt (assq char register-alist))) |
35 (if aelt | |
36 (setcdr aelt value) | |
37 (setq aelt (cons char value)) | |
38 (setq register-alist (cons aelt register-alist))) | |
39 value)) | |
40 | |
141 | 41 (defun point-to-register (char arg) |
42 "Store current location of point in register REGISTER. | |
43 With prefix argument, store current screen configuration. | |
44 Use \\[jump-to-register] to go to that location or restore that configuration. | |
47 | 45 Argument is a character, naming the register." |
141 | 46 (interactive "cPoint to register: \nP") |
47 (set-register char (if arg (current-screen-configuration) (point-marker)))) | |
47 | 48 |
49 (fset 'register-to-point 'jump-to-register) | |
50 (defun jump-to-register (char) | |
51 "Move point to location stored in a register. | |
52 Argument is a character, naming the register." | |
53 (interactive "cJump to register: ") | |
54 (let ((val (get-register char))) | |
141 | 55 (condition-case () |
56 (set-screen-configuration val) | |
57 (error | |
58 (if (markerp val) | |
59 (progn | |
60 (switch-to-buffer (marker-buffer val)) | |
61 (goto-char val)) | |
151 | 62 (error "Register doesn't contain a buffer position or screen configuration")))))) |
47 | 63 |
64 ;(defun number-to-register (arg char) | |
65 ; "Store a number in a register. | |
66 ;Two args, NUMBER and REGISTER (a character, naming the register). | |
67 ;If NUMBER is nil, digits in the buffer following point are read | |
68 ;to get the number to store. | |
69 ;Interactively, NUMBER is the prefix arg (none means nil)." | |
70 ; (interactive "P\ncNumber to register: ") | |
71 ; (set-register char | |
72 ; (if arg | |
73 ; (prefix-numeric-value arg) | |
74 ; (if (looking-at "[0-9][0-9]*") | |
75 ; (save-excursion | |
76 ; (save-restriction | |
77 ; (narrow-to-region (point) | |
78 ; (progn (skip-chars-forward "0-9") | |
79 ; (point))) | |
80 ; (goto-char (point-min)) | |
81 ; (read (current-buffer)))) | |
82 ; 0)))) | |
83 | |
84 ;(defun increment-register (arg char) | |
85 ; "Add NUMBER to the contents of register REGISTER. | |
86 ;Interactively, NUMBER is the prefix arg (none means nil)." | |
87 ; (interactive "p\ncNumber to register: ") | |
88 ; (or (integerp (get-register char)) | |
89 ; (error "Register does not contain a number")) | |
90 ; (set-register char (+ arg (get-register char)))) | |
91 | |
92 (defun view-register (char) | |
93 "Display what is contained in register named REGISTER. | |
94 REGISTER is a character." | |
95 (interactive "cView register: ") | |
96 (let ((val (get-register char))) | |
97 (if (null val) | |
98 (message "Register %s is empty" (single-key-description char)) | |
99 (with-output-to-temp-buffer "*Output*" | |
100 (princ "Register ") | |
101 (princ (single-key-description char)) | |
102 (princ " contains ") | |
103 (if (integerp val) | |
104 (princ val) | |
105 (if (markerp val) | |
106 (progn | |
107 (princ "a buffer position:\nbuffer ") | |
108 (princ (buffer-name (marker-buffer val))) | |
109 (princ ", position ") | |
110 (princ (+ 0 val))) | |
111 (if (consp val) | |
112 (progn | |
113 (princ "the rectangle:\n") | |
114 (while val | |
115 (princ (car val)) | |
116 (terpri) | |
117 (setq val (cdr val)))) | |
118 (princ "the string:\n") | |
119 (princ val)))))))) | |
120 | |
121 (defun insert-register (char &optional arg) | |
122 "Insert contents of register REG. REG is a character. | |
123 Normally puts point before and mark after the inserted text. | |
124 If optional second arg is non-nil, puts mark before and point after. | |
125 Interactively, second arg is non-nil if prefix arg is supplied." | |
126 (interactive "cInsert register: \nP") | |
127 (push-mark) | |
128 (let ((val (get-register char))) | |
129 (if (consp val) | |
130 (insert-rectangle val) | |
131 (if (stringp val) | |
132 (insert val) | |
133 (if (or (integerp val) (markerp val)) | |
134 (princ (+ 0 val) (current-buffer)) | |
135 (error "Register does not contain text"))))) | |
136 (if (not arg) (exchange-point-and-mark))) | |
137 | |
138 (defun copy-to-register (char start end &optional delete-flag) | |
243 | 139 "Copy region into register REG. With prefix arg, delete as well. |
140 Called from program, takes four args: REG, START, END and DELETE-FLAG. | |
47 | 141 START and END are buffer positions indicating what to copy." |
142 (interactive "cCopy to register: \nr\nP") | |
143 (set-register char (buffer-substring start end)) | |
144 (if delete-flag (delete-region start end))) | |
145 | |
146 (defun append-to-register (char start end &optional delete-flag) | |
243 | 147 "Append region to text in register REG. With prefix arg, delete as well. |
148 Called from program, takes four args: REG, START, END and DELETE-FLAG. | |
47 | 149 START and END are buffer positions indicating what to append." |
150 (interactive "cAppend to register: \nr\nP") | |
151 (or (stringp (get-register char)) | |
152 (error "Register does not contain text")) | |
153 (set-register char (concat (get-register char) | |
154 (buffer-substring start end))) | |
155 (if delete-flag (delete-region start end))) | |
156 | |
157 (defun prepend-to-register (char start end &optional delete-flag) | |
243 | 158 "Prepend region to text in register REG. With prefix arg, delete as well. |
159 Called from program, takes four args: REG, START, END and DELETE-FLAG. | |
47 | 160 START and END are buffer positions indicating what to prepend." |
161 (interactive "cPrepend to register: \nr\nP") | |
162 (or (stringp (get-register char)) | |
163 (error "Register does not contain text")) | |
164 (set-register char (concat (buffer-substring start end) | |
165 (get-register char))) | |
166 (if delete-flag (delete-region start end))) | |
167 | |
168 (defun copy-rectangle-to-register (char start end &optional delete-flag) | |
243 | 169 "Copy rectangular region into register REG. With prefix arg, delete as well. |
170 Called from program, takes four args: REG, START, END and DELETE-FLAG. | |
47 | 171 START and END are buffer positions giving two corners of rectangle." |
172 (interactive "cCopy rectangle to register: \nr\nP") | |
173 (set-register char | |
174 (if delete-flag | |
175 (delete-extract-rectangle start end) | |
176 (extract-rectangle start end)))) | |
658
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
243
diff
changeset
|
177 |
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
243
diff
changeset
|
178 ;;; register.el ends here |