all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Looking for (fill-paragraph) Like Functions
@ 2006-11-29 10:48 Passer By
  2006-11-29 11:05 ` Mathias Dahl
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Passer By @ 2006-11-29 10:48 UTC (permalink / raw)





My first learned function and loved function of emacs was the M-q but
there are cases where M-q doesn't do exactly what i want and i would
like to make an improved version or find one somewhere.


Here is an example of what i would want my improved (fill-paragraph)
to do.


1) this is a sentence
2) this is another sentence in a list 
3) this is a sentence is long i would like to hit M-q now but emacs will not just rap this line it will rap all the lines and that makes me mad
4) this is another line M-q here would be good if it would make all the lines nice up to 1)


I would like my M-q to work for any "bulleted" list like this

so the above when My M-q'ed any place in the list would go to 

1) this is a sentence
2) this is another sentence in a list 
3) this is a sentence is long i would like to hit M-q now but emacs
   will not just rap this line it will rap all the lines and that
   makes me mad
4) this is another line M-q here would be good if it would make all
   the lines nice up to 1)

instead of this 


1) this is a sentence 2) this is another sentence in a list 3) this is
a sentence is long i would like to hit M-q now but emacs will not just
rap this line it will rap all the lines and that makes me mad 4) this
is another line M-q here would be good if it would make all the lines
nice up to 1)


Thanks!

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Looking for (fill-paragraph) Like Functions
  2006-11-29 10:48 Looking for (fill-paragraph) Like Functions Passer By
@ 2006-11-29 11:05 ` Mathias Dahl
  2006-11-29 14:35 ` Micha Feigin
  2006-11-29 16:19 ` Floyd L. Davidson
  2 siblings, 0 replies; 10+ messages in thread
From: Mathias Dahl @ 2006-11-29 11:05 UTC (permalink / raw)


Passer By <sender@sender.send> writes:

> 1) this is a sentence
> 2) this is another sentence in a list 
> 3) this is a sentence is long i would like to hit M-q now but emacs
>    will not just rap this line it will rap all the lines and that
>    makes me mad
> 4) this is another line M-q here would be good if it would make all
>    the lines nice up to 1)
>
> instead of this 
>
>
> 1) this is a sentence 2) this is another sentence in a list 3) this is
> a sentence is long i would like to hit M-q now but emacs will not just
> rap this line it will rap all the lines and that makes me mad 4) this
> is another line M-q here would be good if it would make all the lines
> nice up to 1)

I'd be very interested in that too :)

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Looking for (fill-paragraph) Like Functions
  2006-11-29 10:48 Looking for (fill-paragraph) Like Functions Passer By
  2006-11-29 11:05 ` Mathias Dahl
@ 2006-11-29 14:35 ` Micha Feigin
  2006-11-29 15:00   ` Perry Smith
       [not found]   ` <mailman.1286.1164812410.2155.help-gnu-emacs@gnu.org>
  2006-11-29 16:19 ` Floyd L. Davidson
  2 siblings, 2 replies; 10+ messages in thread
From: Micha Feigin @ 2006-11-29 14:35 UTC (permalink / raw)


On Wed, 29 Nov 2006 10:48:23 GMT
Passer By <sender@sender.send> wrote:

> 
> 
> 
> My first learned function and loved function of emacs was the M-q but
> there are cases where M-q doesn't do exactly what i want and i would
> like to make an improved version or find one somewhere.
> 
> 
> Here is an example of what i would want my improved (fill-paragraph)
> to do.
> 
> 
> 1) this is a sentence
> 2) this is another sentence in a list 
> 3) this is a sentence is long i would like to hit M-q now but emacs will not
> just rap this line it will rap all the lines and that makes me mad 4) this is
> another line M-q here would be good if it would make all the lines nice up to
> 1)
> 

The problem is with how do you recognize the end of a paragraph? You can't use
the end of line symbol as that is the same symbol that is used to break a line
in the middle of the paragraph and there is no end of paragraph symbol for text
files (AFAIK, maybe unicode has something).

The solution is to use the latex syntax and break lines with enter and
paragraph with an empty line. I think that that will solve your problem. i.e:

This is paragraph one
second line of paragraph one

This is paragraph two.

> 
> I would like my M-q to work for any "bulleted" list like this
> 
> so the above when My M-q'ed any place in the list would go to 
> 
> 1) this is a sentence
> 2) this is another sentence in a list 
> 3) this is a sentence is long i would like to hit M-q now but emacs
>    will not just rap this line it will rap all the lines and that
>    makes me mad
> 4) this is another line M-q here would be good if it would make all
>    the lines nice up to 1)
> 
> instead of this 
> 
> 
> 1) this is a sentence 2) this is another sentence in a list 3) this is
> a sentence is long i would like to hit M-q now but emacs will not just
> rap this line it will rap all the lines and that makes me mad 4) this
> is another line M-q here would be good if it would make all the lines
> nice up to 1)
> 
> 
> Thanks!
> _______________________________________________
> help-gnu-emacs mailing list
> help-gnu-emacs@gnu.org
> http://lists.gnu.org/mailman/listinfo/help-gnu-emacs
>  
>  +++++++++++++++++++++++++++++++++++++++++++
>  This Mail Was Scanned By Mail-seCure System
>  at the Tel-Aviv University CC.
> 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Looking for (fill-paragraph) Like Functions
  2006-11-29 14:35 ` Micha Feigin
