emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: John Kitchin <jkitchin@andrew.cmu.edu>
To: marvin doyley <marvinpas@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: Converting paragraph to plain lis
Date: Wed, 16 Dec 2015 06:38:51 -0500	[thread overview]
Message-ID: <m2vb7yk4hg.fsf@andrew.cmu.edu> (raw)
In-Reply-To: <542BCA5A-1AC1-454B-8292-C6F196BB57BB@gmail.com>

Here is a solution that works on your paragraph.

#+BEGIN_SRC emacs-lisp
(defun explode-paragraph ()
  (interactive)
  (let (start end)
    ;; narrow to paragraph
    (backward-paragraph) (forward-line)
    (setq start (point))
    (forward-paragraph) (previous-line)
    (setq end (point))

    ;; now move by sentence, insert number and \n. at the end go to beginning
    ;; insert a number and use C-cC-c to renumber the list.
    (save-restriction
      (narrow-to-region start end)
      (goto-char (point-min))
      (while (< (point) (point-max))
        (forward-sentence)
        (insert "\n1. "))
      (goto-char (point-min))
      (insert "1. ")
      (org-ctrl-c-ctrl-c))))

(defun unfill-paragraph ()
  "Unfill paragraph at or after point."
  (interactive "*")
  (let ((fill-column most-positive-fixnum))
    (fill-paragraph nil (region-active-p))))

(defun list-to-paragraph ()
  "Convert list at point to a paragraph."
  (interactive)
  ;; make sure we are at the beginning of the list
  (beginning-of-line)
  (let ((element (org-element-context))
        contents)
    (when (eq 'item (car element))
      (setq element (org-element-property :parent (org-element-context)))
      (goto-char
       (org-element-property
        :begin
        element)))
    ;; collect each sentence, minus the numbers.
    (setq contents (loop for node in
                         (org-element-property :structure element)
                         collect
                         ;; remove number and space
                         (replace-regexp-in-string
                          (regexp-quote (nth 2 node)) ""
                          (buffer-substring (nth 0 node)
                                            (nth 6 node)))))
    ;; replace the list, and then unfill the paragraph.
    (setf (buffer-substring (org-element-property :begin element)
                            (- (org-element-property :end element) 1))
          (mapconcat 'identity contents ""))
    (goto-char (org-element-property :begin element))
    (unfill-paragraph)))
#+END_SRC

marvin doyley writes:

> Hi there,
>
> Does anybody know how to convert a paragraph to a plain list, and vice versa. For example, I would like to convert
>
> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse viverra consectetur euismod. Donec non tempor turpis.
>
> to
>
> 1. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
>  2.  Suspendisse viverra consectetur euismod.
> 3.  Donec non tempor turpis.
>
> In one key stroke, this would speed up my brain storming process.
>
> Thanks,
> M

--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

  parent reply	other threads:[~2015-12-16 11:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-16  0:27 Converting paragraph to plain lis marvin doyley
2015-12-16  8:22 ` Marcin Borkowski
2015-12-16 11:38 ` John Kitchin [this message]
2015-12-16 14:15   ` Fwd: " Doyley, Marvin M.

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=m2vb7yk4hg.fsf@andrew.cmu.edu \
    --to=jkitchin@andrew.cmu.edu \
    --cc=emacs-orgmode@gnu.org \
    --cc=marvinpas@gmail.com \
    /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).