emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Convert list to paragraph
@ 2011-08-26 20:01 Derek Thomas
  2011-08-26 21:27 ` Nick Dokos
  0 siblings, 1 reply; 5+ messages in thread
From: Derek Thomas @ 2011-08-26 20:01 UTC (permalink / raw)
  To: emacs-orgmode

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.

Thanks,

Derek

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

* Re: Convert list to paragraph
  2011-08-26 20:01 Convert list to paragraph Derek Thomas
@ 2011-08-26 21:27 ` Nick Dokos
  2011-08-27  0:59   ` Nicolas Goaziou
  0 siblings, 1 reply; 5+ messages in thread
From: Nick Dokos @ 2011-08-26 21:27 UTC (permalink / raw)
  To: Derek Thomas; +Cc: nicholas.dokos, emacs-orgmode

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.

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

* Re: Convert list to paragraph
  2011-08-26 21:27 ` Nick Dokos
@ 2011-08-27  0:59   ` Nicolas Goaziou
  2011-08-27 14:16     ` Derek Thomas
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolas Goaziou @ 2011-08-27  0:59 UTC (permalink / raw)
  To: nicholas.dokos; +Cc: emacs-orgmode, Derek Thomas

Hello,

Nick Dokos <nicholas.dokos@hp.com> writes:

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

[...]

> ngz will probably suggest changes and improvements on this basic model.

Well, just that "^[ \t]*\\+\\($\\| +\\)" is a more accurate search
string. Otherwise, it could stop too early.

Now, this might also be a solution for Thomas S. Dye's
"paralistification" problem[1]: in an export hook, transform lists
without a preceding blank line into paralist forms, thanks to
`org-list-to-generic'.

Regards,

[1] http://permalink.gmane.org/gmane.emacs.orgmode/46151

-- 
Nicolas Goaziou

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

* Re: Convert list to paragraph
  2011-08-27  0:59   ` Nicolas Goaziou
@ 2011-08-27 14:16     ` Derek Thomas
  2011-08-27 16:32       ` Nick Dokos
  0 siblings, 1 reply; 5+ messages in thread
From: Derek Thomas @ 2011-08-27 14:16 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: nicholas.dokos, emacs-orgmode

> Nick Dokos <nicholas.dokos@hp.com> writes:
>
>> (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))

This looks like it will do what I want.  Is there any way to restrict
this export option to certain org files?  Thanks,

Derek

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

* Re: Convert list to paragraph
  2011-08-27 14:16     ` Derek Thomas
@ 2011-08-27 16:32       ` Nick Dokos
  0 siblings, 0 replies; 5+ messages in thread
From: Nick Dokos @ 2011-08-27 16:32 UTC (permalink / raw)
  To: Derek Thomas; +Cc: emacs-orgmode, nicholas.dokos, Nicolas Goaziou

[-- Attachment #1: Type: text/plain, Size: 1164 bytes --]

Derek Thomas <derekcthomas@gmail.com> wrote:

> > Nick Dokos <nicholas.dokos@hp.com> writes:
> >
> >> (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))
> 
> 
> This looks like it will do what I want.  Is there any way to restrict
> this export option to certain org files?  Thanks,
> 

With elisp you can do anything: just a small matter of
programming (TM).  E.g. you can set up a list with the
files that you want this to apply to and then check in
org-lists-to-paragraphs whether the file you are
exporting is in the list: if not, don't do
anything. Here's a quick and rather dirty
implementation - a minor variation on the above:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: lists to paragraphs --]
[-- Type: text/x-lisp, Size: 1094 bytes --]

(setq ndk-list-to-paragraph-file-list '("/home/nick/src/org/list/to-paragraph/derek-thomas.org"))

(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 ndk-buffer-file-name ()
  ;;; if called from inside org-export-preprocess-string
  ;;; source-buffer will be bound to the original org buffer, not the temp buffer
  ;;; otherwise assume we want to operate on the current buffer
  ;;; don't bother telling me how ugly this is - I know
  ;;; but do bother telling me about a better way to do it.
  (if (boundp 'source-buffer)
      (buffer-file-name source-buffer)
    (buffer-file-name (current-buffer))))

(defun org-lists-to-paragraphs ()
  (if (not (member (ndk-buffer-file-name) ndk-list-to-paragraph-file-list))
      nil
    (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))

[-- Attachment #3: Type: text/plain, Size: 256 bytes --]


but depending on your needs, you might want to do it
differently.  It is just a matter of figuring out what
criteria you want to apply and then figuring out how
to implement those criteria.

Nick

PS Is there a better way to get the original buffer
name?

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

end of thread, other threads:[~2011-08-27 16:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-26 20:01 Convert list to paragraph Derek Thomas
2011-08-26 21:27 ` Nick Dokos
2011-08-27  0:59   ` Nicolas Goaziou
2011-08-27 14:16     ` Derek Thomas
2011-08-27 16:32       ` Nick Dokos

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