@ 2006-11-29 15:00   ` Perry Smith
       [not found]   ` <mailman.1286.1164812410.2155.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 10+ messages in thread
From: Perry Smith @ 2006-11-29 15:00 UTC (permalink / raw)
  Cc: help-gnu-emacs


On Nov 29, 2006, at 8:35 AM, Micha Feigin wrote:

> On Wed, 29 Nov 2006 10:48:23 GMT
> Passer By <sender@sender.send> wrote:
>
>>
>>
>>
>> My first learned function and loved function of emacs was the M-q but
>> there are cases where M-q doesn't do exactly what i want and i would
>> like to make an improved version or find one somewhere.
>>
>>
>> Here is an example of what i would want my improved (fill-paragraph)
>> to do.
>>
>>
>> 1) this is a sentence
>> 2) this is another sentence in a list
>> 3) this is a sentence is long i would like to hit M-q now but  
>> emacs will not
>> just rap this line it will rap all the lines and that makes me mad  
>> 4) this is
>> another line M-q here would be good if it would make all the lines  
>> nice up to
>> 1)
>>
>
> The problem is with how do you recognize the end of a paragraph?  
> You can't use
> the end of line symbol as that is the same symbol that is used to  
> break a line
> in the middle of the paragraph and there is no end of paragraph  
> symbol for text
> files (AFAIK, maybe unicode has something).
>
> The solution is to use the latex syntax and break lines with enter and
> paragraph with an empty line. I think that that will solve your  
> problem. i.e:
>
> This is paragraph one
> second line of paragraph one
>
> This is paragraph two.

I think it is "do-able" but I don't want to volunteer to do it.  From  
my perspective, the
first task is to recognize that you are doing a list.  The pattern  
would be something flexible
broken into pieces (which you can do with regex).  Starting with ^ as  
the anchor of
the beginning of the line, the pattern to notice a list would be  
something like (I'll just
use english to describe it)
<pattern to span white space>
<pattern to span numbering system> (which would match 1, 2, 3 or a,  
b, c.  Maybe even i, ii, iii, iv,...)
<pattern to span ')' and other things that may be used at that point>

After having found the first of these, the start of the next time  
would match the same pattern
but with the second item twiddled to be the next in the sequence.   
Again, all of this is "do-able" but
rather tedious.

To continue, this match would mark the start of the next item -- and  
the end of the previous item.
Then narrow the region to be just the previous item, do a fill  
paragraph, restore to the original region,
and continue.

So, done correctly, it could actually cope with indented lists inside  
of lists.

BUT... my guess is it would take me several days to come up with all  
this.  I would guess it would take
you at least that long.  And, as this reply points out, most people  
just put a blank line between items and
just avoid the problem.

