From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nick Dokos Subject: Re: Convert list to paragraph Date: Fri, 26 Aug 2011 17:27:07 -0400 Message-ID: <5350.1314394027@alphaville.americas.hpqcorp.net> References: Reply-To: nicholas.dokos@hp.com Return-path: Received: from eggs.gnu.org ([140.186.70.92]:55056) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qx3vi-0004U0-P5 for emacs-orgmode@gnu.org; Fri, 26 Aug 2011 17:27:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qx3vh-0002pX-93 for emacs-orgmode@gnu.org; Fri, 26 Aug 2011 17:27:10 -0400 Received: from g4t0017.houston.hp.com ([15.201.24.20]:28538 helo=g1u1820.austin.hp.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qx3vh-0002pM-2d for emacs-orgmode@gnu.org; Fri, 26 Aug 2011 17:27:09 -0400 In-Reply-To: Message from Derek Thomas of "Fri, 26 Aug 2011 15:01:39 CDT." List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Derek Thomas Cc: nicholas.dokos@hp.com, emacs-orgmode@gnu.org Derek Thomas wrote: > I find it convenient to outline LaTeX documents using org-mode. I > often find myself with every sentence in a paragraph as an item in an > org list. This makes it convenient to manipulate the paragraph. Is > it possible to export a certain list bullet style (+,-, etc.) as a > paragraph instead of as a list? Here's an example of what I would > like to achieve: > > + Here is my first sentence. > + Another sentence. > + One more sentence. > > would export to: > > Here is my first sentence. Another sentence. One more sentence. > The following is probably only a zeroth approximation but it works in the simple case above. --8<---------------cut here---------------start------------->8--- (defun org-list-to-paragraph () "Convert the list at point into a paragraph." (interactive) (insert (org-list-to-generic (org-list-parse-list t) '(:ustart "" :splice t :isep " " :nobr t )))) (defun org-lists-to-paragraphs () (goto-char (point-min)) (condition-case nil (while (org-list-search-forward "+ ") (org-list-to-paragraph)) (error nil))) (add-hook 'org-export-preprocess-hook (function org-lists-to-paragraphs)) --8<---------------cut here---------------end--------------->8--- The hook is run as part of the export process. The function looks for lists with the "+ " regexp [fn:1] and applies the org-list-to-paragraph function on each; it gets an error when it cannot find any more which it catches and returns nil. The org-list-to-paragraph function parses the list and deletes it (the t argument) and splices it together. Note that these transformations are done in a temp buffer during export, so the original file remains unchanged. But you can call either of the functions in the original buffer and make the changes there. ngz will probably suggest changes and improvements on this basic model. Nick Footnotes: [fn:1] Note that because the + is at the beginning, it loses its special regexp meaning - if you modify the regexp, you will probably have to quote it appropriately, but that's left as an exercise - and note that the elisp manual warns against this practice: ,---- | *Please note:* For historical compatibility, special characters are | treated as ordinary ones if they are in contexts where their special | meanings make no sense. For example, `*foo' treats `*' as ordinary | since there is no preceding expression on which the `*' can act. It is | poor practice to depend on this behavior; quote the special character | anyway, regardless of where it appears. `---- so don't do as I do, do as I say.