emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nick Dokos <nicholas.dokos@hp.com>
To: Derek Thomas <derekcthomas@gmail.com>
Cc: nicholas.dokos@hp.com, emacs-orgmode@gnu.org
Subject: Re: Convert list to paragraph
Date: Fri, 26 Aug 2011 17:27:07 -0400	[thread overview]
Message-ID: <5350.1314394027@alphaville.americas.hpqcorp.net> (raw)
In-Reply-To: Message from Derek Thomas <derekcthomas@gmail.com> of "Fri, 26 Aug 2011 15:01:39 CDT." <CALDRGc-nUs3V_TPsbhyRfBw1mQrqY0Jdeu0To+WDPr_mRZkCjg@mail.gmail.com>

Derek Thomas <derekcthomas@gmail.com> 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	other threads:[~2011-08-26 21:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-26 20:01 Convert list to paragraph Derek Thomas
2011-08-26 21:27 ` Nick Dokos [this message]
2011-08-27  0:59   ` Nicolas Goaziou
2011-08-27 14:16     ` Derek Thomas
2011-08-27 16:32       ` Nick Dokos

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5350.1314394027@alphaville.americas.hpqcorp.net \
    --to=nicholas.dokos@hp.com \
    --cc=derekcthomas@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

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).