Perry Smith ( pedz@easesoftware.com )
Ease Software, Inc. ( http://www.easesoftware.com )

Low cost SATA Disk Systems for IBMs p5, pSeries, and RS/6000 AIX systems

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Looking for (fill-paragraph) Like Functions
  2006-11-29 10:48 Looking for (fill-paragraph) Like Functions Passer By
  2006-11-29 11:05 ` Mathias Dahl
  2006-11-29 14:35 ` Micha Feigin
@ 2006-11-29 16:19 ` Floyd L. Davidson
  2006-11-29 16:54   ` Markus Triska
  2 siblings, 1 reply; 10+ messages in thread
From: Floyd L. Davidson @ 2006-11-29 16:19 UTC (permalink / raw)


Passer By <sender@sender.send> wrote:
>My first learned function and loved function of emacs was the M-q but
>there are cases where M-q doesn't do exactly what i want and i would
>like to make an improved version or find one somewhere.
>
>Here is an example of what i would want my improved (fill-paragraph)
>to do.
>
>1) this is a sentence
>2) this is another sentence in a list
>3) this is a sentence is long i would like to hit M-q now but emacs will not just rap this line it will rap all the lines and that makes me mad
>4) this is another line M-q here would be good if it would make all the lines nice up to 1)
>
>I would like my M-q to work for any "bulleted" list like this

Between marking the "bullet" pattern, the indent, and the end of
the item, there are so many varieties of bulleted lists that a
simple generic function cannot suffice.  Instead one would need
to either restrict it to certain constructs or provide an
extensive pre-configuration list.  Which probably means it just
isn't practical to use such a function.  For example, if you
make an error or otherwise decide to change the configuration,
editing the results will be far more painful than not.

Likewise there are a few tricks one can learn that make doing it
manually an easy enough task.  One is to enable "text-mode" and
(if it is not by default) set adaptive-fill-mode to true.

To reformat your list above, items 1) and 2) need only a proper
indent, and 3) is the interesting one.  So I'll describe doing
that one step by step (assuming that basic commands, like
navigation and how to insert blank lines, are second nature and
need not be mentioned).

First separate that line from the line above and below it:

    2) this is another sentence in a list

    3) this is a sentence is long i would like to hit M-q ...

    4) this is another line M-q here would be good if it ...

Now, work on item 3 alone.  Start by reformatting it, and it
will look like this (in this case the fill column is 55):

    3) this is a sentence is long i would like to hit
    M-q now but emacs will not just rap this line it
    will rap all the lines and that makes me mad

Then separate the top line for the other lines:

    3) this is a sentence is long i would like to hit

    M-q now but emacs will not just rap this line it
    will rap all the lines and that makes me mad

Now indent the second line to the appropriate column:

    3) this is a sentence is long i would like to hit

       M-q now but emacs will not just rap this line it
    will rap all the lines and that makes me mad

Now use M-q to reformat the second and third lines:

    3) this is a sentence is long i would like to hit

       M-q now but emacs will not just rap this line it
       will rap all the lines and that makes me mad

And obviously at that point simply deleting the excess blank
lines provides the desired result.

-- 
Floyd L. Davidson            <http://www.apaflo.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska)                         floyd@apaflo.com

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Looking for (fill-paragraph) Like Functions
  2006-11-29 16:19 ` Floyd L. Davidson
@ 2006-11-29 16:54   ` Markus Triska
  2006-11-29 23:01     ` Floyd L. Davidson
  0 siblings, 1 reply; 10+ messages in thread
From: Markus Triska @ 2006-11-29 16:54 UTC (permalink / raw)


floyd@apaflo.com (Floyd L. Davidson) writes:

> Then separate the top line for the other lines:
>
>     3) this is a sentence is long i would like to hit
>
>     M-q now but emacs will not just rap this line it
>     will rap all the lines and that makes me mad

This step is unnecessary with adaptive-fill-mode non-nil.

All the best,
Markus Triska

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Looking for (fill-paragraph) Like Functions
  2006-11-29 16:54   ` Markus Triska
@ 2006-11-29 23:01     ` Floyd L. Davidson
  2006-11-29 23:19       ` Markus Triska
  0 siblings, 1 reply; 10+ messages in thread
