Mercurial > emacs
comparison lisp/register.el @ 47:dfec464ac265
Initial revision
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 06 Feb 1990 22:29:40 +0000 |
parents | |
children | 21f566443ad1 |
comparison
equal
deleted
inserted
replaced
46:ca2ddc6f6950 | 47:dfec464ac265 |
---|---|
1 ;; Register commands for Emacs. | |
2 ;; Copyright (C) 1985 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 (defvar register-alist nil | |
22 "Alist of elements (NAME . CONTENTS), one for each Emacs register. | |
23 NAME is a character (a number). CONTENTS is a string, number, | |
24 mark or list. A list represents a rectangle; its elements are strings.") | |
25 | |
26 (defun get-register (char) | |
27 "Return contents of Emacs register named CHAR, or nil if none." | |
28 (cdr (assq char register-alist))) | |
29 | |
30 (defun set-register (char value) | |
31 "Set contents of Emacs register named CHAR to VALUE. | |
32 Returns VALUE." | |
33 (let ((aelt (assq char register-alist))) | |
34 (if aelt | |
35 (setcdr aelt value) | |
36 (setq aelt (cons char value)) | |
37 (setq register-alist (cons aelt register-alist))) | |
38 value)) | |
39 | |
40 (defun point-to-register (char) | |
41 "Store current location of point in a register. | |
42 Argument is a character, naming the register." | |
43 (interactive "cPoint to register: ") | |
44 (set-register char (point-marker))) | |
45 | |
46 (fset 'register-to-point 'jump-to-register) | |
47 (defun jump-to-register (char) | |
48 "Move point to location stored in a register. | |
49 Argument is a character, naming the register." | |
50 (interactive "cJump to register: ") | |
51 (let ((val (get-register char))) | |
52 (if (markerp val) | |
53 (progn | |
54 (switch-to-buffer (marker-buffer val)) | |
55 (goto-char val)) | |
56 (error "Register doesn't contain a buffer position")))) | |
57 | |
58 ;(defun number-to-register (arg char) | |
59 ; "Store a number in a register. | |
60 ;Two args, NUMBER and REGISTER (a character, naming the register). | |
61 ;If NUMBER is nil, digits in the buffer following point are read | |
62 ;to get the number to store. | |
63 ;Interactively, NUMBER is the prefix arg (none means nil)." | |
64 ; (interactive "P\ncNumber to register: ") | |
65 ; (set-register char | |
66 ; (if arg | |
67 ; (prefix-numeric-value arg) | |
68 ; (if (looking-at "[0-9][0-9]*") | |
69 ; (save-excursion | |
70 ; (save-restriction | |
71 ; (narrow-to-region (point) | |
72 ; (progn (skip-chars-forward "0-9") | |
73 ; (point))) | |
74 ; (goto-char (point-min)) | |
75 ; (read (current-buffer)))) | |
76 ; 0)))) | |
77 | |
78 ;(defun increment-register (arg char) | |
79 ; "Add NUMBER to the contents of register REGISTER. | |
80 ;Interactively, NUMBER is the prefix arg (none means nil)." | |
81 ; (interactive "p\ncNumber to register: ") | |
82 ; (or (integerp (get-register char)) | |
83 ; (error "Register does not contain a number")) | |
84 ; (set-register char (+ arg (get-register char)))) | |
85 | |
86 (defun view-register (char) | |
87 "Display what is contained in register named REGISTER. | |
88 REGISTER is a character." | |
89 (interactive "cView register: ") | |
90 (let ((val (get-register char))) | |
91 (if (null val) | |
92 (message "Register %s is empty" (single-key-description char)) | |
93 (with-output-to-temp-buffer "*Output*" | |
94 (princ "Register ") | |
95 (princ (single-key-description char)) | |
96 (princ " contains ") | |
97 (if (integerp val) | |
98 (princ val) | |
99 (if (markerp val) | |
100 (progn | |
101 (princ "a buffer position:\nbuffer ") | |
102 (princ (buffer-name (marker-buffer val))) | |
103 (princ ", position ") | |
104 (princ (+ 0 val))) | |
105 (if (consp val) | |
106 (progn | |
107 (princ "the rectangle:\n") | |
108 (setq val (cdr val)) | |
109 (while val | |
110 (princ (car val)) | |
111 (terpri) | |
112 (setq val (cdr val)))) | |
113 (princ "the string:\n") | |
114 (princ val)))))))) | |
115 | |
116 (defun insert-register (char &optional arg) | |
117 "Insert contents of register REG. REG is a character. | |
118 Normally puts point before and mark after the inserted text. | |
119 If optional second arg is non-nil, puts mark before and point after. | |
120 Interactively, second arg is non-nil if prefix arg is supplied." | |
121 (interactive "cInsert register: \nP") | |
122 (push-mark) | |
123 (let ((val (get-register char))) | |
124 (if (consp val) | |
125 (insert-rectangle val) | |
126 (if (stringp val) | |
127 (insert val) | |
128 (if (or (integerp val) (markerp val)) | |
129 (princ (+ 0 val) (current-buffer)) | |
130 (error "Register does not contain text"))))) | |
131 (if (not arg) (exchange-point-and-mark))) | |
132 | |
133 (defun copy-to-register (char start end &optional delete-flag) | |
134 "Copy region into register REG. | |
135 With prefix arg, delete as well. | |
136 Called from program, takes four args: | |
137 REG, START, END and DELETE-FLAG. | |
138 START and END are buffer positions indicating what to copy." | |
139 (interactive "cCopy to register: \nr\nP") | |
140 (set-register char (buffer-substring start end)) | |
141 (if delete-flag (delete-region start end))) | |
142 | |
143 (defun append-to-register (char start end &optional delete-flag) | |
144 "Append region to text in register REG. | |
145 With prefix arg, delete as well. | |
146 Called from program, takes four args: | |
147 REG, START, END and DELETE-FLAG. | |
148 START and END are buffer positions indicating what to append." | |
149 (interactive "cAppend to register: \nr\nP") | |
150 (or (stringp (get-register char)) | |
151 (error "Register does not contain text")) | |
152 (set-register char (concat (get-register char) | |
153 (buffer-substring start end))) | |
154 (if delete-flag (delete-region start end))) | |
155 | |
156 (defun prepend-to-register (char start end &optional delete-flag) | |
157 "Prepend region to text in register REG. | |
158 With prefix arg, delete as well. | |
159 Called from program, takes four args: | |
160 REG, START, END and DELETE-FLAG. | |
161 START and END are buffer positions indicating what to prepend." | |
162 (interactive "cPrepend to register: \nr\nP") | |
163 (or (stringp (get-register char)) | |
164 (error "Register does not contain text")) | |
165 (set-register char (concat (buffer-substring start end) | |
166 (get-register char))) | |
167 (if delete-flag (delete-region start end))) | |
168 | |
169 (defun copy-rectangle-to-register (char start end &optional delete-flag) | |
170 "Copy rectangular region into register REG. | |
171 With prefix arg, delete as well. | |
172 Called from program, takes four args: | |
173 REG, START, END and DELETE-FLAG. | |
174 START and END are buffer positions giving two corners of rectangle." | |
175 (interactive "cCopy rectangle to register: \nr\nP") | |
176 (set-register char | |
177 (if delete-flag | |
178 (delete-extract-rectangle start end) | |
179 (extract-rectangle start end)))) |