* prefix-region
@ 2005-10-24 20:28 Hrvoje Niksic
2005-10-24 21:39 ` prefix-region Andreas Schwab
2005-10-31 1:14 ` prefix-region Richard M. Stallman
0 siblings, 2 replies; 14+ messages in thread
From: Hrvoje Niksic @ 2005-10-24 20:28 UTC (permalink / raw)
I have found this function, originally from XEmacs, immensely useful:
(prefix-region PREFIX)
Insert PREFIX at the beginning of each line between mark and point.
It is useful for all kinds of editing jobs, including commenting out
pieces of code and quoting mail. While some of these things can be
achieved using other Emacs functions, `M-x prefix-region' is often
much more convenient, especially when the more sophisticated
mechanisms are unavailable (such as when editing snippets of code in
mail messages).
This function is not as easy to write as it seems because there are
several corner cases that need to be gotten right (empty region,
whether mark precedes point or vice versa, mark/point at line start or
end positions). Because of that I propose that you include the
function in Emacs.
I wasn't satisfied with the XEmacs implementation of this function so
I wrote and tested this one:
(defun prefix-region (prefix)
"Insert PREFIX at the beginning of each line between mark and point."
(interactive "sPrefix string: ")
(let ((end (region-end)))
(save-excursion
(goto-char (region-beginning))
(beginning-of-line)
(save-restriction
(narrow-to-region (point) end)
(while (not (eobp))
(insert prefix)
(forward-line 1))))))
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: prefix-region
2005-10-24 20:28 prefix-region Hrvoje Niksic
@ 2005-10-24 21:39 ` Andreas Schwab
2005-10-24 22:45 ` prefix-region Hrvoje Niksic
2005-10-31 1:14 ` prefix-region Richard M. Stallman
1 sibling, 1 reply; 14+ messages in thread
From: Andreas Schwab @ 2005-10-24 21:39 UTC (permalink / raw)
Cc: emacs-devel
Hrvoje Niksic <hniksic@xemacs.org> writes:
> I have found this function, originally from XEmacs, immensely useful:
>
> (prefix-region PREFIX)
>
> Insert PREFIX at the beginning of each line between mark and point.
Looks like string-rectangle can do the same, and more.
Andreas.
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: prefix-region
2005-10-24 21:39 ` prefix-region Andreas Schwab
@ 2005-10-24 22:45 ` Hrvoje Niksic
2005-10-25 8:24 ` prefix-region Romain Francoise
0 siblings, 1 reply; 14+ messages in thread
From: Hrvoje Niksic @ 2005-10-24 22:45 UTC (permalink / raw)
Cc: emacs-devel
Andreas Schwab <schwab@suse.de> writes:
> Hrvoje Niksic <hniksic@xemacs.org> writes:
>
>> I have found this function, originally from XEmacs, immensely useful:
>>
>> (prefix-region PREFIX)
>>
>> Insert PREFIX at the beginning of each line between mark and point.
>
> Looks like string-rectangle can do the same, and more.
That behaves very differently when the endpoints of the region aren't
at line beginnings. It also prefixes the last line even if it wasn't
really part of the selection.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: prefix-region
2005-10-24 22:45 ` prefix-region Hrvoje Niksic
@ 2005-10-25 8:24 ` Romain Francoise
2005-10-25 9:54 ` prefix-region Hrvoje Niksic
0 siblings, 1 reply; 14+ messages in thread
From: Romain Francoise @ 2005-10-25 8:24 UTC (permalink / raw)
Cc: emacs-devel
Hrvoje Niksic <hniksic@xemacs.org> writes:
>> Looks like string-rectangle can do the same, and more.
> That behaves very differently when the endpoints of the region aren't
> at line beginnings. It also prefixes the last line even if it wasn't
> really part of the selection.
See also `string-insert-rectangle'.
--
Romain Francoise <romain@orebokech.com> | I've become someone else's
it's a miracle -- http://orebokech.com/ | nightmare...
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: prefix-region
2005-10-25 8:24 ` prefix-region Romain Francoise
@ 2005-10-25 9:54 ` Hrvoje Niksic
2005-10-25 13:59 ` prefix-region Miles Bader
0 siblings, 1 reply; 14+ messages in thread
From: Hrvoje Niksic @ 2005-10-25 9:54 UTC (permalink / raw)
Cc: emacs-devel
Romain Francoise <romain@orebokech.com> writes:
> See also `string-insert-rectangle'.
That's still a "rectangle" function, not a "region" function, which is
why it gets the corner cases wrong in exactly the same way that
`string-rectangle' does.
I'm not saying that there is anything wrong with those functions, only
that they are not as useful for this particular purpose as
`prefix-region' is.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: prefix-region
2005-10-25 9:54 ` prefix-region Hrvoje Niksic
@ 2005-10-25 13:59 ` Miles Bader
2005-10-25 19:15 ` prefix-region Hrvoje Niksic
0 siblings, 1 reply; 14+ messages in thread
From: Miles Bader @ 2005-10-25 13:59 UTC (permalink / raw)
Cc: Romain Francoise, emacs-devel
2005/10/25, Hrvoje Niksic <hniksic@xemacs.org>:
> I'm not saying that there is anything wrong with those functions, only
> that they are not as useful for this particular purpose as
> `prefix-region' is.
Which purpose though? I suspect 90% of the time, `comment-dwim' (M-;)
or `indent-rigidly' are really what's wanted, and do the job better
(for instance `comment-dwim' handles mail quoting and commenting-out
of code just about perfectly); adding arbitrary prefixes seems kinda
rare.
-Miles
--
Do not taunt Happy Fun Ball.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: prefix-region
2005-10-25 13:59 ` prefix-region Miles Bader
@ 2005-10-25 19:15 ` Hrvoje Niksic
2005-10-25 19:41 ` prefix-region Stefan Monnier
2005-10-25 21:12 ` prefix-region Andreas Schwab
0 siblings, 2 replies; 14+ messages in thread
From: Hrvoje Niksic @ 2005-10-25 19:15 UTC (permalink / raw)
Cc: Romain Francoise, emacs-devel, miles
Miles Bader <snogglethorpe@gmail.com> writes:
> 2005/10/25, Hrvoje Niksic <hniksic@xemacs.org>:
>> I'm not saying that there is anything wrong with those functions, only
>> that they are not as useful for this particular purpose as
>> `prefix-region' is.
>
> Which purpose though?
Prefixing a region with an arbitrary string. It comes up a lot.
> I suspect 90% of the time, `comment-dwim' (M-;)
It won't work when editing snippets of code in mail messages or when
editing a language for which you don't have a major mode handy.
> or `indent-rigidly' are really what's wanted, and do the job better
> (for instance `comment-dwim' handles mail quoting and commenting-out
> of code just about perfectly); adding arbitrary prefixes seems kinda
> rare.
I don't think it's all that rare. I've used the function a lot over
the years, and I know other XEmacs users who have found it useful.
Writing a replacement one is non-trivial.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: prefix-region
2005-10-25 19:15 ` prefix-region Hrvoje Niksic
@ 2005-10-25 19:41 ` Stefan Monnier
2005-10-25 19:47 ` prefix-region Romain Francoise
2005-10-25 20:29 ` prefix-region Edward O'Connor
2005-10-25 21:12 ` prefix-region Andreas Schwab
1 sibling, 2 replies; 14+ messages in thread
From: Stefan Monnier @ 2005-10-25 19:41 UTC (permalink / raw)
Cc: miles, snogglethorpe, Romain Francoise, emacs-devel
>> or `indent-rigidly' are really what's wanted, and do the job better
>> (for instance `comment-dwim' handles mail quoting and commenting-out
>> of code just about perfectly); adding arbitrary prefixes seems kinda
>> rare.
> I don't think it's all that rare.
Agreed: I'd guess that about 80% of my uses of string-rectangle would be
covered by prefix-region. OTOH since I'm used to string-rectangle,
I probably wouldn't bother to use prefix-region.
(I've even found myself using string-rectangle instead of M-;)
Stefan
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: prefix-region
2005-10-25 19:15 ` prefix-region Hrvoje Niksic
2005-10-25 19:41 ` prefix-region Stefan Monnier
@ 2005-10-25 21:12 ` Andreas Schwab
2005-10-25 21:24 ` prefix-region Hrvoje Niksic
1 sibling, 1 reply; 14+ messages in thread
From: Andreas Schwab @ 2005-10-25 21:12 UTC (permalink / raw)
Cc: miles, snogglethorpe, Romain Francoise, emacs-devel
Hrvoje Niksic <hniksic@xemacs.org> writes:
> Miles Bader <snogglethorpe@gmail.com> writes:
>
>> 2005/10/25, Hrvoje Niksic <hniksic@xemacs.org>:
>>> I'm not saying that there is anything wrong with those functions, only
>>> that they are not as useful for this particular purpose as
>>> `prefix-region' is.
>>
>> Which purpose though?
>
> Prefixing a region with an arbitrary string. It comes up a lot.
I have yet to find a situation where string-rectangle did not suit my
needs. YMMV, of course.
Andreas.
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: prefix-region
2005-10-25 21:12 ` prefix-region Andreas Schwab
@ 2005-10-25 21:24 ` Hrvoje Niksic
0 siblings, 0 replies; 14+ messages in thread
From: Hrvoje Niksic @ 2005-10-25 21:24 UTC (permalink / raw)
Cc: miles, snogglethorpe, Romain Francoise, emacs-devel
Andreas Schwab <schwab@suse.de> writes:
>> Prefixing a region with an arbitrary string. It comes up a lot.
>
> I have yet to find a situation where string-rectangle did not suit
> my needs. YMMV, of course.
No one is claiming that prefix-region can do something that
string-rectangle cannot do if you are careful enough. I do claim that
prefix-region is much more convenient to use because you don't need to
adjust region endpoints to beginning of line.
prefix-region is also more easily discovered by someone trying to,
well, prefix a region... Before discovering it I used to do things
like `C-u M-| sed 's/^/PREFIX/'.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: prefix-region
2005-10-24 20:28 prefix-region Hrvoje Niksic
2005-10-24 21:39 ` prefix-region Andreas Schwab
@ 2005-10-31 1:14 ` Richard M. Stallman
2005-10-31 8:54 ` prefix-region Hrvoje Niksic
1 sibling, 1 reply; 14+ messages in thread
From: Richard M. Stallman @ 2005-10-31 1:14 UTC (permalink / raw)
Cc: emacs-devel
It seems possibly useful, and harmless to add.
Could you write patches to the Emacs Manual and etc/NEWS
to document it? We can't install it without that.
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2005-10-31 8:54 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-24 20:28 prefix-region Hrvoje Niksic
2005-10-24 21:39 ` prefix-region Andreas Schwab
2005-10-24 22:45 ` prefix-region Hrvoje Niksic
2005-10-25 8:24 ` prefix-region Romain Francoise
2005-10-25 9:54 ` prefix-region Hrvoje Niksic
2005-10-25 13:59 ` prefix-region Miles Bader
2005-10-25 19:15 ` prefix-region Hrvoje Niksic
2005-10-25 19:41 ` prefix-region Stefan Monnier
2005-10-25 19:47 ` prefix-region Romain Francoise
2005-10-25 20:29 ` prefix-region Edward O'Connor
2005-10-25 21:12 ` prefix-region Andreas Schwab
2005-10-25 21:24 ` prefix-region Hrvoje Niksic
2005-10-31 1:14 ` prefix-region Richard M. Stallman
2005-10-31 8:54 ` prefix-region Hrvoje Niksic
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).