From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Passer By Newsgroups: gmane.emacs.help Subject: Re: Looking for (fill-paragraph) Like Functions Date: Fri, 01 Dec 2006 10:29:39 GMT Organization: EasyNews, UseNet made Easy! Message-ID: <87zma7lxil.fsf@localhost.localdomain> References: <87d576msui.fsf@localhost.localdomain> <20061129163507.0ebf519d@litshi.luna.local> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1164969797 3714 80.91.229.2 (1 Dec 2006 10:43:17 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 1 Dec 2006 10:43:17 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Dec 01 11:43:14 2006 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1Gq5rH-0005jQ-Mg for geh-help-gnu-emacs@m.gmane.org; Fri, 01 Dec 2006 11:43:07 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Gq5rH-0003ST-9V for geh-help-gnu-emacs@m.gmane.org; Fri, 01 Dec 2006 05:43:07 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!headwall.stanford.edu!newsfeed.news2me.com!news-in-01.newsfeed.easynews.com!easynews.com!easynews!easynews-local!fe01.news.easynews.com.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 113 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 Original-X-Complaints-To: abuse@easynews.com X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly. Original-Xref: shelby.stanford.edu gnu.emacs.help:143562 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:39164 Archived-At: Perry Smith writes: > On Nov 29, 2006, at 8:35 AM, Micha Feigin wrote: > > > On Wed, 29 Nov 2006 10:48:23 GMT > > Passer By 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) > > (which would match 1, 2, 3 or a, > b, c. Maybe even i, ii, iii, iv,...) > > > 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.