1 ;;; register.el --- register commands for Emacs.
3 ;; Copyright (C) 1985 Free Software Foundation, Inc.
5 ;; This file is part of GNU Emacs.
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)
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.
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.
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,
25 screen configuration, mark or list.
26 A list represents a rectangle; its elements are strings.")
28 (defun get-register (char)
29 "Return contents of Emacs register named CHAR, or nil if none."
30 (cdr (assq char register-alist
)))
32 (defun set-register (char value
)
33 "Set contents of Emacs register named CHAR to VALUE. Returns VALUE."
34 (let ((aelt (assq char register-alist
)))
37 (setq aelt
(cons char value
))
38 (setq register-alist
(cons aelt register-alist
)))
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.
45 Argument is a character, naming the register."
46 (interactive "cPoint to register: \nP")
47 (set-register char
(if arg
(current-screen-configuration) (point-marker))))
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
)))
56 (set-screen-configuration val
)
60 (switch-to-buffer (marker-buffer val
))
62 (error "Register doesn't contain a buffer position or screen configuration"))))))
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: ")
73 ; (prefix-numeric-value arg)
74 ; (if (looking-at "[0-9][0-9]*")
77 ; (narrow-to-region (point)
78 ; (progn (skip-chars-forward "0-9")
80 ; (goto-char (point-min))
81 ; (read (current-buffer))))
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))))
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
)))
98 (message "Register %s is empty" (single-key-description char
))
99 (with-output-to-temp-buffer "*Output*"
101 (princ (single-key-description char
))
107 (princ "a buffer position:\nbuffer ")
108 (princ (buffer-name (marker-buffer val
)))
109 (princ ", position ")
113 (princ "the rectangle:\n")
117 (setq val
(cdr val
))))
118 (princ "the string:\n")
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")
128 (let ((val (get-register char
)))
130 (insert-rectangle 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)))
138 (defun copy-to-register (char start end
&optional delete-flag
)
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.
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
)))
146 (defun append-to-register (char start end
&optional delete-flag
)
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.
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
)))
157 (defun prepend-to-register (char start end
&optional delete-flag
)
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.
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
)))
168 (defun copy-rectangle-to-register (char start end
&optional delete-flag
)
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.
171 START and END are buffer positions giving two corners of rectangle."
172 (interactive "cCopy rectangle to register: \nr\nP")
175 (delete-extract-rectangle start end
)
176 (extract-rectangle start end
))))
178 ;;; register.el ends here