1 ;;; register.el --- register commands for Emacs.
4 ;; Last-Modified: 09 Jul 1992
7 ;; Copyright (C) 1985 Free Software Foundation, Inc.
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
27 (defvar register-alist nil
28 "Alist of elements (NAME . CONTENTS), one for each Emacs register.
29 NAME is a character (a number). CONTENTS is a string, number,
30 frame configuration, mark or list.
31 A list represents a rectangle; its elements are strings.")
33 (defun get-register (char)
34 "Return contents of Emacs register named CHAR, or nil if none."
35 (cdr (assq char register-alist
)))
37 (defun set-register (char value
)
38 "Set contents of Emacs register named CHAR to VALUE. Returns VALUE."
39 (let ((aelt (assq char register-alist
)))
42 (setq aelt
(cons char value
))
43 (setq register-alist
(cons aelt register-alist
)))
46 (defun point-to-register (char arg
)
47 "Store current location of point in register REGISTER.
48 With prefix argument, store current frame configuration.
49 Use \\[jump-to-register] to go to that location or restore that configuration.
50 Argument is a character, naming the register."
51 (interactive "cPoint to register: \nP")
52 (set-register char
(if arg
(current-frame-configuration) (point-marker))))
54 (defun window-configuration-to-register (char arg
)
55 "Store the window configuration of the selected frame in register REGISTER.
56 Use \\[jump-to-register] to restore the configuration.
57 Argument is a character, naming the register."
58 (interactive "cPoint to register: \nP")
59 (set-register char
(current-window-configuration)))
61 (defun frame-configuration-to-register (char arg
)
62 "Store the window configuration of all frames in register REGISTER.
63 Use \\[jump-to-register] to restore the configuration.
64 Argument is a character, naming the register."
65 (interactive "cPoint to register: \nP")
66 (set-register char
(current-frame-configuration)))
68 (fset 'register-to-point
'jump-to-register
)
69 (defun jump-to-register (char)
70 "Move point to location stored in a register.
71 If the register contains a window configuration (one frame) or a frame
72 configuration (all frames), restore that frame or all frames accordingly.
73 Argument is a character, naming the register."
74 (interactive "cJump to register: ")
75 (let ((val (get-register char
)))
77 (set-frame-configuration val
)
79 (if (window-configuration-p val
)
80 (set-window-configuration val
)
83 (switch-to-buffer (marker-buffer val
))
85 (error "Register doesn't contain a buffer position or configuration")))))))
87 ;(defun number-to-register (arg char)
88 ; "Store a number in a register.
89 ;Two args, NUMBER and REGISTER (a character, naming the register).
90 ;If NUMBER is nil, digits in the buffer following point are read
91 ;to get the number to store.
92 ;Interactively, NUMBER is the prefix arg (none means nil)."
93 ; (interactive "P\ncNumber to register: ")
96 ; (prefix-numeric-value arg)
97 ; (if (looking-at "[0-9][0-9]*")
100 ; (narrow-to-region (point)
101 ; (progn (skip-chars-forward "0-9")
103 ; (goto-char (point-min))
104 ; (read (current-buffer))))
107 ;(defun increment-register (arg char)
108 ; "Add NUMBER to the contents of register REGISTER.
109 ;Interactively, NUMBER is the prefix arg (none means nil)."
110 ; (interactive "p\ncNumber to register: ")
111 ; (or (integerp (get-register char))
112 ; (error "Register does not contain a number"))
113 ; (set-register char (+ arg (get-register char))))
115 (defun view-register (char)
116 "Display what is contained in register named REGISTER.
117 REGISTER is a character."
118 (interactive "cView register: ")
119 (let ((val (get-register char
)))
121 (message "Register %s is empty" (single-key-description char
))
122 (with-output-to-temp-buffer "*Output*"
124 (princ (single-key-description char
))
130 (princ "a buffer position:\nbuffer ")
131 (princ (buffer-name (marker-buffer val
)))
132 (princ ", position ")
136 (princ "the rectangle:\n")
140 (setq val
(cdr val
))))
141 (princ "the string:\n")
144 (defun insert-register (char &optional arg
)
145 "Insert contents of register REG. REG is a character.
146 Normally puts point before and mark after the inserted text.
147 If optional second arg is non-nil, puts mark before and point after.
148 Interactively, second arg is non-nil if prefix arg is supplied."
149 (interactive "cInsert register: \nP")
151 (let ((val (get-register char
)))
153 (insert-rectangle val
)
156 (if (or (integerp val
) (markerp val
))
157 (princ (+ 0 val
) (current-buffer))
158 (error "Register does not contain text")))))
159 (if (not arg
) (exchange-point-and-mark)))
161 (defun copy-to-register (char start end
&optional delete-flag
)
162 "Copy region into register REG. With prefix arg, delete as well.
163 Called from program, takes four args: REG, START, END and DELETE-FLAG.
164 START and END are buffer positions indicating what to copy."
165 (interactive "cCopy to register: \nr\nP")
166 (set-register char
(buffer-substring start end
))
167 (if delete-flag
(delete-region start end
)))
169 (defun append-to-register (char start end
&optional delete-flag
)
170 "Append region to text in register REG. With prefix arg, delete as well.
171 Called from program, takes four args: REG, START, END and DELETE-FLAG.
172 START and END are buffer positions indicating what to append."
173 (interactive "cAppend to register: \nr\nP")
174 (or (stringp (get-register char
))
175 (error "Register does not contain text"))
176 (set-register char
(concat (get-register char
)
177 (buffer-substring start end
)))
178 (if delete-flag
(delete-region start end
)))
180 (defun prepend-to-register (char start end
&optional delete-flag
)
181 "Prepend region to text in register REG. With prefix arg, delete as well.
182 Called from program, takes four args: REG, START, END and DELETE-FLAG.
183 START and END are buffer positions indicating what to prepend."
184 (interactive "cPrepend to register: \nr\nP")
185 (or (stringp (get-register char
))
186 (error "Register does not contain text"))
187 (set-register char
(concat (buffer-substring start end
)
188 (get-register char
)))
189 (if delete-flag
(delete-region start end
)))
191 (defun copy-rectangle-to-register (char start end
&optional delete-flag
)
192 "Copy rectangular region into register REG. With prefix arg, delete as well.
193 Called from program, takes four args: REG, START, END and DELETE-FLAG.
194 START and END are buffer positions giving two corners of rectangle."
195 (interactive "cCopy rectangle to register: \nr\nP")
198 (delete-extract-rectangle start end
)
199 (extract-rectangle start end
))))
201 ;;; register.el ends here