From: Floyd L. Davidson @ 2006-11-29 23:01 UTC (permalink / raw)


Markus Triska <triska@gmx.at> wrote:
>floyd@apaflo.com (Floyd L. Davidson) writes:
>
>> Then separate the top line for the other lines:
>>
>>     3) this is a sentence is long i would like to hit
>>
>>     M-q now but emacs will not just rap this line it
>>     will rap all the lines and that makes me mad
>
>This step is unnecessary with adaptive-fill-mode non-nil.

I use XEmacs, and have not verified this for Emacs.

It is necessary if the bulleted line is to have less indent than
the rest of the paragraph.  This is a reformatted paragraph if
they are not separated:

       3) this is a sentence is long i would like to hit
       M-q now but emacs will not just rap this line it
       will rap all the lines and that makes me mad

This is effected by separating, and then indenting the
second line before reformatting and deleting the blank line:

       3) this is a sentence is long i would like to hit
          M-q now but emacs will not just rap this line
          it will rap all the lines and that makes me
          mad

-- 
Floyd L. Davidson            <http://www.apaflo.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska)                         floyd@apaflo.com

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Looking for (fill-paragraph) Like Functions
  2006-11-29 23:01     ` Floyd L. Davidson
@ 2006-11-29 23:19       ` Markus Triska
  2006-11-30  7:29         ` Floyd L. Davidson
  0 siblings, 1 reply; 10+ messages in thread
From: Markus Triska @ 2006-11-29 23:19 UTC (permalink / raw)


floyd@apaflo.com (Floyd L. Davidson) writes:

> It is necessary if the bulleted line is to have less indent

Not with adaptive-fill-mode and GNU Emacs 22.0.90.10, where M-q on

    3) this is a long sentence.  i would like to hit
       M-q now and emacs will wrap this line it
    will wrap the lines and it works perfectly

gives:

    3) this is a long sentence.  i would like to hit M-q now and emacs
       will wrap this line it will wrap the lines and it works
       perfectly


All the best,
Markus Triska

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Looking for (fill-paragraph) Like Functions
  2006-11-29 23:19       ` Markus Triska
@ 2006-11-30  7:29         ` Floyd L. Davidson
  0 siblings, 0 replies; 10+ messages in thread
From: Floyd L. Davidson @ 2006-11-30  7:29 UTC (permalink / raw)


Markus Triska <triska@gmx.at> wrote:
>floyd@apaflo.com (Floyd L. Davidson) writes:
>
>> It is necessary if the bulleted line is to have less indent
>
>Not with adaptive-fill-mode and GNU Emacs 22.0.90.10, where M-q on

Seems that XEmacs and Emacs do indeed have a difference in the
fill-paragraph command.  It isn't specific to a bulleted list as
such, it's just that in Emacs the indent on the second line of
*any* paragraph will be retained for the rest of the paragraph,
but not with XEmacs, which will indent according to the first
line.  I didn't look into it farther than that, and don't know
but what XEmacs might have a simple way to change that behavior.

I can see where that might occasionally cause a problem, but
overall it looks nice to me!

>    3) this is a long sentence.  i would like to hit
>       M-q now and emacs will wrap this line it
>    will wrap the lines and it works perfectly
>
>gives:
>
>    3) this is a long sentence.  i would like to hit M-q now and emacs
>       will wrap this line it will wrap the lines and it works
>       perfectly
>
>All the best,
>Markus Triska

-- 
Floyd L. Davidson            <http://www.apaflo.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska)                         floyd@apaflo.com

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Looking for (fill-paragraph) Like Functions
       [not found]   ` <mailman.1286.1164812410.2155.help-gnu-emacs@gnu.org>
