org-list.el 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197
  1. ;;; org-list.el --- Plain lists for Org-mode
  2. ;;
  3. ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
  4. ;; Free Software Foundation, Inc.
  5. ;;
  6. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  7. ;; Bastien Guerry <bzg AT altern DOT org>
  8. ;; Keywords: outlines, hypermedia, calendar, wp
  9. ;; Homepage: http://orgmode.org
  10. ;; Version: 6.23
  11. ;;
  12. ;; This file is part of GNU Emacs.
  13. ;;
  14. ;; GNU Emacs is free software: you can redistribute it and/or modify
  15. ;; it under the terms of the GNU General Public License as published by
  16. ;; the Free Software Foundation, either version 3 of the License, or
  17. ;; (at your option) any later version.
  18. ;; GNU Emacs is distributed in the hope that it will be useful,
  19. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. ;; GNU General Public License for more details.
  22. ;; You should have received a copy of the GNU General Public License
  23. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  24. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  25. ;;
  26. ;;; Commentary:
  27. ;; This file contains the code dealing with plain lists in Org-mode.
  28. ;;; Code:
  29. (require 'org-macs)
  30. (require 'org-compat)
  31. (defvar org-blank-before-new-entry)
  32. (defvar org-M-RET-may-split-line)
  33. (declare-function org-invisible-p "org" ())
  34. (declare-function org-on-heading-p "org" (&optional invisible-ok))
  35. (declare-function outline-next-heading "outline" ())
  36. (declare-function outline-back-to-heading "outline" (&optional invisible-ok))
  37. (declare-function org-back-to-heading "org" (&optional invisible-ok))
  38. (declare-function org-back-over-empty-lines "org" ())
  39. (declare-function org-skip-whitespace "org" ())
  40. (declare-function org-trim "org" (s))
  41. (declare-function org-get-indentation "org" (&optional line))
  42. (declare-function org-timer-item "org-timer" (&optional arg))
  43. (declare-function org-combine-plists "org" (&rest plists))
  44. (declare-function org-entry-get "org" (pom property &optional inherit))
  45. (defgroup org-plain-lists nil
  46. "Options concerning plain lists in Org-mode."
  47. :tag "Org Plain lists"
  48. :group 'org-structure)
  49. (defcustom org-cycle-include-plain-lists nil
  50. "Non-nil means, include plain lists into visibility cycling.
  51. This means that during cycling, plain list items will *temporarily* be
  52. interpreted as outline headlines with a level given by 1000+i where i is the
  53. indentation of the bullet. In all other operations, plain list items are
  54. not seen as headlines. For example, you cannot assign a TODO keyword to
  55. such an item."
  56. :group 'org-plain-lists
  57. :type 'boolean)
  58. (defcustom org-plain-list-ordered-item-terminator t
  59. "The character that makes a line with leading number an ordered list item.
  60. Valid values are ?. and ?\). To get both terminators, use t. While
  61. ?. may look nicer, it creates the danger that a line with leading
  62. number may be incorrectly interpreted as an item. ?\) therefore is
  63. the safe choice."
  64. :group 'org-plain-lists
  65. :type '(choice (const :tag "dot like in \"2.\"" ?.)
  66. (const :tag "paren like in \"2)\"" ?\))
  67. (const :tab "both" t)))
  68. (defcustom org-list-two-spaces-after-bullet-regexp nil
  69. "A regular expression matching bullets that should have 2 spaces after them.
  70. When nil, no bullet will have two spaces after them.
  71. When a string, it will be used as a regular expression. When the bullet
  72. type of a list is changed, the new bullet type will be matched against this
  73. regexp. If it matches, there will be two spaces instead of one after
  74. the bullet in each item of he list."
  75. :group 'org-plain-list
  76. :type '(choice
  77. (const :tag "never" nil)
  78. (regexp)))
  79. (defcustom org-empty-line-terminates-plain-lists nil
  80. "Non-nil means, an empty line ends all plain list levels.
  81. When nil, empty lines are part of the preceding item."
  82. :group 'org-plain-lists
  83. :type 'boolean)
  84. (defcustom org-auto-renumber-ordered-lists t
  85. "Non-nil means, automatically renumber ordered plain lists.
  86. Renumbering happens when the sequence have been changed with
  87. \\[org-shiftmetaup] or \\[org-shiftmetadown]. After other editing commands,
  88. use \\[org-ctrl-c-ctrl-c] to trigger renumbering."
  89. :group 'org-plain-lists
  90. :type 'boolean)
  91. (defcustom org-provide-checkbox-statistics t
  92. "Non-nil means, update checkbox statistics after insert and toggle.
  93. When this is set, checkbox statistics is updated each time you either insert
  94. a new checkbox with \\[org-insert-todo-heading] or toggle a checkbox
  95. with \\[org-ctrl-c-ctrl-c\\]."
  96. :group 'org-plain-lists
  97. :type 'boolean)
  98. (defcustom org-description-max-indent 20
  99. "Maximum indentation for the second line of a description list.
  100. When the indentation would be larger than this, it will become
  101. 5 characters instead."
  102. :group 'org-plain-lists
  103. :type 'integer)
  104. (defvar org-list-beginning-re
  105. "^\\([ \t]*\\)\\([-+*]\\|[0-9]+[.)]\\) +\\(.*\\)$")
  106. (defcustom org-list-radio-list-templates
  107. '((latex-mode "% BEGIN RECEIVE ORGLST %n
  108. % END RECEIVE ORGLST %n
  109. \\begin{comment}
  110. #+ORGLST: SEND %n org-list-to-latex
  111. | | |
  112. \\end{comment}\n")
  113. (texinfo-mode "@c BEGIN RECEIVE ORGLST %n
  114. @c END RECEIVE ORGLST %n
  115. @ignore
  116. #+ORGLST: SEND %n org-list-to-texinfo
  117. | | |
  118. @end ignore\n")
  119. (html-mode "<!-- BEGIN RECEIVE ORGLST %n -->
  120. <!-- END RECEIVE ORGLST %n -->
  121. <!--
  122. #+ORGLST: SEND %n org-list-to-html
  123. | | |
  124. -->\n"))
  125. "Templates for radio lists in different major modes.
  126. All occurrences of %n in a template will be replaced with the name of the
  127. list, obtained by prompting the user."
  128. :group 'org-plain-lists
  129. :type '(repeat
  130. (list (symbol :tag "Major mode")
  131. (string :tag "Format"))))
  132. ;;;; Plain list items, including checkboxes
  133. ;;; Plain list items
  134. (defun org-at-item-p ()
  135. "Is point in a line starting a hand-formatted item?"
  136. (let ((llt org-plain-list-ordered-item-terminator))
  137. (save-excursion
  138. (goto-char (point-at-bol))
  139. (looking-at
  140. (cond
  141. ((eq llt t) "\\([ \t]*\\([-+]\\|\\([0-9]+[.)]\\)\\)\\|[ \t]+\\*\\)\\( \\|$\\)")
  142. ((= llt ?.) "\\([ \t]*\\([-+]\\|\\([0-9]+\\.\\)\\)\\|[ \t]+\\*\\)\\( \\|$\\)")
  143. ((= llt ?\)) "\\([ \t]*\\([-+]\\|\\([0-9]+))\\)\\|[ \t]+\\*\\)\\( \\|$\\)")
  144. (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))))))
  145. (defun org-at-item-bullet-p ()
  146. "Is point at the bullet of a plain list item?"
  147. (and (org-at-item-p)
  148. (not (member (char-after) '(?\ ?\t)))
  149. (< (point) (match-end 0))))
  150. (defun org-in-item-p ()
  151. "It the cursor inside a plain list item.
  152. Does not have to be the first line."
  153. (save-excursion
  154. (condition-case nil
  155. (progn
  156. (org-beginning-of-item)
  157. (org-at-item-p)
  158. t)
  159. (error nil))))
  160. (defun org-insert-item (&optional checkbox)
  161. "Insert a new item at the current level.
  162. Return t when things worked, nil when we are not in an item."
  163. (when (save-excursion
  164. (condition-case nil
  165. (progn
  166. (org-beginning-of-item)
  167. (org-at-item-p)
  168. (if (org-invisible-p) (error "Invisible item"))
  169. t)
  170. (error nil)))
  171. (let* ((bul (match-string 0))
  172. (descp (save-excursion (goto-char (match-beginning 0))
  173. (beginning-of-line 1)
  174. (save-match-data
  175. (and (looking-at "[ \t]*\\(.*?\\) ::")
  176. (match-string 1)))))
  177. (empty-line-p (save-excursion
  178. (goto-char (match-beginning 0))
  179. (and (not (bobp))
  180. (or (beginning-of-line 0) t)
  181. (save-match-data
  182. (looking-at "[ \t]*$")))))
  183. (timerp (and descp
  184. (save-match-data
  185. (string-match "^[-+*][ \t]+[0-9]+:[0-9]+:[0-9]+$"
  186. descp))))
  187. (eow (save-excursion (beginning-of-line 1) (looking-at "[ \t]*")
  188. (match-end 0)))
  189. (blank-a (cdr (assq 'plain-list-item org-blank-before-new-entry)))
  190. (blank (if (eq blank-a 'auto) empty-line-p blank-a))
  191. pos)
  192. (if descp (setq checkbox nil))
  193. (if timerp
  194. (progn (org-timer-item) t)
  195. (cond
  196. ((and (org-at-item-p) (<= (point) eow))
  197. ;; before the bullet
  198. (beginning-of-line 1)
  199. (open-line (if blank 2 1)))
  200. ((<= (point) eow)
  201. (beginning-of-line 1))
  202. (t
  203. (unless (org-get-alist-option org-M-RET-may-split-line 'item)
  204. (end-of-line 1)
  205. (delete-horizontal-space))
  206. (newline (if blank 2 1))))
  207. (insert bul
  208. (if checkbox "[ ]" "")
  209. (if descp (concat (if checkbox " " "")
  210. (read-string "Term: ") " :: ") ""))
  211. (just-one-space)
  212. (setq pos (point))
  213. (end-of-line 1)
  214. (unless (= (point) pos) (just-one-space) (backward-delete-char 1)))
  215. (org-maybe-renumber-ordered-list)
  216. (and checkbox (org-update-checkbox-count-maybe))
  217. t)))
  218. ;;; Checkboxes
  219. (defun org-at-item-checkbox-p ()
  220. "Is point at a line starting a plain-list item with a checklet?"
  221. (and (org-at-item-p)
  222. (save-excursion
  223. (goto-char (match-end 0))
  224. (skip-chars-forward " \t")
  225. (looking-at "\\[[- X]\\]"))))
  226. (defun org-toggle-checkbox (&optional toggle-presence)
  227. "Toggle the checkbox in the current line.
  228. With prefix arg TOGGLE-PRESENCE, add or remove checkboxes.
  229. With double prefix, set checkbox to [-].
  230. When there is an active region, toggle status or presence of the checkbox
  231. in the first line, and make every item in the region have the same
  232. status or presence, respectively.
  233. If the cursor is in a headline, apply this to all checkbox items in the
  234. text below the heading."
  235. (interactive "P")
  236. (catch 'exit
  237. (let (beg end status first-present first-status blocked)
  238. (cond
  239. ((org-region-active-p)
  240. (setq beg (region-beginning) end (region-end)))
  241. ((org-on-heading-p)
  242. (setq beg (point) end (save-excursion (outline-next-heading) (point))))
  243. ((org-at-item-checkbox-p)
  244. (save-excursion
  245. (if (equal toggle-presence '(4))
  246. (progn
  247. (replace-match "")
  248. (goto-char (match-beginning 0))
  249. (just-one-space))
  250. (when (setq blocked (org-checkbox-blocked-p))
  251. (error "Checkbox blocked because of unchecked box in line %d"
  252. blocked))
  253. (replace-match
  254. (cond ((equal toggle-presence '(16)) "[-]")
  255. ((member (match-string 0) '("[ ]" "[-]")) "[X]")
  256. (t "[ ]"))
  257. t t)))
  258. (throw 'exit t))
  259. ((org-at-item-p)
  260. ;; add a checkbox
  261. (save-excursion
  262. (goto-char (match-end 0))
  263. (insert "[ ] "))
  264. (throw 'exit t))
  265. (t (error "Not at a checkbox or heading, and no active region")))
  266. (setq end (move-marker (make-marker) end))
  267. (save-excursion
  268. (goto-char beg)
  269. (setq first-present (org-at-item-checkbox-p)
  270. first-status
  271. (save-excursion
  272. (and (re-search-forward "[ \t]\\(\\[[ X]\\]\\)" end t)
  273. (equal (match-string 1) "[X]"))))
  274. (while (< (point) end)
  275. (if toggle-presence
  276. (cond
  277. ((and first-present (org-at-item-checkbox-p))
  278. (save-excursion
  279. (replace-match "")
  280. (goto-char (match-beginning 0))
  281. (just-one-space)))
  282. ((and (not first-present) (not (org-at-item-checkbox-p))
  283. (org-at-item-p))
  284. (save-excursion
  285. (goto-char (match-end 0))
  286. (insert "[ ] "))))
  287. (when (org-at-item-checkbox-p)
  288. (setq status (equal (match-string 0) "[X]"))
  289. (replace-match
  290. (if first-status "[ ]" "[X]") t t)))
  291. (beginning-of-line 2)))))
  292. (org-update-checkbox-count-maybe))
  293. (defun org-checkbox-blocked-p ()
  294. "Is the current checkbox blocked from for being checked now?
  295. A checkbox is blocked if all of the following conditions are fulfilled:
  296. 1. The checkbox is not checked already.
  297. 2. The current entry has the ORDERED property set.
  298. 3. There is an unchecked checkbox in this entry before the current line."
  299. (catch 'exit
  300. (save-match-data
  301. (save-excursion
  302. (unless (org-at-item-checkbox-p) (throw 'exit nil))
  303. (when (equal (match-string 0) "[X]")
  304. ;; the box is already checked!
  305. (throw 'exit nil))
  306. (let ((end (point-at-bol)))
  307. (condition-case nil (org-back-to-heading t)
  308. (error (throw 'exit nil)))
  309. (unless (org-entry-get nil "ORDERED") (throw 'exit nil))
  310. (if (re-search-forward "^[ \t]*[-+*0-9.)] \\[[- ]\\]" end t)
  311. (org-current-line)
  312. nil))))))
  313. (defun org-update-checkbox-count-maybe ()
  314. "Update checkbox statistics unless turned off by user."
  315. (when org-provide-checkbox-statistics
  316. (org-update-checkbox-count)))
  317. (defun org-update-checkbox-count (&optional all)
  318. "Update the checkbox statistics in the current section.
  319. This will find all statistic cookies like [57%] and [6/12] and update them
  320. with the current numbers. With optional prefix argument ALL, do this for
  321. the whole buffer."
  322. (interactive "P")
  323. (save-excursion
  324. (let* ((buffer-invisibility-spec (org-inhibit-invisibility)) ; Emacs 21
  325. (beg (condition-case nil
  326. (progn (org-back-to-heading) (point))
  327. (error (point-min))))
  328. (end (move-marker (make-marker)
  329. (progn (outline-next-heading) (point))))
  330. (re "\\(\\(\\[[0-9]*%\\]\\)\\|\\(\\[[0-9]*/[0-9]*\\]\\)\\)")
  331. (re-box "^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +\\(\\[[- X]\\]\\)")
  332. (re-find (concat re "\\|" re-box))
  333. beg-cookie end-cookie is-percent c-on c-off lim
  334. eline curr-ind next-ind continue-from startsearch
  335. (cstat 0)
  336. )
  337. (when all
  338. (goto-char (point-min))
  339. (outline-next-heading)
  340. (setq beg (point) end (point-max)))
  341. (goto-char end)
  342. ;; find each statistic cookie
  343. (while (re-search-backward re-find beg t)
  344. (setq beg-cookie (match-beginning 1)
  345. end-cookie (match-end 1)
  346. cstat (+ cstat (if end-cookie 1 0))
  347. startsearch (point-at-eol)
  348. continue-from (match-beginning 0)
  349. is-percent (match-beginning 2)
  350. lim (cond
  351. ((org-on-heading-p) (outline-next-heading) (point))
  352. ((org-at-item-p) (org-end-of-item) (point))
  353. (t nil))
  354. c-on 0
  355. c-off 0)
  356. (when lim
  357. ;; find first checkbox for this cookie and gather
  358. ;; statistics from all that are at this indentation level
  359. (goto-char startsearch)
  360. (if (re-search-forward re-box lim t)
  361. (progn
  362. (org-beginning-of-item)
  363. (setq curr-ind (org-get-indentation))
  364. (setq next-ind curr-ind)
  365. (while (and (bolp) (org-at-item-p) (= curr-ind next-ind))
  366. (save-excursion (end-of-line) (setq eline (point)))
  367. (if (re-search-forward re-box eline t)
  368. (if (member (match-string 2) '("[ ]" "[-]"))
  369. (setq c-off (1+ c-off))
  370. (setq c-on (1+ c-on))
  371. )
  372. )
  373. (org-end-of-item)
  374. (setq next-ind (org-get-indentation))
  375. )))
  376. (goto-char continue-from)
  377. ;; update cookie
  378. (when end-cookie
  379. (delete-region beg-cookie end-cookie)
  380. (goto-char beg-cookie)
  381. (insert
  382. (if is-percent
  383. (format "[%d%%]" (/ (* 100 c-on) (max 1 (+ c-on c-off))))
  384. (format "[%d/%d]" c-on (+ c-on c-off)))))
  385. ;; update items checkbox if it has one
  386. (when (org-at-item-p)
  387. (org-beginning-of-item)
  388. (when (and (> (+ c-on c-off) 0)
  389. (re-search-forward re-box (point-at-eol) t))
  390. (setq beg-cookie (match-beginning 2)
  391. end-cookie (match-end 2))
  392. (delete-region beg-cookie end-cookie)
  393. (goto-char beg-cookie)
  394. (cond ((= c-off 0) (insert "[X]"))
  395. ((= c-on 0) (insert "[ ]"))
  396. (t (insert "[-]")))
  397. )))
  398. (goto-char continue-from))
  399. (when (interactive-p)
  400. (message "Checkbox statistics updated %s (%d places)"
  401. (if all "in entire file" "in current outline entry") cstat)))))
  402. (defun org-get-checkbox-statistics-face ()
  403. "Select the face for checkbox statistics.
  404. The face will be `org-done' when all relevant boxes are checked. Otherwise
  405. it will be `org-todo'."
  406. (if (match-end 1)
  407. (if (equal (match-string 1) "100%") 'org-done 'org-todo)
  408. (if (and (> (match-end 2) (match-beginning 2))
  409. (equal (match-string 2) (match-string 3)))
  410. 'org-done
  411. 'org-todo)))
  412. (defun org-beginning-of-item ()
  413. "Go to the beginning of the current hand-formatted item.
  414. If the cursor is not in an item, throw an error."
  415. (interactive)
  416. (let ((pos (point))
  417. (limit (save-excursion
  418. (condition-case nil
  419. (progn
  420. (org-back-to-heading)
  421. (beginning-of-line 2) (point))
  422. (error (point-min)))))
  423. (ind-empty (if org-empty-line-terminates-plain-lists 0 10000))
  424. ind ind1)
  425. (if (org-at-item-p)
  426. (beginning-of-line 1)
  427. (beginning-of-line 1)
  428. (skip-chars-forward " \t")
  429. (setq ind (current-column))
  430. (if (catch 'exit
  431. (while t
  432. (beginning-of-line 0)
  433. (if (or (bobp) (< (point) limit)) (throw 'exit nil))
  434. (if (looking-at "[ \t]*$")
  435. (setq ind1 ind-empty)
  436. (skip-chars-forward " \t")
  437. (setq ind1 (current-column)))
  438. (if (< ind1 ind)
  439. (progn (beginning-of-line 1) (throw 'exit (org-at-item-p))))))
  440. nil
  441. (goto-char pos)
  442. (error "Not in an item")))))
  443. (defun org-end-of-item ()
  444. "Go to the end of the current hand-formatted item.
  445. If the cursor is not in an item, throw an error."
  446. (interactive)
  447. (let* ((pos (point))
  448. ind1
  449. (ind-empty (if org-empty-line-terminates-plain-lists 0 10000))
  450. (limit (save-excursion (outline-next-heading) (point)))
  451. (ind (save-excursion
  452. (org-beginning-of-item)
  453. (skip-chars-forward " \t")
  454. (current-column)))
  455. (end (catch 'exit
  456. (while t
  457. (beginning-of-line 2)
  458. (if (eobp) (throw 'exit (point)))
  459. (if (>= (point) limit) (throw 'exit (point-at-bol)))
  460. (if (looking-at "[ \t]*$")
  461. (setq ind1 ind-empty)
  462. (skip-chars-forward " \t")
  463. (setq ind1 (current-column)))
  464. (if (<= ind1 ind)
  465. (throw 'exit (point-at-bol)))))))
  466. (if end
  467. (goto-char end)
  468. (goto-char pos)
  469. (error "Not in an item"))))
  470. (defun org-next-item ()
  471. "Move to the beginning of the next item in the current plain list.
  472. Error if not at a plain list, or if this is the last item in the list."
  473. (interactive)
  474. (let (ind ind1 (pos (point)))
  475. (org-beginning-of-item)
  476. (setq ind (org-get-indentation))
  477. (org-end-of-item)
  478. (setq ind1 (org-get-indentation))
  479. (unless (and (org-at-item-p) (= ind ind1))
  480. (goto-char pos)
  481. (error "On last item"))))
  482. (defun org-previous-item ()
  483. "Move to the beginning of the previous item in the current plain list.
  484. Error if not at a plain list, or if this is the first item in the list."
  485. (interactive)
  486. (let (beg ind ind1 (pos (point)))
  487. (org-beginning-of-item)
  488. (setq beg (point))
  489. (setq ind (org-get-indentation))
  490. (goto-char beg)
  491. (catch 'exit
  492. (while t
  493. (beginning-of-line 0)
  494. (if (looking-at "[ \t]*$")
  495. nil
  496. (if (<= (setq ind1 (org-get-indentation)) ind)
  497. (throw 'exit t)))))
  498. (condition-case nil
  499. (if (or (not (org-at-item-p))
  500. (< ind1 (1- ind)))
  501. (error "")
  502. (org-beginning-of-item))
  503. (error (goto-char pos)
  504. (error "On first item")))))
  505. (defun org-first-list-item-p ()
  506. "Is this heading the item in a plain list?"
  507. (unless (org-at-item-p)
  508. (error "Not at a plain list item"))
  509. (org-beginning-of-item)
  510. (= (point) (save-excursion (org-beginning-of-item-list))))
  511. (defun org-move-item-down ()
  512. "Move the plain list item at point down, i.e. swap with following item.
  513. Subitems (items with larger indentation) are considered part of the item,
  514. so this really moves item trees."
  515. (interactive)
  516. (let ((col (current-column))
  517. (pos (point))
  518. beg beg0 end end0 ind ind1 txt ne-end ne-beg)
  519. (org-beginning-of-item)
  520. (setq beg0 (point))
  521. (save-excursion
  522. (setq ne-beg (org-back-over-empty-lines))
  523. (setq beg (point)))
  524. (goto-char beg0)
  525. (setq ind (org-get-indentation))
  526. (org-end-of-item)
  527. (setq end0 (point))
  528. (setq ind1 (org-get-indentation))
  529. (setq ne-end (org-back-over-empty-lines))
  530. (setq end (point))
  531. (goto-char beg0)
  532. (when (and (org-first-list-item-p) (< ne-end ne-beg))
  533. ;; include less whitespace
  534. (save-excursion
  535. (goto-char beg)
  536. (forward-line (- ne-beg ne-end))
  537. (setq beg (point))))
  538. (goto-char end0)
  539. (if (and (org-at-item-p) (= ind ind1))
  540. (progn
  541. (org-end-of-item)
  542. (org-back-over-empty-lines)
  543. (setq txt (buffer-substring beg end))
  544. (save-excursion
  545. (delete-region beg end))
  546. (setq pos (point))
  547. (insert txt)
  548. (goto-char pos) (org-skip-whitespace)
  549. (org-maybe-renumber-ordered-list)
  550. (move-to-column col))
  551. (goto-char pos)
  552. (move-to-column col)
  553. (error "Cannot move this item further down"))))
  554. (defun org-move-item-up (arg)
  555. "Move the plain list item at point up, i.e. swap with previous item.
  556. Subitems (items with larger indentation) are considered part of the item,
  557. so this really moves item trees."
  558. (interactive "p")
  559. (let ((col (current-column)) (pos (point))
  560. beg beg0 end ind ind1 txt
  561. ne-beg ne-ins ins-end)
  562. (org-beginning-of-item)
  563. (setq beg0 (point))
  564. (setq ind (org-get-indentation))
  565. (save-excursion
  566. (setq ne-beg (org-back-over-empty-lines))
  567. (setq beg (point)))
  568. (goto-char beg0)
  569. (org-end-of-item)
  570. (org-back-over-empty-lines)
  571. (setq end (point))
  572. (goto-char beg0)
  573. (catch 'exit
  574. (while t
  575. (beginning-of-line 0)
  576. (if (looking-at "[ \t]*$")
  577. (if org-empty-line-terminates-plain-lists
  578. (progn
  579. (goto-char pos)
  580. (error "Cannot move this item further up"))
  581. nil)
  582. (if (<= (setq ind1 (org-get-indentation)) ind)
  583. (throw 'exit t)))))
  584. (condition-case nil
  585. (org-beginning-of-item)
  586. (error (goto-char beg0)
  587. (move-to-column col)
  588. (error "Cannot move this item further up")))
  589. (setq ind1 (org-get-indentation))
  590. (if (and (org-at-item-p) (= ind ind1))
  591. (progn
  592. (setq ne-ins (org-back-over-empty-lines))
  593. (setq txt (buffer-substring beg end))
  594. (save-excursion
  595. (delete-region beg end))
  596. (setq pos (point))
  597. (insert txt)
  598. (setq ins-end (point))
  599. (goto-char pos) (org-skip-whitespace)
  600. (when (and (org-first-list-item-p) (> ne-ins ne-beg))
  601. ;; Move whitespace back to beginning
  602. (save-excursion
  603. (goto-char ins-end)
  604. (let ((kill-whole-line t))
  605. (kill-line (- ne-ins ne-beg)) (point)))
  606. (insert (make-string (- ne-ins ne-beg) ?\n)))
  607. (org-maybe-renumber-ordered-list)
  608. (move-to-column col))
  609. (goto-char pos)
  610. (move-to-column col)
  611. (error "Cannot move this item further up"))))
  612. (defun org-maybe-renumber-ordered-list ()
  613. "Renumber the ordered list at point if setup allows it.
  614. This tests the user option `org-auto-renumber-ordered-lists' before
  615. doing the renumbering."
  616. (interactive)
  617. (when (and org-auto-renumber-ordered-lists
  618. (org-at-item-p))
  619. (if (match-beginning 3)
  620. (org-renumber-ordered-list 1)
  621. (org-fix-bullet-type))))
  622. (defun org-maybe-renumber-ordered-list-safe ()
  623. (condition-case nil
  624. (save-excursion
  625. (org-maybe-renumber-ordered-list))
  626. (error nil)))
  627. (defun org-cycle-list-bullet (&optional which)
  628. "Cycle through the different itemize/enumerate bullets.
  629. This cycle the entire list level through the sequence:
  630. `-' -> `+' -> `*' -> `1.' -> `1)'
  631. If WHICH is a string, use that as the new bullet. If WHICH is an integer,
  632. 0 means `-', 1 means `+' etc."
  633. (interactive "P")
  634. (org-preserve-lc
  635. (org-beginning-of-item-list)
  636. (org-at-item-p)
  637. (beginning-of-line 1)
  638. (let ((current (match-string 0))
  639. (prevp (eq which 'previous))
  640. new old)
  641. (setq new (cond
  642. ((and (numberp which)
  643. (nth (1- which) '("-" "+" "*" "1." "1)"))))
  644. ((string-match "-" current) (if prevp "1)" "+"))
  645. ((string-match "\\+" current)
  646. (if prevp "-" (if (looking-at "\\S-") "1." "*")))
  647. ((string-match "\\*" current) (if prevp "+" "1."))
  648. ((string-match "\\." current)
  649. (if prevp (if (looking-at "\\S-") "+" "*") "1)"))
  650. ((string-match ")" current) (if prevp "1." "-"))
  651. (t (error "This should not happen"))))
  652. (and (looking-at "\\([ \t]*\\)\\(\\S-+\\)")
  653. (setq old (match-string 2))
  654. (replace-match (concat "\\1" new)))
  655. (org-shift-item-indentation (- (length new) (length old)))
  656. (org-fix-bullet-type)
  657. (org-maybe-renumber-ordered-list))))
  658. (defun org-get-string-indentation (s)
  659. "What indentation has S due to SPACE and TAB at the beginning of the string?"
  660. (let ((n -1) (i 0) (w tab-width) c)
  661. (catch 'exit
  662. (while (< (setq n (1+ n)) (length s))
  663. (setq c (aref s n))
  664. (cond ((= c ?\ ) (setq i (1+ i)))
  665. ((= c ?\t) (setq i (* (/ (+ w i) w) w)))
  666. (t (throw 'exit t)))))
  667. i))
  668. (defun org-renumber-ordered-list (arg)
  669. "Renumber an ordered plain list.
  670. Cursor needs to be in the first line of an item, the line that starts
  671. with something like \"1.\" or \"2)\"."
  672. (interactive "p")
  673. (unless (and (org-at-item-p)
  674. (match-beginning 3))
  675. (error "This is not an ordered list"))
  676. (let ((line (org-current-line))
  677. (col (current-column))
  678. (ind (org-get-string-indentation
  679. (buffer-substring (point-at-bol) (match-beginning 3))))
  680. ;; (term (substring (match-string 3) -1))
  681. ind1 (n (1- arg))
  682. fmt bobp old new)
  683. ;; find where this list begins
  684. (org-beginning-of-item-list)
  685. (setq bobp (bobp))
  686. (looking-at "[ \t]*[0-9]+\\([.)]\\)")
  687. (setq fmt (concat "%d" (or (match-string 1) ".")))
  688. (beginning-of-line 0)
  689. ;; walk forward and replace these numbers
  690. (catch 'exit
  691. (while t
  692. (catch 'next
  693. (if bobp (setq bobp nil) (beginning-of-line 2))
  694. (if (eobp) (throw 'exit nil))
  695. (if (looking-at "[ \t]*$") (throw 'next nil))
  696. (skip-chars-forward " \t") (setq ind1 (current-column))
  697. (if (> ind1 ind) (throw 'next t))
  698. (if (< ind1 ind) (throw 'exit t))
  699. (if (not (org-at-item-p)) (throw 'exit nil))
  700. (setq old (match-string 2))
  701. (delete-region (match-beginning 2) (match-end 2))
  702. (goto-char (match-beginning 2))
  703. (insert (setq new (format fmt (setq n (1+ n)))))
  704. (org-shift-item-indentation (- (length new) (length old))))))
  705. (goto-line line)
  706. (org-move-to-column col)))
  707. (defun org-fix-bullet-type ()
  708. "Make sure all items in this list have the same bullet as the first item.
  709. Also, fix the indentation."
  710. (interactive)
  711. (unless (org-at-item-p) (error "This is not a list"))
  712. (let ((line (org-current-line))
  713. (col (current-column))
  714. (ind (current-indentation))
  715. ind1 bullet oldbullet)
  716. ;; find where this list begins
  717. (org-beginning-of-item-list)
  718. (beginning-of-line 1)
  719. ;; find out what the bullet type is
  720. (looking-at "[ \t]*\\(\\S-+\\)")
  721. (setq bullet (concat (match-string 1) " "))
  722. (if (and org-list-two-spaces-after-bullet-regexp
  723. (string-match org-list-two-spaces-after-bullet-regexp bullet))
  724. (setq bullet (concat bullet " ")))
  725. ;; walk forward and replace these numbers
  726. (beginning-of-line 0)
  727. (catch 'exit
  728. (while t
  729. (catch 'next
  730. (beginning-of-line 2)
  731. (if (eobp) (throw 'exit nil))
  732. (if (looking-at "[ \t]*$") (throw 'next nil))
  733. (skip-chars-forward " \t") (setq ind1 (current-column))
  734. (if (> ind1 ind) (throw 'next t))
  735. (if (< ind1 ind) (throw 'exit t))
  736. (if (not (org-at-item-p)) (throw 'exit nil))
  737. (skip-chars-forward " \t")
  738. (looking-at "\\S-+ *")
  739. (setq oldbullet (match-string 0))
  740. (unless (equal bullet oldbullet) (replace-match bullet))
  741. (org-shift-item-indentation (- (length bullet) (length oldbullet))))))
  742. (goto-line line)
  743. (org-move-to-column col)
  744. (if (string-match "[0-9]" bullet)
  745. (org-renumber-ordered-list 1))))
  746. (defun org-shift-item-indentation (delta)
  747. "Shift the indentation in current item by DELTA."
  748. (save-excursion
  749. (let ((beg (point-at-bol))
  750. (end (progn (org-end-of-item) (point)))
  751. i)
  752. (goto-char end)
  753. (beginning-of-line 0)
  754. (while (> (point) beg)
  755. (when (looking-at "[ \t]*\\S-")
  756. ;; this is not an empty line
  757. (setq i (org-get-indentation))
  758. (if (and (> i 0) (> (setq i (+ i delta)) 0))
  759. (indent-line-to i)))
  760. (beginning-of-line 0)))))
  761. (defun org-beginning-of-item-list ()
  762. "Go to the beginning of the current item list.
  763. I.e. to the first item in this list."
  764. (interactive)
  765. (org-beginning-of-item)
  766. (let ((pos (point-at-bol))
  767. (ind (org-get-indentation))
  768. ind1)
  769. ;; find where this list begins
  770. (catch 'exit
  771. (while t
  772. (catch 'next
  773. (beginning-of-line 0)
  774. (if (looking-at "[ \t]*$")
  775. (throw (if (bobp) 'exit 'next) t))
  776. (skip-chars-forward " \t") (setq ind1 (current-column))
  777. (if (or (< ind1 ind)
  778. (and (= ind1 ind)
  779. (not (org-at-item-p)))
  780. (and (= (point-at-bol) (point-min))
  781. (setq pos (point-min))))
  782. (throw 'exit t)
  783. (when (org-at-item-p) (setq pos (point-at-bol)))))))
  784. (goto-char pos)))
  785. (defun org-end-of-item-list ()
  786. "Go to the end of the current item list.
  787. I.e. to the text after the last item."
  788. (interactive)
  789. (org-beginning-of-item)
  790. (let ((pos (point-at-bol))
  791. (ind (org-get-indentation))
  792. ind1)
  793. ;; find where this list begins
  794. (catch 'exit
  795. (while t
  796. (catch 'next
  797. (beginning-of-line 2)
  798. (if (looking-at "[ \t]*$")
  799. (throw (if (eobp) 'exit 'next) t))
  800. (skip-chars-forward " \t") (setq ind1 (current-column))
  801. (if (or (< ind1 ind)
  802. (and (= ind1 ind)
  803. (not (org-at-item-p)))
  804. (eobp))
  805. (progn
  806. (setq pos (point-at-bol))
  807. (throw 'exit t))))))
  808. (goto-char pos)))
  809. (defvar org-last-indent-begin-marker (make-marker))
  810. (defvar org-last-indent-end-marker (make-marker))
  811. (defun org-outdent-item (arg)
  812. "Outdent a local list item."
  813. (interactive "p")
  814. (org-indent-item (- arg)))
  815. (defun org-indent-item (arg)
  816. "Indent a local list item."
  817. (interactive "p")
  818. (and (org-region-active-p) (org-cursor-to-region-beginning))
  819. (unless (org-at-item-p)
  820. (error "Not on an item"))
  821. (save-excursion
  822. (let (beg end ind ind1 tmp delta ind-down ind-up)
  823. (setq end (and (org-region-active-p) (region-end)))
  824. (if (memq last-command '(org-shiftmetaright org-shiftmetaleft))
  825. (setq beg org-last-indent-begin-marker
  826. end org-last-indent-end-marker)
  827. (org-beginning-of-item)
  828. (setq beg (move-marker org-last-indent-begin-marker (point)))
  829. (org-end-of-item)
  830. (setq end (move-marker org-last-indent-end-marker (or end (point)))))
  831. (goto-char beg)
  832. (setq tmp (org-item-indent-positions)
  833. ind (car tmp)
  834. ind-down (nth 2 tmp)
  835. ind-up (nth 1 tmp)
  836. delta (if (> arg 0)
  837. (if ind-down (- ind-down ind) 2)
  838. (if ind-up (- ind-up ind) -2)))
  839. (if (< (+ delta ind) 0) (error "Cannot outdent beyond margin"))
  840. (while (< (point) end)
  841. (beginning-of-line 1)
  842. (skip-chars-forward " \t") (setq ind1 (current-column))
  843. (delete-region (point-at-bol) (point))
  844. (or (eolp) (org-indent-to-column (+ ind1 delta)))
  845. (beginning-of-line 2))))
  846. (org-fix-bullet-type)
  847. (org-maybe-renumber-ordered-list-safe)
  848. (save-excursion
  849. (beginning-of-line 0)
  850. (condition-case nil (org-beginning-of-item) (error nil))
  851. (org-maybe-renumber-ordered-list-safe)))
  852. (defun org-item-indent-positions ()
  853. "Return indentation for plain list items.
  854. This returns a list with three values: The current indentation, the
  855. parent indentation and the indentation a child should have.
  856. Assumes cursor in item line."
  857. (let* ((bolpos (point-at-bol))
  858. (ind (org-get-indentation))
  859. ind-down ind-up pos)
  860. (save-excursion
  861. (org-beginning-of-item-list)
  862. (skip-chars-backward "\n\r \t")
  863. (when (org-in-item-p)
  864. (org-beginning-of-item)
  865. (setq ind-up (org-get-indentation))))
  866. (setq pos (point))
  867. (save-excursion
  868. (cond
  869. ((and (condition-case nil (progn (org-previous-item) t)
  870. (error nil))
  871. (or (forward-char 1) t)
  872. (re-search-forward "^\\([ \t]*\\([-+]\\|\\([0-9]+[.)]\\)\\)\\|[ \t]+\\*\\)\\( \\|$\\)" bolpos t))
  873. (setq ind-down (org-get-indentation)))
  874. ((and (goto-char pos)
  875. (org-at-item-p))
  876. (goto-char (match-end 0))
  877. (skip-chars-forward " \t")
  878. (setq ind-down (current-column)))))
  879. (list ind ind-up ind-down)))
  880. ;;; Send and receive lists
  881. (defun org-list-parse-list (&optional delete)
  882. "Parse the list at point and maybe DELETE it.
  883. Return a list containing first level items as strings and
  884. sublevels as a list of strings."
  885. (let* ((item-beginning (org-list-item-beginning))
  886. (start (car item-beginning))
  887. (end (org-list-end (cdr item-beginning)))
  888. output itemsep ltype)
  889. (while (re-search-forward org-list-beginning-re end t)
  890. (goto-char (match-beginning 3))
  891. (save-match-data
  892. (cond ((string-match "[0-9]" (match-string 2))
  893. (setq itemsep "[0-9]+\\(?:\\.\\|)\\)"
  894. ltype 'ordered))
  895. ((string-match "^.*::" (match-string 0))
  896. (setq itemsep "[-+]" ltype 'descriptive))
  897. (t (setq itemsep "[-+]" ltype 'unordered))))
  898. (let* ((indent1 (match-string 1))
  899. (nextitem (save-excursion
  900. (save-match-data
  901. (or (and (re-search-forward
  902. (concat "^" indent1 itemsep " *?") end t)
  903. (match-beginning 0)) end))))
  904. (item (buffer-substring
  905. (point)
  906. (or (and (re-search-forward
  907. org-list-beginning-re end t)
  908. (goto-char (match-beginning 0)))
  909. (goto-char end))))
  910. (nextindent (match-string 1))
  911. (item (org-trim item))
  912. (item (if (string-match "^\\[\\([xX ]\\)\\]" item)
  913. (replace-match (if (equal (match-string 1 item) " ")
  914. "[CBOFF]"
  915. "[CBON]")
  916. t nil item)
  917. item)))
  918. (push item output)
  919. (when (> (length nextindent)
  920. (length indent1))
  921. (narrow-to-region (point) nextitem)
  922. (push (org-list-parse-list) output)
  923. (widen))))
  924. (when delete (delete-region start end))
  925. (setq output (nreverse output))
  926. (push ltype output)))
  927. (defun org-list-item-beginning ()
  928. "Find the beginning of the list item.
  929. Return a cons which car is the beginning position of the item and
  930. cdr is the indentation string."
  931. (save-excursion
  932. (if (not (or (looking-at org-list-beginning-re)
  933. (re-search-backward
  934. org-list-beginning-re nil t)))
  935. (progn (goto-char (point-min)) (point))
  936. (cons (match-beginning 0) (match-string 1)))))
  937. (defun org-list-end (indent)
  938. "Return the position of the end of the list.
  939. INDENT is the indentation of the list."
  940. (save-excursion
  941. (catch 'exit
  942. (while (or (looking-at org-list-beginning-re)
  943. (looking-at (concat "^" indent "[ \t]+\\|^$")))
  944. (if (eq (point) (point-max))
  945. (throw 'exit (point-max)))
  946. (forward-line 1))) (point)))
  947. (defun org-list-insert-radio-list ()
  948. "Insert a radio list template appropriate for this major mode."
  949. (interactive)
  950. (let* ((e (assq major-mode org-list-radio-list-templates))
  951. (txt (nth 1 e))
  952. name pos)
  953. (unless e (error "No radio list setup defined for %s" major-mode))
  954. (setq name (read-string "List name: "))
  955. (while (string-match "%n" txt)
  956. (setq txt (replace-match name t t txt)))
  957. (or (bolp) (insert "\n"))
  958. (setq pos (point))
  959. (insert txt)
  960. (goto-char pos)))
  961. (defun org-list-send-list (&optional maybe)
  962. "Send a tranformed version of this list to the receiver position.
  963. With argument MAYBE, fail quietly if no transformation is defined for
  964. this list."
  965. (interactive)
  966. (catch 'exit
  967. (unless (org-at-item-p) (error "Not at a list"))
  968. (save-excursion
  969. (goto-char (car (org-list-item-beginning)))
  970. (beginning-of-line 0)
  971. (unless (looking-at "#\\+ORGLST: *SEND +\\([a-zA-Z0-9_]+\\) +\\([^ \t\r\n]+\\)\\( +.*\\)?")
  972. (if maybe
  973. (throw 'exit nil)
  974. (error "Don't know how to transform this list"))))
  975. (let* ((name (match-string 1))
  976. (item-beginning (org-list-item-beginning))
  977. (transform (intern (match-string 2)))
  978. (txt (buffer-substring-no-properties
  979. (car item-beginning)
  980. (org-list-end (cdr item-beginning))))
  981. (list (org-list-parse-list))
  982. beg)
  983. (unless (fboundp transform)
  984. (error "No such transformation function %s" transform))
  985. (setq txt (funcall transform list))
  986. ;; Find the insertion place
  987. (save-excursion
  988. (goto-char (point-min))
  989. (unless (re-search-forward
  990. (concat "BEGIN RECEIVE ORGLST +" name "\\([ \t]\\|$\\)") nil t)
  991. (error "Don't know where to insert translated list"))
  992. (goto-char (match-beginning 0))
  993. (beginning-of-line 2)
  994. (setq beg (point))
  995. (unless (re-search-forward (concat "END RECEIVE ORGLST +" name) nil t)
  996. (error "Cannot find end of insertion region"))
  997. (beginning-of-line 1)
  998. (delete-region beg (point))
  999. (goto-char beg)
  1000. (insert txt "\n"))
  1001. (message "List converted and installed at receiver location"))))
  1002. (defun org-list-to-generic (list params)
  1003. "Convert a LIST parsed through `org-list-parse-list' to other formats.
  1004. Valid parameters PARAMS are
  1005. :ustart String to start an unordered list
  1006. :uend String to end an unordered list
  1007. :ostart String to start an ordered list
  1008. :oend String to end an ordered list
  1009. :dstart String to start a descriptive list
  1010. :dend String to end a descriptive list
  1011. :dtstart String to start a descriptive term
  1012. :dtend String to end a descriptive term
  1013. :ddstart String to start a description
  1014. :ddend String to end a description
  1015. :splice When set to t, return only list body lines, don't wrap
  1016. them into :[u/o]start and :[u/o]end. Default is nil.
  1017. :istart String to start a list item
  1018. :iend String to end a list item
  1019. :isep String to separate items
  1020. :lsep String to separate sublists
  1021. :cboff String to insert for an unchecked checkbox
  1022. :cbon String to insert for a checked checkbox"
  1023. (interactive)
  1024. (let* ((p params) sublist
  1025. (splicep (plist-get p :splice))
  1026. (ostart (plist-get p :ostart))
  1027. (oend (plist-get p :oend))
  1028. (ustart (plist-get p :ustart))
  1029. (uend (plist-get p :uend))
  1030. (dstart (plist-get p :dstart))
  1031. (dend (plist-get p :dend))
  1032. (dtstart (plist-get p :dtstart))
  1033. (dtend (plist-get p :dtend))
  1034. (ddstart (plist-get p :ddstart))
  1035. (ddend (plist-get p :ddend))
  1036. (istart (plist-get p :istart))
  1037. (iend (plist-get p :iend))
  1038. (isep (plist-get p :isep))
  1039. (lsep (plist-get p :lsep))
  1040. (cbon (plist-get p :cbon))
  1041. (cboff (plist-get p :cboff)))
  1042. (let ((wrapper
  1043. (cond ((eq (car list) 'ordered)
  1044. (concat ostart "\n%s" oend "\n"))
  1045. ((eq (car list) 'unordered)
  1046. (concat ustart "\n%s" uend "\n"))
  1047. ((eq (car list) 'descriptive)
  1048. (concat dstart "\n%s" dend "\n"))))
  1049. rtn term defstart defend)
  1050. (while (setq sublist (pop list))
  1051. (cond ((symbolp sublist) nil)
  1052. ((stringp sublist)
  1053. (when (string-match "^\\(.*\\) ::" sublist)
  1054. (setq term (org-trim (format (concat dtstart "%s" dtend)
  1055. (match-string 1 sublist))))
  1056. (setq sublist (substring sublist (1+ (length term)))))
  1057. (if (string-match "\\[CBON\\]" sublist)
  1058. (setq sublist (replace-match cbon t t sublist)))
  1059. (if (string-match "\\[CBOFF\\]" sublist)
  1060. (setq sublist (replace-match cboff t t sublist)))
  1061. (setq rtn (concat rtn istart term ddstart
  1062. sublist ddend iend isep)))
  1063. (t (setq rtn (concat rtn ;; previous list
  1064. lsep ;; list separator
  1065. (org-list-to-generic sublist p)
  1066. lsep ;; list separator
  1067. )))))
  1068. (format wrapper rtn))))
  1069. (defun org-list-to-latex (list &optional params)
  1070. "Convert LIST into a LaTeX list.
  1071. LIST is as returnd by `org-list-parse-list'. PARAMS is a property list
  1072. with overruling parameters for `org-list-to-generic'."
  1073. (org-list-to-generic
  1074. list
  1075. (org-combine-plists
  1076. '(:splicep nil :ostart "\\begin{enumerate}" :oend "\\end{enumerate}"
  1077. :ustart "\\begin{itemize}" :uend "\\end{itemize}"
  1078. :dstart "\\begin{description}" :dend "\\end{description}"
  1079. :dtstart "[" :dtend "]"
  1080. :ddstart "" :ddend ""
  1081. :istart "\\item " :iend ""
  1082. :isep "\n" :lsep "\n"
  1083. :cbon "\\texttt{[X]}" :cboff "\\texttt{[ ]}")
  1084. params)))
  1085. (defun org-list-to-html (list &optional params)
  1086. "Convert LIST into a HTML list.
  1087. LIST is as returnd by `org-list-parse-list'. PARAMS is a property list
  1088. with overruling parameters for `org-list-to-generic'."
  1089. (org-list-to-generic
  1090. list
  1091. (org-combine-plists
  1092. '(:splicep nil :ostart "<ol>" :oend "</ol>"
  1093. :ustart "<ul>" :uend "</ul>"
  1094. :dstart "<dl>" :dend "</dl>"
  1095. :dtstart "<dt>" :dtend "</dt>"
  1096. :ddstart "<dd>" :ddend "</dd>"
  1097. :istart "<li>" :iend "</li>"
  1098. :isep "\n" :lsep "\n"
  1099. :cbon "<code>[X]</code>" :cboff "<code>[ ]</code>")
  1100. params)))
  1101. (defun org-list-to-texinfo (list &optional params)
  1102. "Convert LIST into a Texinfo list.
  1103. LIST is as returnd by `org-list-parse-list'. PARAMS is a property list
  1104. with overruling parameters for `org-list-to-generic'."
  1105. (org-list-to-generic
  1106. list
  1107. (org-combine-plists
  1108. '(:splicep nil :ostart "@itemize @minus" :oend "@end itemize"
  1109. :ustart "@enumerate" :uend "@end enumerate"
  1110. :dstart "@table" :dend "@end table"
  1111. :dtstart "@item " :dtend "\n"
  1112. :ddstart "" :ddend ""
  1113. :istart "@item\n" :iend ""
  1114. :isep "\n" :lsep "\n"
  1115. :cbon "@code{[X]}" :cboff "@code{[ ]}")
  1116. params)))
  1117. (provide 'org-list)
  1118. ;; arch-tag: 73cf50c1-200f-4d1d-8a53-4e842a5b11c8
  1119. ;;; org-list.el ends here