初稿: 2018-07-23 Mon 14:26
最終更新日: 2018-12-14 Fri 20:44
ホーム | 文書トップ | 目次

org-list
lisp式をorg記法に変換する

目次

org-modeにはorg-list.elというファイルが標準添付されています。

org記法とlisp式の変換などをサポートしており、可能性の多い関数群だと思います。

1 org-list-to関数群

1.1 org-list-to-org

 1: (defun org-list-to-org (list &optional params)
 2:   "Convert LIST into an Org plain list.
 3: LIST is as returned by `org-list-parse-list'.  PARAMS is a property list
 4: with overruling parameters for `org-list-to-generic'."
 5:   (let* ((make-item
 6:       (lambda (type _depth &optional c)
 7:         (concat (if (eq type 'ordered) "1. " "- ")
 8:             (and c (format "[@%d] " c)))))
 9:      (defaults
10:        (list :istart make-item
11:          :icount make-item
12:          :ifmt (lambda (_type contents)
13:              (replace-regexp-in-string "\n" "\n  " contents))
14:          :dtend " :: "
15:          :cbon "[X] "
16:          :cboff "[ ] "
17:          :cbtrans "[-] ")))
18:     (org-list-to-generic list (org-combine-plists defaults params))))

org-list-to-org はlispのlistをorg記法でのリストに変換します。

(org-list-to-org '("a" ("b" "c")))
"- b
  c"

(org-list-to-org '("org-1" ("a" "b")
                   ("c"
                    ("org-2" ("d" "e")))))
"- a
  b
- c
  - d
    e"

1.2 org-list-to-subtree

 1: (defun org-list-to-subtree (list &optional params)
 2:   "Convert LIST into an Org subtree.
 3: LIST is as returned by `org-list-to-lisp'.  PARAMS is a property
 4: list with overruling parameters for `org-list-to-generic'."
 5:   (let* ((blank (pcase (cdr (assq 'heading org-blank-before-new-entry))
 6:           (`t t)
 7:           (`auto (save-excursion
 8:                (org-with-limited-levels (outline-previous-heading))
 9:                (org-previous-line-empty-p)))))
10:      (level (org-reduced-level (or (org-current-level) 0)))
11:      (make-stars
12:       (lambda (_type depth &optional _count)
13:         ;; Return the string for the heading, depending on DEPTH
14:         ;; of current sub-list.
15:         (let ((oddeven-level (+ level depth)))
16:           (concat (make-string (if org-odd-levels-only
17:                        (1- (* 2 oddeven-level))
18:                      oddeven-level)
19:                    ?*)
20:               " ")))))
21:     (org-list-to-generic
22:      list
23:      (org-combine-plists
24:       (list :splice t
25:         :istart make-stars
26:         :icount make-stars
27:         :dtstart " " :dtend " "
28:         :isep (if blank "\n\n" "\n")
29:         :cbon "DONE " :cboff "TODO " :cbtrans "TODO ")
30:       params))))

org-list-to-subtree はlispのlistをorg記法でのリストに変換します。

(org-list-to-subtree '("a" ("b" "c")))
"* b
c"

(org-list-to-subtree '("org-1" ("a" "b")
                   ("c"
                    ("org-2" ("d" "e")))))
"* a
b
* c
** d
e"

1.3 その他

  • org-list-to-latex

    (org-list-to-latex '("a" ("b" "c")))
    "\\begin{itemize}
    \\item b
    c
    \\end{itemize}"
    
    (org-list-to-latex '("org-1" ("a" "b")
                       ("c"
                        ("org-2" ("d" "e")))))
    "\\begin{itemize}
    \\item a
    b
    \\item c
    \\begin{itemize}
    \\item d
    e
    \\end{itemize}
    \\end{itemize}"
    
  • org-list-to-html

    (org-list-to-html '("a" ("b" "c")))
    "<ul class=\"org-ul\">
    <li>b
    c</li>
    </ul>"
    
    (org-list-to-html '("org-1" ("a" "b")
                       ("c"
                        ("org-2" ("d" "e")))))
    "<ul class=\"org-ul\">
    <li>a
    b</li>
    <li>c
    <ul class=\"org-ul\">
    <li>d
    e</li>
    </ul></li>
    </ul>"
    
  • org-list-to-texinfo

    (org-list-to-texinfo '("a" ("b" "c")))
    "@itemize
    @item
    b
    c
    @end itemize"
    
    (org-list-to-texinfo '("org-1" ("a" "b")
                       ("c"
                        ("org-2" ("d" "e")))))
    "@itemize
    @item
    a
    b
    @item
    c
    @itemize
    @item
    d
    e
    @end itemize
    @end itemize"
    

日付: 2018-07-23 Mon 14:26

著者: conao

Created: 2018-12-14 Fri 21:04

Validate