2

Q: how do I unlist an org-mode plain list?

I have a plain list that looks like:

* header

  - List item 1.
  - List item 2.
  - List item 3.

I want to remove the plain list formatting and convert it to plain text:

* header

List item 1.  List item 2.  List item 3.

I want to do this programmatically. Are there org facilitates to strip off the bullets and refill the text, or do I need to roll my own?

  • Have you tried a keyboard macro? (There may be an existing org-mode command that does what you want, though - dunno.) – Drew Apr 23 at 10:46
3

First select the region with the items and remove the bullets with M-x org-toggle-item afterwards type M-q to run org-fill-paragraph.

If you need that more often you could bind org-toggle-item to a key of your choice in your init file.

Example:

(define-key org-mode-map (kbd "C-c i") #'org-toggle-item)

One programmatic solution would be:

(defun myorg-list-to-text ()
  "Transform item list at point into section text.
Searches for the next item list if there is none at point."
  (save-mark-and-excursion
    (unless (org-in-item-p)
      (org-list-search-forward (org-item-beginning-re)))
    (set-mark (org-end-of-item-list))
    (org-beginning-of-item-list)
    (when (org-at-item-checkbox-p)
      (org-toggle-checkbox '(4)))
    (org-toggle-item nil)
    (org-fill-paragraph)
    ))

Test conditions:

  • emacs-version: GNU Emacs 26.1 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.22.30) of 2018-05-29

  • Emacs started with emacs -Q and M-x package-initialize

  • org-version: Org mode version 9.1.13 (9.1.13-elpaplus @ /mnt/c/Users/Tobias.Zawada/.emacs.d/elpa/org-plus-contrib-20180618/)

  • Test file test.org with data:

 ** test

 - [X] first
 - [-] second
 - [X] third
 - fourth 
  • Place point at end of heading and call myorg-list-to-text

  • Undo, place point at end of first and call myorg-list-to-text

  • Undo, place point at end of fourth and call myorg-list-to-text

All tests deliver:

** test

first second third fourth

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.