|
0
|
1 ;;; register.el --- register commands for XEmacs.
|
|
|
2
|
|
|
3 ;; Copyright (C) 1985, 1993, 1994 Free Software Foundation, Inc.
|
|
|
4
|
|
|
5 ;; Maintainer: FSF
|
|
|
6 ;; Keywords: internal
|
|
|
7
|
|
|
8 ;; This file is part of XEmacs.
|
|
|
9
|
|
|
10 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
|
11 ;; under the terms of the GNU General Public License as published by
|
|
|
12 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
|
13 ;; any later version.
|
|
|
14
|
|
|
15 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
|
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
18 ;; General Public License for more details.
|
|
|
19
|
|
|
20 ;; You should have received a copy of the GNU General Public License
|
|
|
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
|
4
|
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
23 ;; 02111-1307, USA.
|
|
0
|
24
|
|
4
|
25 ;;; Synched up with: FSF 19.34.
|
|
0
|
26
|
|
|
27 ;;; Commentary:
|
|
|
28
|
|
|
29 ;; This package of functions emulates and somewhat extends the venerable
|
|
|
30 ;; TECO's `register' feature, which permits you to save various useful
|
|
|
31 ;; pieces of buffer state to named variables. The entry points are
|
|
|
32 ;; documented in the XEmacs Reference Manual.
|
|
|
33
|
|
|
34 ;;; Code:
|
|
|
35
|
|
|
36 (defvar register-alist nil
|
|
|
37 "Alist of elements (NAME . CONTENTS), one for each Emacs register.
|
|
|
38 NAME is a character (a number). CONTENTS is a string, number,
|
|
|
39 frame configuration, mark or list.
|
|
|
40 A list of strings represents a rectangle.
|
|
|
41 A list of the form (file . NAME) represents the file named NAME.")
|
|
|
42
|
|
|
43 (defun get-register (reg)
|
|
|
44 "Return contents of Emacs register named REG, or nil if none."
|
|
|
45 (cdr (assq reg register-alist)))
|
|
|
46
|
|
|
47 (defun set-register (register value)
|
|
|
48 "Set contents of Emacs register named REGISTER to VALUE. Returns VALUE.
|
|
|
49 See the documentation of the variable `register-alist' for possible VALUEs."
|
|
|
50 (let ((aelt (assq register register-alist)))
|
|
|
51 (if aelt
|
|
|
52 (setcdr aelt value)
|
|
|
53 (setq aelt (cons register value))
|
|
|
54 (setq register-alist (cons aelt register-alist)))
|
|
|
55 value))
|
|
|
56
|
|
|
57 (defun point-to-register (register &optional arg)
|
|
|
58 "Store current location of point in register REGISTER.
|
|
|
59 With prefix argument, store current frame configuration.
|
|
|
60 Use \\[jump-to-register] to go to that location or restore that configuration.
|
|
|
61 Argument is a character, naming the register."
|
|
|
62 (interactive "cPoint to register: \nP")
|
|
|
63 (set-register register
|
|
|
64 (if arg (current-frame-configuration) (point-marker))))
|
|
|
65
|
|
4
|
66 (defun window-configuration-to-register (register &optional arg)
|
|
0
|
67 "Store the window configuration of the selected frame in register REGISTER.
|
|
|
68 Use \\[jump-to-register] to restore the configuration.
|
|
|
69 Argument is a character, naming the register."
|
|
4
|
70 (interactive "cWindow configuration to register: \nP")
|
|
0
|
71 (set-register register (current-window-configuration)))
|
|
|
72
|
|
|
73 (defun frame-configuration-to-register (register &optional arg)
|
|
|
74 "Store the window configuration of all frames in register REGISTER.
|
|
|
75 Use \\[jump-to-register] to restore the configuration.
|
|
|
76 Argument is a character, naming the register."
|
|
4
|
77 (interactive "cFrame configuration to register: \nP")
|
|
0
|
78 (set-register register (current-frame-configuration)))
|
|
|
79
|
|
|
80 (defalias 'register-to-point 'jump-to-register)
|
|
|
81 (defun jump-to-register (register &optional delete)
|
|
|
82 "Move point to location stored in a register.
|
|
|
83 If the register contains a file name, find that file.
|
|
|
84 \(To put a file name in a register, you must use `set-register'.)
|
|
|
85 If the register contains a window configuration (one frame) or a frame
|
|
|
86 configuration (all frames), restore that frame or all frames accordingly.
|
|
|
87 First argument is a character, naming the register.
|
|
|
88 Optional second arg non-nil (interactively, prefix argument) says to
|
|
|
89 delete any existing frames that the frame configuration doesn't mention.
|
|
|
90 \(Otherwise, these frames are iconified.)"
|
|
|
91 (interactive "cJump to register: \nP")
|
|
|
92 (let ((val (get-register register)))
|
|
|
93 (cond
|
|
|
94 ((and (fboundp 'frame-configuration-p)
|
|
|
95 (frame-configuration-p val))
|
|
|
96 (set-frame-configuration val (not delete)))
|
|
|
97 ((window-configuration-p val)
|
|
|
98 (set-window-configuration val))
|
|
|
99 ((markerp val)
|
|
|
100 (or (marker-buffer val)
|
|
|
101 (error "That register's buffer no longer exists"))
|
|
|
102 (switch-to-buffer (marker-buffer val))
|
|
|
103 (goto-char val))
|
|
|
104 ((and (consp val) (eq (car val) 'file))
|
|
|
105 (find-file (cdr val)))
|
|
|
106 (t
|
|
|
107 (error "Register doesn't contain a buffer position or configuration")))))
|
|
|
108
|
|
|
109 ;(defun number-to-register (arg char)
|
|
|
110 ; "Store a number in a register.
|
|
|
111 ;Two args, NUMBER and REGISTER (a character, naming the register).
|
|
|
112 ;If NUMBER is nil, digits in the buffer following point are read
|
|
|
113 ;to get the number to store.
|
|
|
114 ;Interactively, NUMBER is the prefix arg (none means nil)."
|
|
|
115 ; (interactive "P\ncNumber to register: ")
|
|
|
116 ; (set-register char
|
|
|
117 ; (if arg
|
|
|
118 ; (prefix-numeric-value arg)
|
|
|
119 ; (if (looking-at "[0-9][0-9]*")
|
|
|
120 ; (save-excursion
|
|
|
121 ; (save-restriction
|
|
|
122 ; (narrow-to-region (point)
|
|
|
123 ; (progn (skip-chars-forward "0-9")
|
|
|
124 ; (point)))
|
|
|
125 ; (goto-char (point-min))
|
|
|
126 ; (read (current-buffer))))
|
|
|
127 ; 0))))
|
|
|
128
|
|
|
129 ;(defun increment-register (arg char)
|
|
|
130 ; "Add NUMBER to the contents of register REGISTER.
|
|
|
131 ;Interactively, NUMBER is the prefix arg (none means nil)."
|
|
|
132 ; (interactive "p\ncNumber to register: ")
|
|
|
133 ; (or (integerp (get-register char))
|
|
|
134 ; (error "Register does not contain a number"))
|
|
|
135 ; (set-register char (+ arg (get-register char))))
|
|
|
136
|
|
|
137 (defun view-register (register)
|
|
|
138 "Display what is contained in register named REGISTER.
|
|
|
139 The Lisp value REGISTER is a character."
|
|
|
140 (interactive "cView register: ")
|
|
|
141 (let ((val (get-register register)))
|
|
|
142 (if (null val)
|
|
4
|
143 (message "Register %s is empty" (single-key-description register))
|
|
0
|
144 (with-output-to-temp-buffer "*Output*"
|
|
|
145 (princ (format "Register %s contains "
|
|
|
146 (single-key-description register)))
|
|
|
147 (cond
|
|
4
|
148 ((integerp val)
|
|
|
149 (princ val))
|
|
0
|
150
|
|
4
|
151 ((markerp val)
|
|
|
152 (let ((buf (marker-buffer val)))
|
|
|
153 (if (null buf)
|
|
|
154 (princ "a marker in no buffer")
|
|
|
155 (princ (format
|
|
|
156 "a buffer position:\nbuff %s, position %s"
|
|
|
157 (buffer-name (marker-buffer val))
|
|
|
158 (marker-position val))))))
|
|
0
|
159
|
|
|
160 ((window-configuration-p val)
|
|
|
161 (princ "a window configuration."))
|
|
|
162
|
|
|
163
|
|
|
164 ;; ((frame-configuration-p val)
|
|
|
165 ;; (princ "a frame configuration."))
|
|
|
166
|
|
|
167 ((and (consp val) (eq (car val) 'file))
|
|
|
168 (princ "the file ")
|
|
|
169 (prin1 (cdr val))
|
|
|
170 (princ "."))
|
|
|
171
|
|
4
|
172 ((consp val)
|
|
|
173 (princ "the rectangle:\n")
|
|
0
|
174 (while val
|
|
4
|
175 (princ (car val))
|
|
|
176 (terpri)
|
|
|
177 (setq val (cdr val))))
|
|
0
|
178
|
|
|
179 ((stringp val)
|
|
|
180 (princ "the text:\n")
|
|
|
181 (princ val))
|
|
|
182
|
|
4
|
183 (t
|
|
0
|
184 (princ "Garbage:\n")
|
|
|
185 (prin1 val)))))))
|
|
|
186
|
|
|
187 (defun insert-register (register &optional arg)
|
|
4
|
188 "Insert contents of register REGISTER. (REGISTER is a character).
|
|
0
|
189 Normally puts point before and mark after the inserted text.
|
|
|
190 If optional second arg is non-nil, puts mark before and point after.
|
|
|
191 Interactively, second arg is non-nil if prefix arg is supplied."
|
|
|
192 (interactive "*cInsert register: \nP")
|
|
|
193 (push-mark)
|
|
|
194 (let ((val (get-register register)))
|
|
4
|
195 (cond
|
|
|
196 ((consp val)
|
|
|
197 (insert-rectangle val))
|
|
|
198 ((stringp val)
|
|
|
199 (insert val))
|
|
|
200 ((integerp val)
|
|
|
201 (princ val (current-buffer)))
|
|
|
202 ((and (markerp val) (marker-position val))
|
|
|
203 (princ (marker-position val) (current-buffer)))
|
|
|
204 (t
|
|
|
205 (error "Register does not contain text"))))
|
|
0
|
206 ;; XEmacs: don't activate the region. It's annoying.
|
|
|
207 (if (not arg) (exchange-point-and-mark t)))
|
|
|
208
|
|
|
209 (defun copy-to-register (register start end &optional delete-flag)
|
|
4
|
210 "Copy region into register REGISTER. With prefix arg, delete as well.
|
|
|
211 Called from program, takes four args: REGISTER, START, END and DELETE-FLAG.
|
|
0
|
212 START and END are buffer positions indicating what to copy."
|
|
|
213 (interactive "cCopy to register: \nr\nP")
|
|
|
214 (set-register register (buffer-substring start end))
|
|
|
215 (if delete-flag (delete-region start end)))
|
|
|
216
|
|
|
217 (defun append-to-register (register start end &optional delete-flag)
|
|
|
218 "Append region to text in register REGISTER.
|
|
|
219 With prefix arg, delete as well.
|
|
4
|
220 Called from program, takes four args: REGISTER, START, END and DELETE-FLAG.
|
|
0
|
221 START and END are buffer positions indicating what to append."
|
|
|
222 (interactive "cAppend to register: \nr\nP")
|
|
|
223 (or (stringp (get-register register))
|
|
|
224 (error "Register does not contain text"))
|
|
|
225 (set-register register (concat (get-register register)
|
|
|
226 (buffer-substring start end)))
|
|
|
227 (if delete-flag (delete-region start end)))
|
|
|
228
|
|
|
229 (defun prepend-to-register (register start end &optional delete-flag)
|
|
|
230 "Prepend region to text in register REGISTER.
|
|
|
231 With prefix arg, delete as well.
|
|
4
|
232 Called from program, takes four args: REGISTER, START, END and DELETE-FLAG.
|
|
0
|
233 START and END are buffer positions indicating what to prepend."
|
|
|
234 (interactive "cPrepend to register: \nr\nP")
|
|
|
235 (or (stringp (get-register register))
|
|
|
236 (error "Register does not contain text"))
|
|
|
237 (set-register register (concat (buffer-substring start end)
|
|
|
238 (get-register register)))
|
|
|
239 (if delete-flag (delete-region start end)))
|
|
|
240
|
|
|
241 (defun copy-rectangle-to-register (register start end &optional delete-flag)
|
|
|
242 "Copy rectangular region into register REGISTER.
|
|
|
243 With prefix arg, delete as well.
|
|
4
|
244 Called from program, takes four args: REGISTER, START, END and DELETE-FLAG.
|
|
0
|
245 START and END are buffer positions giving two corners of rectangle."
|
|
|
246 (interactive "cCopy rectangle to register: \nr\nP")
|
|
|
247 (set-register register
|
|
|
248 (if delete-flag
|
|
|
249 (delete-extract-rectangle start end)
|
|
|
250 (extract-rectangle start end))))
|
|
|
251
|
|
|
252 ;;; register.el ends here
|