aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/calc/calc-yank.el122
1 files changed, 122 insertions, 0 deletions
diff --git a/lisp/calc/calc-yank.el b/lisp/calc/calc-yank.el
index a9a0e54b9a8..e1e83abe70c 100644
--- a/lisp/calc/calc-yank.el
+++ b/lisp/calc/calc-yank.el
@@ -132,6 +132,128 @@
132 val)) 132 val))
133 val)))))))) 133 val))))))))
134 134
135;;; The Calc set- and get-register commands are modified versions of functions
136;;; in register.el
137
138(defvar calc-register-alist nil
139 "Alist of elements (NAME . (TEXT . CALCVAL)).
140NAME is a character (a number).
141TEXT and CALCVAL are the TEXT and internal structure of stack entries.")
142
143(defun calc-set-register (register text calcval)
144 "Set the contents of the Calc register REGISTER to (TEXT . CALCVAL),
145as well as set the contents of the Emacs register REGISTER to TEXT."
146 (set-register register text)
147 (let ((aelt (assq register calc-register-alist)))
148 (if aelt
149 (setcdr aelt (cons text calcval))
150 (push (cons register (cons text calcval)) calc-register-alist))))
151
152(defun calc-get-register (reg)
153 "Return the CALCVAL portion of the contents of the Calc register REG,
154unless the TEXT portion doesn't match the contents of the Emacs register REG,
155in which case either return the contents of the Emacs register (if it is
156text) or `nil'."
157 (let ((cval (cdr (assq reg calc-register-alist)))
158 (val (cdr (assq reg register-alist))))
159 (if (and (stringp (car cval))
160 (stringp val))
161 (if (string= (car cval) val)
162 (cdr cval)
163 val))))
164
165(defun calc-copy-to-register (register start end &optional delete-flag)
166 "Copy the lines in the region into register REGISTER.
167With prefix arg, delete as well."
168 (interactive "cCopy to register: \nr\nP")
169 (if (eq major-mode 'calc-mode)
170 (let* ((top-num (calc-locate-cursor-element start))
171 (top-pos (save-excursion
172 (calc-cursor-stack-index top-num)
173 (point)))
174 (bot-num (calc-locate-cursor-element (1- end)))
175 (bot-pos (save-excursion
176 (calc-cursor-stack-index (max 0 (1- bot-num)))
177 (point)))
178 (num (- top-num bot-num -1))
179 (str (buffer-substring top-pos bot-pos)))
180 (calc-set-register register str (calc-top-list num bot-num))
181 (if delete-flag
182 (calc-wrapper
183 (calc-pop-stack num bot-num))))
184 (copy-to-register register start end delete-flag)))
185
186(defun calc-insert-register (register)
187 "Insert the contents of register REGISTER."
188 (interactive "cInsert register: ")
189 (if (eq major-mode 'calc-mode)
190 (let ((val (calc-get-register register)))
191 (calc-wrapper
192 (calc-pop-push-record-list
193 0 "insr"
194 (if (not val)
195 (error "Bad format in register data")
196 (if (consp val)
197 val
198 (let ((nval (math-read-exprs (calc-clean-newlines val))))
199 (if (eq (car-safe nval) 'error)
200 (progn
201 (setq nval (math-read-exprs val))
202 (if (eq (car-safe nval) 'error)
203 (error "Bad format in register data")
204 nval))
205 nval)))))))
206 (insert-register register)))
207
208(defun calc-add-to-register (register start end prepend delete-flag)
209 "Add the lines in the region to register REGISTER.
210If PREPEND is non-nil, add them to the beginning of the register,
211otherwise the end. If DELETE-FLAG is non-nil, also delete the region."
212 (let* ((top-num (calc-locate-cursor-element start))
213 (top-pos (save-excursion
214 (calc-cursor-stack-index top-num)
215 (point)))
216 (bot-num (calc-locate-cursor-element (1- end)))
217 (bot-pos (save-excursion
218 (calc-cursor-stack-index (max 0 (1- bot-num)))
219 (point)))
220 (num (- top-num bot-num -1))
221 (str (buffer-substring top-pos bot-pos))
222 (calcval (calc-top-list num bot-num))
223 (cval (cdr (assq register calc-register-alist))))
224 (if (not cval)
225 (calc-set-register register str calcval)
226 (if prepend
227 (calc-set-register
228 register
229 (concat str (car cval))
230 (append calcval (cdr cval)))
231 (calc-set-register
232 register
233 (concat (car cval) str)
234 (append (cdr cval) calcval))))
235 (if delete-flag
236 (calc-wrapper
237 (calc-pop-stack num bot-num)))))
238
239(defun calc-append-to-register (register start end &optional delete-flag)
240 "Copy the lines in the region to the end of register REGISTER.
241With prefix arg, also delete the region."
242 (interactive "cAppend to register: \nr\nP")
243 (if (eq major-mode 'calc-mode)
244 (calc-add-to-register register start end nil delete-flag)
245 (append-to-register register start end delete-flag)))
246
247(defun calc-prepend-to-register (register start end &optional delete-flag)
248 "Copy the lines in the region to the beginning of register REGISTER.
249With prefix arg, also delete the region."
250 (interactive "cPrepend to register: \nr\nP")
251 (if (eq major-mode 'calc-mode)
252 (calc-add-to-register register start end t delete-flag)
253 (prepend-to-register register start end delete-flag)))
254
255
256
135(defun calc-clean-newlines (s) 257(defun calc-clean-newlines (s)
136 (cond 258 (cond
137 259