Subject: [PATCH] Re: 24.2.50; append-to-register: Provide a convenient key binding

From: Jambunathan K <[email-masked]>
Date: Fri, 17 Aug 2012 15:26:47 +0530

See attached patch.

Once patch goes through, I will submit a second part which updates
regs.texi.

Some context:

I usually to use M-x append-to-register (and with this patch `C-x r +')
to collect sexps.  I think it will be convenient to have the collected
snippets separated by a suitable separator. Is it OK if a default "\n"
be used? WDYT.  Note that this will be a departure from current
behaviour where the snippets are blindly concatenated.

ps: Patch should apply cleanly to below bzr version.

,----
| kjambunathan@debian-6:~/src/emacs/trunk$ bzr version-info
| revision-id: [email-masked]
| date: 2012-08-17 00:28:23 -0700
| build-date: 2012-08-17 15:17:41 +0530
| revno: 109655
| branch-nick: trunk
`----

=== modified file 'lisp/ChangeLog'
--- lisp/ChangeLog	2012-08-17 06:01:17 +0000
+++ lisp/ChangeLog	2012-08-17 09:45:08 +0000
@@ -1,3 +1,9 @@
+2012-08-17  Jambunathan K  <[email-masked]>
+
+	* register.el (increment-register): If register contains a string,
+	call `append-to-register'.  This way, `C-x r +' can be used to
+	invoke `append-to-register'.  See (Bug#12217).
+
 2012-08-17  Martin Rudalics  <[email-masked]>
 
 	* window.el (delete-window): Fix last fix.

=== modified file 'lisp/register.el'
--- lisp/register.el	2012-07-29 04:45:48 +0000
+++ lisp/register.el	2012-08-17 09:05:29 +0000
@@ -192,13 +192,25 @@
 			(string-to-number (match-string 0)))
 		    0))))
 
-(defun increment-register (number register)
-  "Add NUMBER to the contents of register REGISTER.
-Interactively, NUMBER is the prefix arg."
-  (interactive "p\ncIncrement register: ")
-  (or (numberp (get-register register))
-      (error "Register does not contain a number"))
-  (set-register register (+ number (get-register register))))
+(defun increment-register (prefix register)
+  "Augment contents of REGISTER.
+Interactively, PREFIX is in raw form.
+
+If REGISTER contains a number, add `prefix-numeric-value' of
+PREFIX to it.
+
+If REGISTER is empty or if it contains a string, call
+`append-to-register' with `delete-flag' set to PREFIX."
+  (interactive "P\ncIncrement register: ")
+  (let ((register-val (get-register register)))
+    (unless (or (not register-val)
+		(numberp register-val)
+		(stringp register-val))
+      (error "Register does not contain a number or string"))
+    (if (numberp register-val)
+	(let ((number (prefix-numeric-value prefix)))
+	  (set-register register (+ number register-val)))
+      (append-to-register register (region-beginning) (region-end) prefix))))
 
 (defun view-register (register)
   "Display what is contained in register named REGISTER.