* repexp to collapse multiple blank lines into one
@ 2005-10-09 12:27 B. T. Raven
2005-10-09 12:59 ` Friedrich Laher
` (4 more replies)
0 siblings, 5 replies; 14+ messages in thread
From: B. T. Raven @ 2005-10-09 12:27 UTC (permalink / raw)
Is there a way to use M-C-% to flush extra blank lines from a buffer.
Something like:
Query replace regexp: ^$+ [which of course doesn't work, presumably
because $ has to be last]
with: C-j
I know about C-x C-o but that's interactive rather than batch mode.
Thanks,
Ed
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: repexp to collapse multiple blank lines into one
2005-10-09 12:27 repexp to collapse multiple blank lines into one B. T. Raven
@ 2005-10-09 12:59 ` Friedrich Laher
2005-10-09 13:01 ` Peter Dyballa
` (3 subsequent siblings)
4 siblings, 0 replies; 14+ messages in thread
From: Friedrich Laher @ 2005-10-09 12:59 UTC (permalink / raw)
you could run until search fail replacing 2 newlines by one
B. T. Raven wrote:
>Is there a way to use M-C-% to flush extra blank lines from a buffer.
>Something like:
>Query replace regexp: ^$+ [which of course doesn't work, presumably
>because $ has to be last]
>with: C-j
>
>I know about C-x C-o but that's interactive rather than batch mode.
>
>Thanks,
>
>Ed
>
>
>_______________________________________________
>Help-gnu-emacs mailing list
>Help-gnu-emacs@gnu.org
>http://lists.gnu.org/mailman/listinfo/help-gnu-emacs
>
>
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: repexp to collapse multiple blank lines into one
2005-10-09 12:27 repexp to collapse multiple blank lines into one B. T. Raven
2005-10-09 12:59 ` Friedrich Laher
@ 2005-10-09 13:01 ` Peter Dyballa
2005-10-09 13:44 ` Neon Absentius
` (2 subsequent siblings)
4 siblings, 0 replies; 14+ messages in thread
From: Peter Dyballa @ 2005-10-09 13:01 UTC (permalink / raw)
Cc: help-gnu-emacs
Am 09.10.2005 um 14:27 schrieb B. T. Raven:
> Query replace regexp: ^$+ [which of course doesn't work, presumably
> because $ has to be last]
> with: C-j
>
What about ^C-j+ with C-j?
--
Greetings
Pete
A child of five could understand this! Fetch me a child of five.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: repexp to collapse multiple blank lines into one
2005-10-09 12:27 repexp to collapse multiple blank lines into one B. T. Raven
2005-10-09 12:59 ` Friedrich Laher
2005-10-09 13:01 ` Peter Dyballa
@ 2005-10-09 13:44 ` Neon Absentius
[not found] ` <mailman.10556.1128865819.20277.help-gnu-emacs@gnu.org>
2005-10-10 20:59 ` repexp " David Hansen
4 siblings, 0 replies; 14+ messages in thread
From: Neon Absentius @ 2005-10-09 13:44 UTC (permalink / raw)
On Sun, Oct 09, 2005 at 12:27:07PM +0000, B. T. Raven wrote:
> Is there a way to use M-C-% to flush extra blank lines from a buffer.
> Something like:
> Query replace regexp: ^$+ [which of course doesn't work, presumably
> because $ has to be last]
> with: C-j
>
The following seems to work
C-M-% \(^C-qC-j\)+ RET \1 RET
Provided of course that your lines are really blank and do not contain
any spaces, tabs etc.
> Thanks,
>
> Ed
>
--
There is no national science just as there is no national
multiplication table; what is national is no longer science.
-- Anton Checov
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: regexp to collapse multiple blank lines into one
[not found] ` <mailman.10556.1128865819.20277.help-gnu-emacs@gnu.org>
@ 2005-10-09 18:36 ` B. T. Raven
2005-10-10 16:35 ` Kevin Rodgers
0 siblings, 1 reply; 14+ messages in thread
From: B. T. Raven @ 2005-10-09 18:36 UTC (permalink / raw)
"Neon Absentius" <absent@sdf.lonestar.org> wrote in message
news:mailman.10556.1128865819.20277.help-gnu-emacs@gnu.org...
> On Sun, Oct 09, 2005 at 12:27:07PM +0000, B. T. Raven wrote:
> > Is there a way to use M-C-% to flush extra blank lines from a
buffer.
> > Something like:
> > Query replace regexp: ^$+ [which of course doesn't work, presumably
> > because $ has to be last]
> > with: C-j
> >
>
> The following seems to work
>
> C-M-% \(^C-qC-j\)+ RET \1 RET
>
> Provided of course that your lines are really blank and do not contain
> any spaces, tabs etc.
>
> > Thanks,
> >
> > Ed
> >
>
> --
> There is no national science just as there is no national
> multiplication table; what is national is no longer science.
> -- Anton Checov
Thanks F.L., P.D., N.A. Neon's solution seems the easiest to me. I need
this only because I can't get control chars into the replacement string.
The replacement can be a bare RET but you can't replace with less than
nothing, i.e. replacing a regexp with nothing and then backspacing to
get rid of the blank line. Could this be related to the fact that
C-<spacebar> is no longer bound to 'set-mark'? It used to be, but now
C-h k reports nothing, (in fact, doesn't react at all) to that keypress.
Ed, child of four.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: regexp to collapse multiple blank lines into one
2005-10-09 18:36 ` regexp " B. T. Raven
@ 2005-10-10 16:35 ` Kevin Rodgers
2005-10-10 17:28 ` Neon Absentius
2005-10-10 18:02 ` Peter Dyballa
0 siblings, 2 replies; 14+ messages in thread
From: Kevin Rodgers @ 2005-10-10 16:35 UTC (permalink / raw)
B. T. Raven wrote:
> "Neon Absentius" <absent@sdf.lonestar.org> wrote in message
> news:mailman.10556.1128865819.20277.help-gnu-emacs@gnu.org...
>>The following seems to work
>>
>>C-M-% \(^C-qC-j\)+ RET \1 RET
>>
>>Provided of course that your lines are really blank and do not contain
>>any spaces, tabs etc.
>
> Thanks F.L., P.D., N.A. Neon's solution seems the easiest to me. I need
> this only because I can't get control chars into the replacement string.
> The replacement can be a bare RET but you can't replace with less than
> nothing, i.e. replacing a regexp with nothing and then backspacing to
> get rid of the blank line.
Why can't you use the same technique to put a control character into the
replacement string as Neon suggests for the search string/regexp
(namely, C-q)?
I'll admit, I don't understand why that solution works: it appears to
replace the matched sequence of LFD characters with itself, instead of
replacing it with just a single LFD character (or nothing at all,
depending on the desired result).
> Could this be related to the fact that
> C-<spacebar> is no longer bound to 'set-mark'? It used to be, but now
> C-h k reports nothing, (in fact, doesn't react at all) to that keypress.
No. When you type C-SPC, your terminal is no longer sending anything
for Emacs to interpret. Try C-@ instead.
--
Kevin Rodgers
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: regexp to collapse multiple blank lines into one
2005-10-10 16:35 ` Kevin Rodgers
@ 2005-10-10 17:28 ` Neon Absentius
2005-10-10 18:33 ` Kevin Rodgers
2005-10-10 18:02 ` Peter Dyballa
1 sibling, 1 reply; 14+ messages in thread
From: Neon Absentius @ 2005-10-10 17:28 UTC (permalink / raw)
On Mon, Oct 10, 2005 at 10:35:01AM -0600, Kevin Rodgers wrote:
> B. T. Raven wrote:
> > "Neon Absentius" <absent@sdf.lonestar.org> wrote in message
> > news:mailman.10556.1128865819.20277.help-gnu-emacs@gnu.org...
> >>The following seems to work
> >>
> >>C-M-% \(^C-qC-j\)+ RET \1 RET
> >>
> >>Provided of course that your lines are really blank and do not contain
> >>any spaces, tabs etc.
> >
> > Thanks F.L., P.D., N.A. Neon's solution seems the easiest to me. I need
> > this only because I can't get control chars into the replacement string.
> > The replacement can be a bare RET but you can't replace with less than
> > nothing, i.e. replacing a regexp with nothing and then backspacing to
> > get rid of the blank line.
>
> Why can't you use the same technique to put a control character into the
> replacement string as Neon suggests for the search string/regexp
> (namely, C-q)?
>
Actually that also works. The reason I used "\1" is that I had
already grouped the regexp so it saved me typing.
> I'll admit, I don't understand why that solution works: it appears to
> replace the matched sequence of LFD characters with itself, instead of
> replacing it with just a single LFD character (or nothing at all,
> depending on the desired result).
>
I don't understand what you don't understand :) My solutions replaces
one or more occurences of a regexp with a single occurence. Perhaps
you are worried abour efficiency? that if there is a single occurence
I replace it with itself? In that case you are right. A better
solution would be better:
C-M-% \(^C-qC-j\)\{2,\} RET \1 RET
--
There is no national science just as there is no national
multiplication table; what is national is no longer science.
-- Anton Checov
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: regexp to collapse multiple blank lines into one
2005-10-10 16:35 ` Kevin Rodgers
2005-10-10 17:28 ` Neon Absentius
@ 2005-10-10 18:02 ` Peter Dyballa
1 sibling, 0 replies; 14+ messages in thread
From: Peter Dyballa @ 2005-10-10 18:02 UTC (permalink / raw)
Cc: help-gnu-emacs
Am 10.10.2005 um 18:35 schrieb Kevin Rodgers:
> >>C-M-% \(^C-qC-j\)+ RET \1 RET
> >>
> I'll admit, I don't understand why that solution works: it appears to
>
But it's so easy: it's exactly one newline between the parentheses!
Outside is the plus. So up to many occurences of newline get replaced
by exactly one.
--
Greetings
Pete
War springs from unseen and generally insignificant causes.
-Anonymous
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: regexp to collapse multiple blank lines into one
2005-10-10 17:28 ` Neon Absentius
@ 2005-10-10 18:33 ` Kevin Rodgers
2005-10-10 19:06 ` Neon Absentius
[not found] ` <mailman.10719.1128971211.20277.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 14+ messages in thread
From: Kevin Rodgers @ 2005-10-10 18:33 UTC (permalink / raw)
Neon Absentius wrote:
> Actually that also works. The reason I used "\1" is that I had
> already grouped the regexp so it saved me typing.
...
> I don't understand what you don't understand :) My solutions replaces
> one or more occurences of a regexp with a single occurence. Perhaps
> you are worried abour efficiency?
No, it was just that I read \(...\)+ as \(...+\).
\(...\)+ is suspect to me, since in the general case ... can match
different literal strings in the buffer and it wasn't obvious to me what
\1 should refer to. I know see that the Emacs manual says
If a particular `\( ... \)' construct matches more than once
(which can easily happen if it is followed by `*'), only the last
match is recorded.
but I guess I was effected by my experience with a proprietary text
processing language (which shall remain nameless) that prohibited such
references.
In any case, replacing \(^ C-q C-j \)+ with \1 is 10 key strokes, which
is actually more typing than if you were to replace ^ C-q C-j + with C-q
C-j (6 keys).
--
Kevin Rodgers
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: regexp to collapse multiple blank lines into one
2005-10-10 18:33 ` Kevin Rodgers
@ 2005-10-10 19:06 ` Neon Absentius
[not found] ` <mailman.10719.1128971211.20277.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 14+ messages in thread
From: Neon Absentius @ 2005-10-10 19:06 UTC (permalink / raw)
On Mon, Oct 10, 2005 at 12:33:50PM -0600, Kevin Rodgers wrote:
>
> In any case, replacing \(^ C-q C-j \)+ with \1 is 10 key strokes, which
> is actually more typing than if you were to replace ^ C-q C-j + with C-q
> C-j (6 keys).
>
Yes indeed. I didn't think of it. I just wrote the first think
that came to my mind and it worked. About the keystrokes though I
think that C-q shoud count for more than 1 keystroke; perhaps not 2
keystrokes but 1.5 so your solution has really 8 keystrokes :).
Still my solution is not that bad because it is general: a simple
modification of it will work whenever one whishes to replace
multiple occurences of a regexp with a single occurence.
Also on most files using ^ C-q C-j \{2,\} will save you a lot a
keystrokes because one won't have to press all these "y".
--
There is no national science just as there is no national
multiplication table; what is national is no longer science.
-- Anton Checov
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: repexp to collapse multiple blank lines into one
2005-10-09 12:27 repexp to collapse multiple blank lines into one B. T. Raven
` (3 preceding siblings ...)
[not found] ` <mailman.10556.1128865819.20277.help-gnu-emacs@gnu.org>
@ 2005-10-10 20:59 ` David Hansen
2005-10-11 2:09 ` Neon Absentius
4 siblings, 1 reply; 14+ messages in thread
From: David Hansen @ 2005-10-10 20:59 UTC (permalink / raw)
On Sun, 09 Oct 2005 12:27:07 GMT B. T. Raven wrote:
[...]
And i thought he wrote his novels on a rusty typewriter... ;-)
David
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: repexp to collapse multiple blank lines into one
2005-10-10 20:59 ` repexp " David Hansen
@ 2005-10-11 2:09 ` Neon Absentius
0 siblings, 0 replies; 14+ messages in thread
From: Neon Absentius @ 2005-10-11 2:09 UTC (permalink / raw)
On Mon, Oct 10, 2005 at 10:59:53PM +0200, David Hansen wrote:
> On Sun, 09 Oct 2005 12:27:07 GMT B. T. Raven wrote:
>
> [...]
>
> And i thought he wrote his novels on a rusty typewriter... ;-)
Well, Emacs has a long and rich history!
--
There is no national science just as there is no national
multiplication table; what is national is no longer science.
-- Anton Checov
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: regexp to collapse multiple blank lines into one
[not found] ` <mailman.10719.1128971211.20277.help-gnu-emacs@gnu.org>
@ 2005-10-11 22:21 ` Tim X
2005-10-12 1:14 ` Neon Absentius
0 siblings, 1 reply; 14+ messages in thread
From: Tim X @ 2005-10-11 22:21 UTC (permalink / raw)
Neon Absentius <absent@sdf.lonestar.org> writes:
> On Mon, Oct 10, 2005 at 12:33:50PM -0600, Kevin Rodgers wrote:
>
> >
> > In any case, replacing \(^ C-q C-j \)+ with \1 is 10 key strokes, which
> > is actually more typing than if you were to replace ^ C-q C-j + with C-q
> > C-j (6 keys).
> >
>
> Yes indeed. I didn't think of it. I just wrote the first think
> that came to my mind and it worked. About the keystrokes though I
> think that C-q shoud count for more than 1 keystroke; perhaps not 2
> keystrokes but 1.5 so your solution has really 8 keystrokes :).
So, in that case, is A 1.5 keystrokes while a is only 1?
Tim
--
Tim Cross
The e-mail address on this message is FALSE (obviously!). My real e-mail is
to a company in Australia called rapttech and my login is tcross - if you
really need to send mail, you should be able to work it out!
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: regexp to collapse multiple blank lines into one
2005-10-11 22:21 ` Tim X
@ 2005-10-12 1:14 ` Neon Absentius
0 siblings, 0 replies; 14+ messages in thread
From: Neon Absentius @ 2005-10-12 1:14 UTC (permalink / raw)
On Wed, Oct 12, 2005 at 08:21:29AM +1000, Tim X wrote:
> Neon Absentius <absent@sdf.lonestar.org> writes:
>
> > On Mon, Oct 10, 2005 at 12:33:50PM -0600, Kevin Rodgers wrote:
> >
> > >
> > > In any case, replacing \(^ C-q C-j \)+ with \1 is 10 key strokes, which
> > > is actually more typing than if you were to replace ^ C-q C-j + with C-q
> > > C-j (6 keys).
> > >
> >
> > Yes indeed. I didn't think of it. I just wrote the first think
> > that came to my mind and it worked. About the keystrokes though I
> > think that C-q shoud count for more than 1 keystroke; perhaps not 2
> > keystrokes but 1.5 so your solution has really 8 keystrokes :).
>
> So, in that case, is A 1.5 keystrokes while a is only 1?
>
Yes. Or maybe 1.3 since A is somewhat easier to type than C-a ;)
--
There is no national science just as there is no national
multiplication table; what is national is no longer science.
-- Anton Checov
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2005-10-12 1:14 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-09 12:27 repexp to collapse multiple blank lines into one B. T. Raven
2005-10-09 12:59 ` Friedrich Laher
2005-10-09 13:01 ` Peter Dyballa
2005-10-09 13:44 ` Neon Absentius
[not found] ` <mailman.10556.1128865819.20277.help-gnu-emacs@gnu.org>
2005-10-09 18:36 ` regexp " B. T. Raven
2005-10-10 16:35 ` Kevin Rodgers
2005-10-10 17:28 ` Neon Absentius
2005-10-10 18:33 ` Kevin Rodgers
2005-10-10 19:06 ` Neon Absentius
[not found] ` <mailman.10719.1128971211.20277.help-gnu-emacs@gnu.org>
2005-10-11 22:21 ` Tim X
2005-10-12 1:14 ` Neon Absentius
2005-10-10 18:02 ` Peter Dyballa
2005-10-10 20:59 ` repexp " David Hansen
2005-10-11 2:09 ` Neon Absentius
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).