emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Converting paragraph to plain lis
@ 2015-12-16  0:27 marvin doyley
  2015-12-16  8:22 ` Marcin Borkowski
  2015-12-16 11:38 ` John Kitchin
  0 siblings, 2 replies; 4+ messages in thread
From: marvin doyley @ 2015-12-16  0:27 UTC (permalink / raw)
  To: emacs-orgmode

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

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

[-- Attachment #2: Type: text/html, Size: 2151 bytes --]

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

* Re: Converting paragraph to plain lis
  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
  1 sibling, 0 replies; 4+ messages in thread
From: Marcin Borkowski @ 2015-12-16  8:22 UTC (permalink / raw)
  To: marvin doyley; +Cc: emacs-orgmode



On 2015-12-16, at 01:27, marvin doyley <marvinpas@gmail.com> wrote:

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

1. A keyboard macro, or
2. Some elisp involving =forward-sentence=.

I don't have time to write this now (I have a lecture soon), but I might
e.g. in the afternoon, if there's still demand.

> Thanks,
> M

Hth,

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University

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

* Re: Converting paragraph to plain lis
  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
  2015-12-16 14:15   ` Fwd: " Doyley, Marvin M.
  1 sibling, 1 reply; 4+ messages in thread
From: John Kitchin @ 2015-12-16 11:38 UTC (permalink / raw)
  To: marvin doyley; +Cc: emacs-orgmode

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

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

* Fwd:  Converting paragraph to plain lis
  2015-12-16 11:38 ` John Kitchin
@ 2015-12-16 14:15   ` Doyley, Marvin M.
  0 siblings, 0 replies; 4+ messages in thread
From: Doyley, Marvin M. @ 2015-12-16 14:15 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

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

Hi John,
I really appreciate this.
Cheers,
M
---





Begin forwarded message:

From: John Kitchin <jkitchin@andrew.cmu.edu<mailto:jkitchin@andrew.cmu.edu>>
Date: December 16, 2015 at 6:38:51 AM EST
To: marvin doyley <marvinpas@gmail.com<mailto:marvinpas@gmail.com>>
Cc: emacs-orgmode@gnu.org<mailto:emacs-orgmode@gnu.org>
Subject: Re: [O] Converting paragraph to plain lis

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


[-- Attachment #2: Type: text/html, Size: 10164 bytes --]

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

end of thread, other threads:[~2015-12-16 15:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2015-12-16 14:15   ` Fwd: " Doyley, Marvin M.

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