@ 2006-12-01 10:29     ` Passer By
  0 siblings, 0 replies; 10+ messages in thread
From: Passer By @ 2006-12-01 10:29 UTC (permalink / raw)


Perry Smith <pedz@easesoftware.com> writes:

> On Nov 29, 2006, at 8:35 AM, Micha Feigin wrote:
> 
> > On Wed, 29 Nov 2006 10:48:23 GMT
> > Passer By <sender@sender.send> wrote:
> >
> >>
> >>
> >>
> >> My first learned function and loved function of emacs was the M-q but
> >> there are cases where M-q doesn't do exactly what i want and i would
> >> like to make an improved version or find one somewhere.
> >>
> >>
> >> Here is an example of what i would want my improved (fill-paragraph)
> >> to do.
> >>
> >>
> >> 1) this is a sentence
> >> 2) this is another sentence in a list
> >> 3) this is a sentence is long i would like to hit M-q now but
> >> emacs will not
> >> just rap this line it will rap all the lines and that makes me mad
> >> 4) this is
> >> another line M-q here would be good if it would make all the lines
> >> nice up to
> >> 1)
> >>
> >
> > The problem is with how do you recognize the end of a paragraph?
> > You can't use
> > the end of line symbol as that is the same symbol that is used to
> > break a line
> > in the middle of the paragraph and there is no end of paragraph
> > symbol for text
> > files (AFAIK, maybe unicode has something).
> >
> > The solution is to use the latex syntax and break lines with enter and
> > paragraph with an empty line. I think that that will solve your
> > problem. i.e:
> >
> > This is paragraph one
> > second line of paragraph one
> >
> > This is paragraph two.
> 
> I think it is "do-able" but I don't want to volunteer to do it.  From
> my perspective, the
> first task is to recognize that you are doing a list.  The pattern
> would be something flexible
> broken into pieces (which you can do with regex).  Starting with ^ as
> the anchor of
> the beginning of the line, the pattern to notice a list would be
> something like (I'll just
> use english to describe it)
> <pattern to span white space>
> <pattern to span numbering system> (which would match 1, 2, 3 or a,
> b, c.  Maybe even i, ii, iii, iv,...)
> <pattern to span ')' and other things that may be used at that point>
> 
> After having found the first of these, the start of the next time
> would match the same pattern
> but with the second item twiddled to be the next in the sequence.
> Again, all of this is "do-able" but
> rather tedious.
> 
> To continue, this match would mark the start of the next item -- and
> the end of the previous item.
> Then narrow the region to be just the previous item, do a fill
> paragraph, restore to the original region,
> and continue.
> 
> So, done correctly, it could actually cope with indented lists inside
> of lists.
> 
> BUT... my guess is it would take me several days to come up with all
> this.  I would guess it would take
> you at least that long.  And, as this reply points out, most people
> just put a blank line between items and
> just avoid the problem.
> 
> Perry Smith ( pedz@easesoftware.com )
> Ease Software, Inc. ( http://www.easesoftware.com )
> 
> Low cost SATA Disk Systems for IBMs p5, pSeries, and RS/6000 AIX systems

I guess to make a generic function would be harder than it has to be,
i mean i could make a function that was just for bullets.

The algorith would be something like



1) Got to beginning of paragraph

2) get mask of first "word" i.e. the first string before (ignoring
   leading white space, and followed by whitespace) In this list it
   would be "[0-9]+)" But it could be "-" "+", etc, etc

3) for each "bullet" open line above the next bullet 
       run M-q on bulleted line
      
4) erase lines that were opened.



Or basically, make every section between bullets a paragraph, run M-q
on the paragraphs, clean-up (erase the blank lines).


There might be some restrictions on the list, i.e. must have leading
newline to start and a newline/EOF to end.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2006-12-01 10:29 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-11-29 10:48 Looking for (fill-paragraph) Like Functions Passer By
2006-11-29 11:05 ` Mathias Dahl
2006-11-29 14:35 ` Micha Feigin
2006-11-29 15:00   ` Perry Smith
     [not found]   ` <mailman.1286.1164812410.2155.help-gnu-emacs@gnu.org>
2006-12-01 10:29     ` Passer By
2006-11-29 16:19 ` Floyd L. Davidson
2006-11-29 16:54   ` Markus Triska
2006-11-29 23:01     ` Floyd L. Davidson
2006-11-29 23:19       ` Markus Triska
2006-11-30  7:29         ` Floyd L. Davidson

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.