emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r109946: * lisp/register.el (incremen


From: Stefan Monnier
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r109946: * lisp/register.el (increment-register): Route it to `append-to-register',
Date: Sat, 08 Sep 2012 16:09:06 -0400
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 109946
fixes bug: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=12217
author: Jambunathan K <address@hidden>
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Sat 2012-09-08 16:09:06 -0400
message:
  * lisp/register.el (increment-register): Route it to `append-to-register',
  if register contains text so that `C-x r +' can now be
  used for appending to a text register.
  (register): New group.
  (register-separator): New user option.
  (append-to-register, prepend-to-register): Add separator based on
  `register-separator.
  * doc/emacs/regs.texi (Text Registers): `C-x r +' can now be used instead of
  M-x append-to-register.  New option `register-separator'.
  (Number Registers): Mention that `C-x r +' is polymorphic.
modified:
  doc/emacs/ChangeLog
  doc/emacs/regs.texi
  etc/NEWS
  lisp/ChangeLog
  lisp/register.el
=== modified file 'doc/emacs/ChangeLog'
--- a/doc/emacs/ChangeLog       2012-09-07 10:27:11 +0000
+++ b/doc/emacs/ChangeLog       2012-09-08 20:09:06 +0000
@@ -1,3 +1,9 @@
+2012-09-08  Jambunathan K  <address@hidden>
+
+       * regs.texi (Text Registers): `C-x r +' can now be used instead of
+       M-x append-to-register.  New option `register-separator'.
+       (Number Registers): Mention that `C-x r +' is polymorphic.
+
 2012-09-07  Chong Yidong  <address@hidden>
 
        * windows.texi (Window Choice): Don't mention obsolete
@@ -10,9 +16,9 @@
 
 2012-08-24  Michael Albinus  <address@hidden>
 
-       * cmdargs.texi (General Variables): Setting
-       $DBUS_SESSION_BUS_ADDRESS to a dummy value suppresses connections
-       to the D-Bus session bus.  (Bug#12112)
+       * cmdargs.texi (General Variables):
+       Setting $DBUS_SESSION_BUS_ADDRESS to a dummy value suppresses
+       connections to the D-Bus session bus.  (Bug#12112)
 
 2012-08-14  Eli Zaretskii  <address@hidden>
 

=== modified file 'doc/emacs/regs.texi'
--- a/doc/emacs/regs.texi       2012-05-27 01:25:06 +0000
+++ b/doc/emacs/regs.texi       2012-09-08 20:09:06 +0000
@@ -92,6 +92,13 @@
 Insert text from register @var{r} (@code{insert-register}).
 @item M-x append-to-register @key{RET} @var{r}
 Append region to text in register @var{r}.
+
address@hidden C-x r +
+When register @var{r} contains text, you can use @kbd{C-x r +}
+(@code{increment-register}) to append to that register.  Note that
+command @kbd{C-x r +} behaves differently if @var{r} contains a
+number.  @xref{Number Registers}.
+
 @item M-x prepend-to-register @key{RET} @var{r}
 Prepend region to text in register @var{r}.
 @end table
@@ -116,6 +123,19 @@
 the region text to the text in the register instead of
 @emph{appending} it.
 
address@hidden register-separator
+  When you are collecting text using @code{append-to-register} and
address@hidden, you may want to separate individual
+collected pieces using a separator.  In that case, configure a
address@hidden and store the separator text in to that
+register.  For example, to get double newlines as text separator
+during the collection process, you can use the following setting.
+
address@hidden
+(setq register-separator ?+)
+(set-register register-separator "\n\n")
address@hidden example
+
 @kindex C-x r i
 @findex insert-register
   @kbd{C-x r i @var{r}} inserts in the buffer the text from register
@@ -191,8 +211,10 @@
 @item C-u @var{number} C-x r + @var{r}
 @kindex C-x r +
 @findex increment-register
-Increment the number in register @var{r} by @var{number}
-(@code{increment-register}).
+If @var{r} contains a number, increment the number in that register by
address@hidden  Note that command @kbd{C-x r +}
+(@code{increment-register}) behaves differently if @var{r} contains
+text.  @xref{Text Registers}.
 @item C-x r i @var{r}
 Insert the number from register @var{r} into the buffer.
 @end table

=== modified file 'etc/NEWS'
--- a/etc/NEWS  2012-09-08 14:48:26 +0000
+++ b/etc/NEWS  2012-09-08 20:09:06 +0000
@@ -182,6 +182,13 @@
 delete-trailing-whitespace command should delete trailing lines at the
 end of the buffer.  It defaults to t.
 
++++
+** `C-x r +' is now overloaded to invoke `append-to-register.
++++
+** New option `separator-register'.  Separator register stores
+separator text for use with M-x append-to-register and M-x
+prepend-to-register.  See manual for details.
+
 ** Search changes
 
 *** Global `M-s _' starts a symbol (identifier) incremental search,

=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2012-09-08 20:00:13 +0000
+++ b/lisp/ChangeLog    2012-09-08 20:09:06 +0000
@@ -1,15 +1,25 @@
+2012-09-08  Jambunathan K  <address@hidden>
+
+       * register.el (register): New group.
+       (register-separator): New user option.
+       (increment-register): Route it to `append-to-register', if
+       register contains text.  Implication is that `C-x r +' can now be
+       used for appending to a text register (bug#12217).
+       (append-to-register, prepend-to-register): Add separator based on
+       `register-separator.
+
 2012-09-08  Alan Mackenzie  <address@hidden>
 
        AWK Mode: make auto-newline work when there's "==" in the pattern.
        * progmodes/cc-cmds.el (c-point-syntax): Handle virtual semicolons
        correctly.
-       * progmodes/cc-engine.el (c-guess-basic-syntax CASE 5A.3): Test
-       more rigorously for "=" token.
+       * progmodes/cc-engine.el (c-guess-basic-syntax CASE 5A.3):
+       Test more rigorously for "=" token.
 
 2012-09-08  Dmitry Gutov  <address@hidden>
 
-       * progmodes/ruby-mode.el (ruby-match-expression-expansion): Only
-       fail when reached LIMIT.
+       * progmodes/ruby-mode.el (ruby-match-expression-expansion):
+       Only fail when reached LIMIT.
 
 2012-09-08  Chong Yidong  <address@hidden>
 

=== modified file 'lisp/register.el'
--- a/lisp/register.el  2012-07-29 04:45:48 +0000
+++ b/lisp/register.el  2012-09-08 20:09:06 +0000
@@ -76,6 +76,22 @@
 A list of the form (FRAME-CONFIGURATION POSITION)
  represents a saved frame configuration plus a saved value of point.")
 
+(defgroup register nil
+  "Register commands."
+  :group 'convenience
+  :version "24.2.50")
+
+(defcustom separator-register nil
+  "Use contents of this register to separate collected text.
+
+When collecting text with
+`append-to-register' (resp. `prepend-to-register') contents of
+this register is added to the beginning (resp. end) of the marked
+text."
+  :group 'register
+  :type '(choice (const :tag "None" nil)
+                (character :tag "Use register" :value ?+)))
+
 (defun get-register (register)
   "Return contents of Emacs register named REGISTER, or nil if none."
   (cdr (assq register register-alist)))
@@ -192,13 +208,24 @@
                        (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 text, call
+`append-to-register' with `delete-flag' set to PREFIX."
+  (interactive "P\ncIncrement register: ")
+  (let ((register-val (get-register register)))
+    (cond
+     ((numberp register-val)
+      (let ((number (prefix-numeric-value prefix)))
+       (set-register register (+ number register-val))))
+     ((or (not register-val) (stringp register-val))
+      (append-to-register register (region-beginning) (region-end) prefix))
+     (t (error "Register does not contain a number or text")))))
 
 (defun view-register (register)
   "Display what is contained in register named REGISTER.
@@ -349,10 +376,11 @@
 START and END are buffer positions indicating what to append."
   (interactive "cAppend to register: \nr\nP")
   (let ((reg (get-register register))
-        (text (filter-buffer-substring start end)))
+        (text (filter-buffer-substring start end))
+       (separator (and separator-register (get-register separator-register))))
     (set-register
      register (cond ((not reg) text)
-                    ((stringp reg) (concat reg text))
+                    ((stringp reg) (concat reg separator text))
                     (t (error "Register does not contain text")))))
   (cond (delete-flag
         (delete-region start end))
@@ -366,10 +394,11 @@
 START and END are buffer positions indicating what to prepend."
   (interactive "cPrepend to register: \nr\nP")
   (let ((reg (get-register register))
-        (text (filter-buffer-substring start end)))
+        (text (filter-buffer-substring start end))
+       (separator (and separator-register (get-register separator-register))))
     (set-register
      register (cond ((not reg) text)
-                    ((stringp reg) (concat text reg))
+                    ((stringp reg) (concat text separator reg))
                     (t (error "Register does not contain text")))))
   (cond (delete-flag
         (delete-region start end))


reply via email to

[Prev in Thread] Current Thread [Next in Thread]