From: Jambunathan K <kjambunathan@gmail.com>
To: Stefan Monnier <monnier@IRO.UMontreal.CA>
Cc: 12217@debbugs.gnu.org
Subject: bug#12217: [PATCH] Re: 24.2.50; append-to-register: Provide a convenient key binding
Date: Sat, 08 Sep 2012 23:56:20 +0530 [thread overview]
Message-ID: <87fw6sz7zn.fsf@gmail.com> (raw)
In-Reply-To: <jwvsjbgmar1.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Tue, 21 Aug 2012 13:20:13 -0400")
[-- Attachment #1: Type: text/plain, Size: 1520 bytes --]
Attaching modified patch. Patch is generated against revno: 109935.
>> Once patch goes through, I will submit a second part which updates
>> regs.texi.
>
> I think the change is OK. I would prefer a single `cond' form with the
> `error' in the last branch (instead of unless+if) so as to avoid
> a redundant `numberp' check (not as a matter of efficiency, of course,
> but maintenance).
> If you send such an updated patch with the corresponding regs.texi
> change, we'll install it.
Done.
>> 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.
>
> I think I'd rather not add any separator by default.
> In many cases adding such a separator would render the command
> inconvenient, and in many others the user can easily make sure the
> text he appends includes an appropriate separator.
> I can see cases where adding a separator could be handy, but I'm not
> sure hardcoding "\n" would solve enough of those cases.
> Maybe you could prompt for a separator if the user provided a C-u
> prefix?
Prefix is used as a `delete-flag' already ...
I have introduced an extra indirection via a `separator-register' (which
is nil by default) Now what gets used as a separator - a newline, a
double newline, a comma or a tab - is under user control.
There is already one user - that is me - who will find this feature
useful.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: bug-12217.patch --]
[-- Type: text/x-diff, Size: 7114 bytes --]
=== modified file 'doc/emacs/ChangeLog'
--- doc/emacs/ChangeLog 2012-09-07 10:27:11 +0000
+++ doc/emacs/ChangeLog 2012-09-08 18:04:28 +0000
@@ -1,3 +1,9 @@
+2012-09-08 Jambunathan K <kjambunathan@gmail.com>
+
+ * regs.texi (Text Registers): `C-x r +' can now be used instead of
+ M-x append-to-register. New option `separator-register'.
+ (Number Registers): Mention that `C-x r +' is polymorphic.
+
2012-09-07 Chong Yidong <cyd@gnu.org>
* windows.texi (Window Choice): Don't mention obsolete
=== modified file 'doc/emacs/regs.texi'
--- doc/emacs/regs.texi 2012-05-27 01:25:06 +0000
+++ doc/emacs/regs.texi 2012-09-08 17:14:13 +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}.
+
+@kindex 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.
+@vindex separator-register
+ When you are collecting text using @code{append-to-register} and
+@code{prepend-to-register}, you may want to separate individual
+collected pieces using a separator. In that case, configure a
+@code{separator-register} 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.
+
+@example
+(setq separator-register ?+)
+(set-register separator-register "\n\n")
+@end 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
+@var{number}. 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'
--- etc/NEWS 2012-09-07 10:27:11 +0000
+++ etc/NEWS 2012-09-08 17:31:09 +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'
--- lisp/ChangeLog 2012-09-07 20:14:55 +0000
+++ lisp/ChangeLog 2012-09-08 17:39:03 +0000
@@ -1,3 +1,13 @@
+2012-09-08 Jambunathan K <kjambunathan@gmail.com>
+
+ * register.el (register): New group.
+ (separator-register): 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.
+ (append-to-register, prepend-to-register): Add separator based on
+ `separator-register.
+
2012-09-07 Stefan Monnier <monnier@iro.umontreal.ca>
* emacs-lisp/byte-run.el (defun): Tweak message. Simplify code.
=== modified file 'lisp/register.el'
--- lisp/register.el 2012-07-29 04:45:48 +0000
+++ lisp/register.el 2012-09-08 14:12:42 +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))
next prev parent reply other threads:[~2012-09-08 18:26 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-17 9:39 bug#12217: 24.2.50; append-to-register: Provide a convenient key binding Jambunathan K
[not found] ` <handler.12217.B.134519691317483.ack@debbugs.gnu.org>
2012-08-17 9:56 ` bug#12217: [PATCH] " Jambunathan K
2012-08-21 17:20 ` Stefan Monnier
2012-09-08 18:26 ` Jambunathan K [this message]
2012-09-08 20:09 ` Stefan Monnier
2012-09-09 8:52 ` Jambunathan K
2012-09-09 7:45 ` Andreas Schwab
2012-09-09 8:45 ` Jambunathan K
2012-09-09 9:02 ` Jambunathan K
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87fw6sz7zn.fsf@gmail.com \
--to=kjambunathan@gmail.com \
--cc=12217@debbugs.gnu.org \
--cc=monnier@IRO.UMontreal.CA \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).