emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Convert list to paragraph


From: Nick Dokos
Subject: Re: [O] Convert list to paragraph
Date: Fri, 26 Aug 2011 17:27:07 -0400

Derek Thomas <address@hidden> 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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]