1 ;; Register commands for Emacs.
2 ;; Copyright (C) 1985 Free Software Foundation, Inc.
4 ;; This file is part of GNU Emacs.
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)
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.
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.
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 screen configuration, mark or list.
25 A list represents a rectangle; its elements are strings.")
27 (defun get-register (char)
28 "Return contents of Emacs register named CHAR, or nil if none."
29 (cdr (assq char register-alist)))
31 (defun set-register (char value)
32 "Set contents of Emacs register named CHAR to 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.
140 With prefix arg, delete as well.
141 Called from program, takes four args:
142 REG, START, END and DELETE-FLAG.
143 START and END are buffer positions indicating what to copy."
144 (interactive "cCopy to register: \nr\nP")
145 (set-register char (buffer-substring start end))
146 (if delete-flag (delete-region start end)))
148 (defun append-to-register (char start end &optional delete-flag)
149 "Append region to text in register REG.
150 With prefix arg, delete as well.
151 Called from program, takes four args:
152 REG, START, END and DELETE-FLAG.
153 START and END are buffer positions indicating what to append."
154 (interactive "cAppend to register: \nr\nP")
155 (or (stringp (get-register char))
156 (error "Register does not contain text"))
157 (set-register char (concat (get-register char)
158 (buffer-substring start end)))
159 (if delete-flag (delete-region start end)))
161 (defun prepend-to-register (char start end &optional delete-flag)
162 "Prepend region to text in register REG.
163 With prefix arg, delete as well.
164 Called from program, takes four args:
165 REG, START, END and DELETE-FLAG.
166 START and END are buffer positions indicating what to prepend."
167 (interactive "cPrepend to register: \nr\nP")
168 (or (stringp (get-register char))
169 (error "Register does not contain text"))
170 (set-register char (concat (buffer-substring start end)
171 (get-register char)))
172 (if delete-flag (delete-region start end)))
174 (defun copy-rectangle-to-register (char start end &optional delete-flag)
175 "Copy rectangular region into register REG.
176 With prefix arg, delete as well.
177 Called from program, takes four args:
178 REG, START, END and DELETE-FLAG.
179 START and END are buffer positions giving two corners of rectangle."
180 (interactive "cCopy rectangle to register: \nr\nP")
183 (delete-extract-rectangle start end)
184 (extract-rectangle start end))))