org-list.el 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207
  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.26d
  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 (if org-empty-line-terminates-plain-lists
  190. nil
  191. (cdr (assq 'plain-list-item org-blank-before-new-entry))))
  192. (blank (if (eq blank-a 'auto) empty-line-p blank-a))
  193. pos)
  194. (if descp (setq checkbox nil))
  195. (if timerp
  196. (progn (org-timer-item) t)
  197. (cond
  198. ((and (org-at-item-p) (<= (point) eow))
  199. ;; before the bullet
  200. (beginning-of-line 1)
  201. (open-line (if blank 2 1)))
  202. ((<= (point) eow)
  203. (beginning-of-line 1))
  204. (t
  205. (unless (org-get-alist-option org-M-RET-may-split-line 'item)
  206. (end-of-line 1)
  207. (delete-horizontal-space))
  208. (newline (if blank 2 1))))
  209. (insert bul
  210. (if checkbox "[ ]" "")
  211. (if descp (concat (if checkbox " " "")
  212. (read-string "Term: ") " :: ") ""))
  213. (just-one-space)
  214. (setq pos (point))
  215. (end-of-line 1)
  216. (unless (= (point) pos) (just-one-space) (backward-delete-char 1)))
  217. (org-maybe-renumber-ordered-list)
  218. (and checkbox (org-update-checkbox-count-maybe))
  219. t)))
  220. ;;; Checkboxes
  221. (defun org-at-item-checkbox-p ()
  222. "Is point at a line starting a plain-list item with a checklet?"
  223. (and (org-at-item-p)
  224. (save-excursion
  225. (goto-char (match-end 0))
  226. (skip-chars-forward " \t")
  227. (looking-at "\\[[- X]\\]"))))
  228. (defun org-toggle-checkbox (&optional toggle-presence)
  229. "Toggle the checkbox in the current line.
  230. With prefix arg TOGGLE-PRESENCE, add or remove checkboxes.
  231. With double prefix, set checkbox to [-].
  232. When there is an active region, toggle status or presence of the checkbox
  233. in the first line, and make every item in the region have the same
  234. status or presence, respectively.
  235. If the cursor is in a headline, apply this to all checkbox items in the
  236. text below the heading."
  237. (interactive "P")
  238. (catch 'exit
  239. (let (beg end status first-present first-status blocked)
  240. (cond
  241. ((org-region-active-p)
  242. (setq beg (region-beginning) end (region-end)))
  243. ((org-on-heading-p)
  244. (setq beg (point) end (save-excursion (outline-next-heading) (point))))
  245. ((org-at-item-checkbox-p)
  246. (save-excursion
  247. (if (equal toggle-presence '(4))
  248. (progn
  249. (replace-match "")
  250. (goto-char (match-beginning 0))
  251. (just-one-space))
  252. (when (setq blocked (org-checkbox-blocked-p))
  253. (error "Checkbox blocked because of unchecked box in line %d"
  254. blocked))
  255. (replace-match
  256. (cond ((equal toggle-presence '(16)) "[-]")
  257. ((member (match-string 0) '("[ ]" "[-]")) "[X]")
  258. (t "[ ]"))
  259. t t)))
  260. (throw 'exit t))
  261. ((org-at-item-p)
  262. ;; add a checkbox
  263. (save-excursion
  264. (goto-char (match-end 0))
  265. (insert "[ ] "))
  266. (throw 'exit t))
  267. (t (error "Not at a checkbox or heading, and no active region")))
  268. (setq end (move-marker (make-marker) end))
  269. (save-excursion
  270. (goto-char beg)
  271. (setq first-present (org-at-item-checkbox-p)
  272. first-status
  273. (save-excursion
  274. (and (re-search-forward "[ \t]\\(\\[[ X]\\]\\)" end t)
  275. (equal (match-string 1) "[X]"))))
  276. (while (< (point) end)
  277. (if toggle-presence
  278. (cond
  279. ((and first-present (org-at-item-checkbox-p))
  280. (save-excursion
  281. (replace-match "")
  282. (goto-char (match-beginning 0))
  283. (just-one-space)))
  284. ((and (not first-present) (not (org-at-item-checkbox-p))
  285. (org-at-item-p))
  286. (save-excursion
  287. (goto-char (match-end 0))
  288. (insert "[ ] "))))
  289. (when (org-at-item-checkbox-p)
  290. (setq status (equal (match-string 0) "[X]"))
  291. (replace-match
  292. (if first-status "[ ]" "[X]") t t)))
  293. (beginning-of-line 2)))))
  294. (org-update-checkbox-count-maybe))
  295. (defun org-checkbox-blocked-p ()
  296. "Is the current checkbox blocked from for being checked now?
  297. A checkbox is blocked if all of the following conditions are fulfilled:
  298. 1. The checkbox is not checked already.
  299. 2. The current entry has the ORDERED property set.
  300. 3. There is an unchecked checkbox in this entry before the current line."
  301. (catch 'exit
  302. (save-match-data
  303. (save-excursion
  304. (unless (org-at-item-checkbox-p) (throw 'exit nil))
  305. (when (equal (match-string 0) "[X]")
  306. ;; the box is already checked!
  307. (throw 'exit nil))
  308. (let ((end (point-at-bol)))
  309. (condition-case nil (org-back-to-heading t)
  310. (error (throw 'exit nil)))
  311. (unless (org-entry-get nil "ORDERED") (throw 'exit nil))
  312. (if (re-search-forward "^[ \t]*[-+*0-9.)] \\[[- ]\\]" end t)
  313. (org-current-line)
  314. nil))))))
  315. (defun org-update-checkbox-count-maybe ()
  316. "Update checkbox statistics unless turned off by user."
  317. (when org-provide-checkbox-statistics
  318. (org-update-checkbox-count)))
  319. (defun org-update-checkbox-count (&optional all)
  320. "Update the checkbox statistics in the current section.
  321. This will find all statistic cookies like [57%] and [6/12] and update them
  322. with the current numbers. With optional prefix argument ALL, do this for
  323. the whole buffer."
  324. (interactive "P")
  325. (save-excursion
  326. (let* ((buffer-invisibility-spec (org-inhibit-invisibility)) ; Emacs 21
  327. (beg (condition-case nil
  328. (progn (org-back-to-heading) (point))
  329. (error (point-min))))
  330. (end (move-marker (make-marker)
  331. (progn (outline-next-heading) (point))))
  332. (re "\\(\\(\\[[0-9]*%\\]\\)\\|\\(\\[[0-9]*/[0-9]*\\]\\)\\)")
  333. (re-box "^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +\\(\\[[- X]\\]\\)")
  334. (re-find (concat re "\\|" re-box))
  335. beg-cookie end-cookie is-percent c-on c-off lim
  336. eline curr-ind next-ind continue-from startsearch
  337. (cstat 0)
  338. )
  339. (when all
  340. (goto-char (point-min))
  341. (outline-next-heading)
  342. (setq beg (point) end (point-max)))
  343. (goto-char end)
  344. ;; find each statistics cookie
  345. (while (and (re-search-backward re-find beg t)
  346. (not (save-match-data
  347. (and (org-on-heading-p)
  348. (equal (downcase
  349. (or (org-entry-get
  350. nil "COOKIE_DATA")
  351. ""))
  352. "todo")))))
  353. (setq beg-cookie (match-beginning 1)
  354. end-cookie (match-end 1)
  355. cstat (+ cstat (if end-cookie 1 0))
  356. startsearch (point-at-eol)
  357. continue-from (match-beginning 0)
  358. is-percent (match-beginning 2)
  359. lim (cond
  360. ((org-on-heading-p) (outline-next-heading) (point))
  361. ((org-at-item-p) (org-end-of-item) (point))
  362. (t nil))
  363. c-on 0
  364. c-off 0)
  365. (when lim
  366. ;; find first checkbox for this cookie and gather
  367. ;; statistics from all that are at this indentation level
  368. (goto-char startsearch)
  369. (if (re-search-forward re-box lim t)
  370. (progn
  371. (org-beginning-of-item)
  372. (setq curr-ind (org-get-indentation))
  373. (setq next-ind curr-ind)
  374. (while (and (bolp) (org-at-item-p) (= curr-ind next-ind))
  375. (save-excursion (end-of-line) (setq eline (point)))
  376. (if (re-search-forward re-box eline t)
  377. (if (member (match-string 2) '("[ ]" "[-]"))
  378. (setq c-off (1+ c-off))
  379. (setq c-on (1+ c-on))
  380. )
  381. )
  382. (org-end-of-item)
  383. (setq next-ind (org-get-indentation))
  384. )))
  385. (goto-char continue-from)
  386. ;; update cookie
  387. (when end-cookie
  388. (delete-region beg-cookie end-cookie)
  389. (goto-char beg-cookie)
  390. (insert
  391. (if is-percent
  392. (format "[%d%%]" (/ (* 100 c-on) (max 1 (+ c-on c-off))))
  393. (format "[%d/%d]" c-on (+ c-on c-off)))))
  394. ;; update items checkbox if it has one
  395. (when (org-at-item-p)
  396. (org-beginning-of-item)
  397. (when (and (> (+ c-on c-off) 0)
  398. (re-search-forward re-box (point-at-eol) t))
  399. (setq beg-cookie (match-beginning 2)
  400. end-cookie (match-end 2))
  401. (delete-region beg-cookie end-cookie)
  402. (goto-char beg-cookie)
  403. (cond ((= c-off 0) (insert "[X]"))
  404. ((= c-on 0) (insert "[ ]"))
  405. (t (insert "[-]")))
  406. )))
  407. (goto-char continue-from))
  408. (when (interactive-p)
  409. (message "Checkbox statistics updated %s (%d places)"
  410. (if all "in entire file" "in current outline entry") cstat)))))
  411. (defun org-get-checkbox-statistics-face ()
  412. "Select the face for checkbox statistics.
  413. The face will be `org-done' when all relevant boxes are checked. Otherwise
  414. it will be `org-todo'."
  415. (if (match-end 1)
  416. (if (equal (match-string 1) "100%") 'org-done 'org-todo)
  417. (if (and (> (match-end 2) (match-beginning 2))
  418. (equal (match-string 2) (match-string 3)))
  419. 'org-done
  420. 'org-todo)))
  421. (defun org-beginning-of-item ()
  422. "Go to the beginning of the current hand-formatted item.
  423. If the cursor is not in an item, throw an error."
  424. (interactive)
  425. (let ((pos (point))
  426. (limit (save-excursion
  427. (condition-case nil
  428. (progn
  429. (org-back-to-heading)
  430. (beginning-of-line 2) (point))
  431. (error (point-min)))))
  432. (ind-empty (if org-empty-line-terminates-plain-lists 0 10000))
  433. ind ind1)
  434. (if (org-at-item-p)
  435. (beginning-of-line 1)
  436. (beginning-of-line 1)
  437. (skip-chars-forward " \t")
  438. (setq ind (current-column))
  439. (if (catch 'exit
  440. (while t
  441. (beginning-of-line 0)
  442. (if (or (bobp) (< (point) limit)) (throw 'exit nil))
  443. (if (looking-at "[ \t]*$")
  444. (setq ind1 ind-empty)
  445. (skip-chars-forward " \t")
  446. (setq ind1 (current-column)))
  447. (if (< ind1 ind)
  448. (progn (beginning-of-line 1) (throw 'exit (org-at-item-p))))))
  449. nil
  450. (goto-char pos)
  451. (error "Not in an item")))))
  452. (defun org-end-of-item ()
  453. "Go to the end of the current hand-formatted item.
  454. If the cursor is not in an item, throw an error."
  455. (interactive)
  456. (let* ((pos (point))
  457. ind1
  458. (ind-empty (if org-empty-line-terminates-plain-lists 0 10000))
  459. (limit (save-excursion (outline-next-heading) (point)))
  460. (ind (save-excursion
  461. (org-beginning-of-item)
  462. (skip-chars-forward " \t")
  463. (current-column)))
  464. (end (catch 'exit
  465. (while t
  466. (beginning-of-line 2)
  467. (if (eobp) (throw 'exit (point)))
  468. (if (>= (point) limit) (throw 'exit (point-at-bol)))
  469. (if (looking-at "[ \t]*$")
  470. (setq ind1 ind-empty)
  471. (skip-chars-forward " \t")
  472. (setq ind1 (current-column)))
  473. (if (<= ind1 ind)
  474. (throw 'exit (point-at-bol)))))))
  475. (if end
  476. (goto-char end)
  477. (goto-char pos)
  478. (error "Not in an item"))))
  479. (defun org-next-item ()
  480. "Move to the beginning of the next item in the current plain list.
  481. Error if not at a plain list, or if this is the last item in the list."
  482. (interactive)
  483. (let (ind ind1 (pos (point)))
  484. (org-beginning-of-item)
  485. (setq ind (org-get-indentation))
  486. (org-end-of-item)
  487. (setq ind1 (org-get-indentation))
  488. (unless (and (org-at-item-p) (= ind ind1))
  489. (goto-char pos)
  490. (error "On last item"))))
  491. (defun org-previous-item ()
  492. "Move to the beginning of the previous item in the current plain list.
  493. Error if not at a plain list, or if this is the first item in the list."
  494. (interactive)
  495. (let (beg ind ind1 (pos (point)))
  496. (org-beginning-of-item)
  497. (setq beg (point))
  498. (setq ind (org-get-indentation))
  499. (goto-char beg)
  500. (catch 'exit
  501. (while t
  502. (beginning-of-line 0)
  503. (if (looking-at "[ \t]*$")
  504. nil
  505. (if (<= (setq ind1 (org-get-indentation)) ind)
  506. (throw 'exit t)))))
  507. (condition-case nil
  508. (if (or (not (org-at-item-p))
  509. (< ind1 (1- ind)))
  510. (error "")
  511. (org-beginning-of-item))
  512. (error (goto-char pos)
  513. (error "On first item")))))
  514. (defun org-first-list-item-p ()
  515. "Is this heading the item in a plain list?"
  516. (unless (org-at-item-p)
  517. (error "Not at a plain list item"))
  518. (org-beginning-of-item)
  519. (= (point) (save-excursion (org-beginning-of-item-list))))
  520. (defun org-move-item-down ()
  521. "Move the plain list item at point down, i.e. swap with following item.
  522. Subitems (items with larger indentation) are considered part of the item,
  523. so this really moves item trees."
  524. (interactive)
  525. (let ((col (current-column))
  526. (pos (point))
  527. beg beg0 end end0 ind ind1 txt ne-end ne-beg)
  528. (org-beginning-of-item)
  529. (setq beg0 (point))
  530. (save-excursion
  531. (setq ne-beg (org-back-over-empty-lines))
  532. (setq beg (point)))
  533. (goto-char beg0)
  534. (setq ind (org-get-indentation))
  535. (org-end-of-item)
  536. (setq end0 (point))
  537. (setq ind1 (org-get-indentation))
  538. (setq ne-end (org-back-over-empty-lines))
  539. (setq end (point))
  540. (goto-char beg0)
  541. (when (and (org-first-list-item-p) (< ne-end ne-beg))
  542. ;; include less whitespace
  543. (save-excursion
  544. (goto-char beg)
  545. (forward-line (- ne-beg ne-end))
  546. (setq beg (point))))
  547. (goto-char end0)
  548. (if (and (org-at-item-p) (= ind ind1))
  549. (progn
  550. (org-end-of-item)
  551. (org-back-over-empty-lines)
  552. (setq txt (buffer-substring beg end))
  553. (save-excursion
  554. (delete-region beg end))
  555. (setq pos (point))
  556. (insert txt)
  557. (goto-char pos) (org-skip-whitespace)
  558. (org-maybe-renumber-ordered-list)
  559. (move-to-column col))
  560. (goto-char pos)
  561. (move-to-column col)
  562. (error "Cannot move this item further down"))))
  563. (defun org-move-item-up (arg)
  564. "Move the plain list item at point up, i.e. swap with previous item.
  565. Subitems (items with larger indentation) are considered part of the item,
  566. so this really moves item trees."
  567. (interactive "p")
  568. (let ((col (current-column)) (pos (point))
  569. beg beg0 end ind ind1 txt
  570. ne-beg ne-ins ins-end)
  571. (org-beginning-of-item)
  572. (setq beg0 (point))
  573. (setq ind (org-get-indentation))
  574. (save-excursion
  575. (setq ne-beg (org-back-over-empty-lines))
  576. (setq beg (point)))
  577. (goto-char beg0)
  578. (org-end-of-item)
  579. (org-back-over-empty-lines)
  580. (setq end (point))
  581. (goto-char beg0)
  582. (catch 'exit
  583. (while t
  584. (beginning-of-line 0)
  585. (if (looking-at "[ \t]*$")
  586. (if org-empty-line-terminates-plain-lists
  587. (progn
  588. (goto-char pos)
  589. (error "Cannot move this item further up"))
  590. nil)
  591. (if (<= (setq ind1 (org-get-indentation)) ind)
  592. (throw 'exit t)))))
  593. (condition-case nil
  594. (org-beginning-of-item)
  595. (error (goto-char beg0)
  596. (move-to-column col)
  597. (error "Cannot move this item further up")))
  598. (setq ind1 (org-get-indentation))
  599. (if (and (org-at-item-p) (= ind ind1))
  600. (progn
  601. (setq ne-ins (org-back-over-empty-lines))
  602. (setq txt (buffer-substring beg end))
  603. (save-excursion
  604. (delete-region beg end))
  605. (setq pos (point))
  606. (insert txt)
  607. (setq ins-end (point))
  608. (goto-char pos) (org-skip-whitespace)
  609. (when (and (org-first-list-item-p) (> ne-ins ne-beg))
  610. ;; Move whitespace back to beginning
  611. (save-excursion
  612. (goto-char ins-end)
  613. (let ((kill-whole-line t))
  614. (kill-line (- ne-ins ne-beg)) (point)))
  615. (insert (make-string (- ne-ins ne-beg) ?\n)))
  616. (org-maybe-renumber-ordered-list)
  617. (move-to-column col))
  618. (goto-char pos)
  619. (move-to-column col)
  620. (error "Cannot move this item further up"))))
  621. (defun org-maybe-renumber-ordered-list ()
  622. "Renumber the ordered list at point if setup allows it.
  623. This tests the user option `org-auto-renumber-ordered-lists' before
  624. doing the renumbering."
  625. (interactive)
  626. (when (and org-auto-renumber-ordered-lists
  627. (org-at-item-p))
  628. (if (match-beginning 3)
  629. (org-renumber-ordered-list 1)
  630. (org-fix-bullet-type))))
  631. (defun org-maybe-renumber-ordered-list-safe ()
  632. (condition-case nil
  633. (save-excursion
  634. (org-maybe-renumber-ordered-list))
  635. (error nil)))
  636. (defun org-cycle-list-bullet (&optional which)
  637. "Cycle through the different itemize/enumerate bullets.
  638. This cycle the entire list level through the sequence:
  639. `-' -> `+' -> `*' -> `1.' -> `1)'
  640. If WHICH is a string, use that as the new bullet. If WHICH is an integer,
  641. 0 means `-', 1 means `+' etc."
  642. (interactive "P")
  643. (org-preserve-lc
  644. (org-beginning-of-item-list)
  645. (org-at-item-p)
  646. (beginning-of-line 1)
  647. (let ((current (match-string 0))
  648. (prevp (eq which 'previous))
  649. new old)
  650. (setq new (cond
  651. ((and (numberp which)
  652. (nth (1- which) '("-" "+" "*" "1." "1)"))))
  653. ((string-match "-" current) (if prevp "1)" "+"))
  654. ((string-match "\\+" current)
  655. (if prevp "-" (if (looking-at "\\S-") "1." "*")))
  656. ((string-match "\\*" current) (if prevp "+" "1."))
  657. ((string-match "\\." current)
  658. (if prevp (if (looking-at "\\S-") "+" "*") "1)"))
  659. ((string-match ")" current) (if prevp "1." "-"))
  660. (t (error "This should not happen"))))
  661. (and (looking-at "\\([ \t]*\\)\\(\\S-+\\)")
  662. (setq old (match-string 2))
  663. (replace-match (concat "\\1" new)))
  664. (org-shift-item-indentation (- (length new) (length old)))
  665. (org-fix-bullet-type)
  666. (org-maybe-renumber-ordered-list))))
  667. (defun org-get-string-indentation (s)
  668. "What indentation has S due to SPACE and TAB at the beginning of the string?"
  669. (let ((n -1) (i 0) (w tab-width) c)
  670. (catch 'exit
  671. (while (< (setq n (1+ n)) (length s))
  672. (setq c (aref s n))
  673. (cond ((= c ?\ ) (setq i (1+ i)))
  674. ((= c ?\t) (setq i (* (/ (+ w i) w) w)))
  675. (t (throw 'exit t)))))
  676. i))
  677. (defun org-renumber-ordered-list (arg)
  678. "Renumber an ordered plain list.
  679. Cursor needs to be in the first line of an item, the line that starts
  680. with something like \"1.\" or \"2)\"."
  681. (interactive "p")
  682. (unless (and (org-at-item-p)
  683. (match-beginning 3))
  684. (error "This is not an ordered list"))
  685. (let ((line (org-current-line))
  686. (col (current-column))
  687. (ind (org-get-string-indentation
  688. (buffer-substring (point-at-bol) (match-beginning 3))))
  689. ;; (term (substring (match-string 3) -1))
  690. ind1 (n (1- arg))
  691. fmt bobp old new)
  692. ;; find where this list begins
  693. (org-beginning-of-item-list)
  694. (setq bobp (bobp))
  695. (looking-at "[ \t]*[0-9]+\\([.)]\\)")
  696. (setq fmt (concat "%d" (or (match-string 1) ".")))
  697. (beginning-of-line 0)
  698. ;; walk forward and replace these numbers
  699. (catch 'exit
  700. (while t
  701. (catch 'next
  702. (if bobp (setq bobp nil) (beginning-of-line 2))
  703. (if (eobp) (throw 'exit nil))
  704. (if (looking-at "[ \t]*$") (throw 'next nil))
  705. (skip-chars-forward " \t") (setq ind1 (current-column))
  706. (if (> ind1 ind) (throw 'next t))
  707. (if (< ind1 ind) (throw 'exit t))
  708. (if (not (org-at-item-p)) (throw 'exit nil))
  709. (setq old (match-string 2))
  710. (delete-region (match-beginning 2) (match-end 2))
  711. (goto-char (match-beginning 2))
  712. (insert (setq new (format fmt (setq n (1+ n)))))
  713. (org-shift-item-indentation (- (length new) (length old))))))
  714. (goto-line line)
  715. (org-move-to-column col)))
  716. (defun org-fix-bullet-type ()
  717. "Make sure all items in this list have the same bullet as the first item.
  718. Also, fix the indentation."
  719. (interactive)
  720. (unless (org-at-item-p) (error "This is not a list"))
  721. (let ((line (org-current-line))
  722. (col (current-column))
  723. (ind (current-indentation))
  724. ind1 bullet oldbullet)
  725. ;; find where this list begins
  726. (org-beginning-of-item-list)
  727. (beginning-of-line 1)
  728. ;; find out what the bullet type is
  729. (looking-at "[ \t]*\\(\\S-+\\)")
  730. (setq bullet (concat (match-string 1) " "))
  731. (if (and org-list-two-spaces-after-bullet-regexp
  732. (string-match org-list-two-spaces-after-bullet-regexp bullet))
  733. (setq bullet (concat bullet " ")))
  734. ;; walk forward and replace these numbers
  735. (beginning-of-line 0)
  736. (catch 'exit
  737. (while t
  738. (catch 'next
  739. (beginning-of-line 2)
  740. (if (eobp) (throw 'exit nil))
  741. (if (looking-at "[ \t]*$") (throw 'next nil))
  742. (skip-chars-forward " \t") (setq ind1 (current-column))
  743. (if (> ind1 ind) (throw 'next t))
  744. (if (< ind1 ind) (throw 'exit t))
  745. (if (not (org-at-item-p)) (throw 'exit nil))
  746. (skip-chars-forward " \t")
  747. (looking-at "\\S-+ *")
  748. (setq oldbullet (match-string 0))
  749. (unless (equal bullet oldbullet) (replace-match bullet))
  750. (org-shift-item-indentation (- (length bullet) (length oldbullet))))))
  751. (goto-line line)
  752. (org-move-to-column col)
  753. (if (string-match "[0-9]" bullet)
  754. (org-renumber-ordered-list 1))))
  755. (defun org-shift-item-indentation (delta)
  756. "Shift the indentation in current item by DELTA."
  757. (save-excursion
  758. (let ((beg (point-at-bol))
  759. (end (progn (org-end-of-item) (point)))
  760. i)
  761. (goto-char end)
  762. (beginning-of-line 0)
  763. (while (> (point) beg)
  764. (when (looking-at "[ \t]*\\S-")
  765. ;; this is not an empty line
  766. (setq i (org-get-indentation))
  767. (if (and (> i 0) (> (setq i (+ i delta)) 0))
  768. (indent-line-to i)))
  769. (beginning-of-line 0)))))
  770. (defun org-beginning-of-item-list ()
  771. "Go to the beginning of the current item list.
  772. I.e. to the first item in this list."
  773. (interactive)
  774. (org-beginning-of-item)
  775. (let ((pos (point-at-bol))
  776. (ind (org-get-indentation))
  777. ind1)
  778. ;; find where this list begins
  779. (catch 'exit
  780. (while t
  781. (catch 'next
  782. (beginning-of-line 0)
  783. (if (looking-at "[ \t]*$")
  784. (throw (if (bobp) 'exit 'next) t))
  785. (skip-chars-forward " \t") (setq ind1 (current-column))
  786. (if (or (< ind1 ind)
  787. (and (= ind1 ind)
  788. (not (org-at-item-p)))
  789. (and (= (point-at-bol) (point-min))
  790. (setq pos (point-min))))
  791. (throw 'exit t)
  792. (when (org-at-item-p) (setq pos (point-at-bol)))))))
  793. (goto-char pos)))
  794. (defun org-end-of-item-list ()
  795. "Go to the end of the current item list.
  796. I.e. to the text after the last item."
  797. (interactive)
  798. (org-beginning-of-item)
  799. (let ((pos (point-at-bol))
  800. (ind (org-get-indentation))
  801. ind1)
  802. ;; find where this list begins
  803. (catch 'exit
  804. (while t
  805. (catch 'next
  806. (beginning-of-line 2)
  807. (if (looking-at "[ \t]*$")
  808. (throw (if (eobp) 'exit 'next) t))
  809. (skip-chars-forward " \t") (setq ind1 (current-column))
  810. (if (or (< ind1 ind)
  811. (and (= ind1 ind)
  812. (not (org-at-item-p)))
  813. (eobp))
  814. (progn
  815. (setq pos (point-at-bol))
  816. (throw 'exit t))))))
  817. (goto-char pos)))
  818. (defvar org-last-indent-begin-marker (make-marker))
  819. (defvar org-last-indent-end-marker (make-marker))
  820. (defun org-outdent-item (arg)
  821. "Outdent a local list item."
  822. (interactive "p")
  823. (org-indent-item (- arg)))
  824. (defun org-indent-item (arg)
  825. "Indent a local list item."
  826. (interactive "p")
  827. (and (org-region-active-p) (org-cursor-to-region-beginning))
  828. (unless (org-at-item-p)
  829. (error "Not on an item"))
  830. (save-excursion
  831. (let (beg end ind ind1 tmp delta ind-down ind-up)
  832. (setq end (and (org-region-active-p) (region-end)))
  833. (if (memq last-command '(org-shiftmetaright org-shiftmetaleft))
  834. (setq beg org-last-indent-begin-marker
  835. end org-last-indent-end-marker)
  836. (org-beginning-of-item)
  837. (setq beg (move-marker org-last-indent-begin-marker (point)))
  838. (org-end-of-item)
  839. (setq end (move-marker org-last-indent-end-marker (or end (point)))))
  840. (goto-char beg)
  841. (setq tmp (org-item-indent-positions)
  842. ind (car tmp)
  843. ind-down (nth 2 tmp)
  844. ind-up (nth 1 tmp)
  845. delta (if (> arg 0)
  846. (if ind-down (- ind-down ind) 2)
  847. (if ind-up (- ind-up ind) -2)))
  848. (if (< (+ delta ind) 0) (error "Cannot outdent beyond margin"))
  849. (while (< (point) end)
  850. (beginning-of-line 1)
  851. (skip-chars-forward " \t") (setq ind1 (current-column))
  852. (delete-region (point-at-bol) (point))
  853. (or (eolp) (org-indent-to-column (+ ind1 delta)))
  854. (beginning-of-line 2))))
  855. (org-fix-bullet-type)
  856. (org-maybe-renumber-ordered-list-safe)
  857. (save-excursion
  858. (beginning-of-line 0)
  859. (condition-case nil (org-beginning-of-item) (error nil))
  860. (org-maybe-renumber-ordered-list-safe)))
  861. (defun org-item-indent-positions ()
  862. "Return indentation for plain list items.
  863. This returns a list with three values: The current indentation, the
  864. parent indentation and the indentation a child should have.
  865. Assumes cursor in item line."
  866. (let* ((bolpos (point-at-bol))
  867. (ind (org-get-indentation))
  868. ind-down ind-up pos)
  869. (save-excursion
  870. (org-beginning-of-item-list)
  871. (skip-chars-backward "\n\r \t")
  872. (when (org-in-item-p)
  873. (org-beginning-of-item)
  874. (setq ind-up (org-get-indentation))))
  875. (setq pos (point))
  876. (save-excursion
  877. (cond
  878. ((and (condition-case nil (progn (org-previous-item) t)
  879. (error nil))
  880. (or (forward-char 1) t)
  881. (re-search-forward "^\\([ \t]*\\([-+]\\|\\([0-9]+[.)]\\)\\)\\|[ \t]+\\*\\)\\( \\|$\\)" bolpos t))
  882. (setq ind-down (org-get-indentation)))
  883. ((and (goto-char pos)
  884. (org-at-item-p))
  885. (goto-char (match-end 0))
  886. (skip-chars-forward " \t")
  887. (setq ind-down (current-column)))))
  888. (list ind ind-up ind-down)))
  889. ;;; Send and receive lists
  890. (defun org-list-parse-list (&optional delete)
  891. "Parse the list at point and maybe DELETE it.
  892. Return a list containing first level items as strings and
  893. sublevels as a list of strings."
  894. (let* ((item-beginning (org-list-item-beginning))
  895. (start (car item-beginning))
  896. (end (org-list-end (cdr item-beginning)))
  897. output itemsep ltype)
  898. (while (re-search-forward org-list-beginning-re end t)
  899. (goto-char (match-beginning 3))
  900. (save-match-data
  901. (cond ((string-match "[0-9]" (match-string 2))
  902. (setq itemsep "[0-9]+\\(?:\\.\\|)\\)"
  903. ltype 'ordered))
  904. ((string-match "^.*::" (match-string 0))
  905. (setq itemsep "[-+]" ltype 'descriptive))
  906. (t (setq itemsep "[-+]" ltype 'unordered))))
  907. (let* ((indent1 (match-string 1))
  908. (nextitem (save-excursion
  909. (save-match-data
  910. (or (and (re-search-forward
  911. (concat "^" indent1 itemsep " *?") end t)
  912. (match-beginning 0)) end))))
  913. (item (buffer-substring
  914. (point)
  915. (or (and (re-search-forward
  916. org-list-beginning-re end t)
  917. (goto-char (match-beginning 0)))
  918. (goto-char end))))
  919. (nextindent (match-string 1))
  920. (item (org-trim item))
  921. (item (if (string-match "^\\[\\([xX ]\\)\\]" item)
  922. (replace-match (if (equal (match-string 1 item) " ")
  923. "[CBOFF]"
  924. "[CBON]")
  925. t nil item)
  926. item)))
  927. (push item output)
  928. (when (> (length nextindent)
  929. (length indent1))
  930. (narrow-to-region (point) nextitem)
  931. (push (org-list-parse-list) output)
  932. (widen))))
  933. (when delete (delete-region start end))
  934. (setq output (nreverse output))
  935. (push ltype output)))
  936. (defun org-list-item-beginning ()
  937. "Find the beginning of the list item.
  938. Return a cons which car is the beginning position of the item and
  939. cdr is the indentation string."
  940. (save-excursion
  941. (if (not (or (looking-at org-list-beginning-re)
  942. (re-search-backward
  943. org-list-beginning-re nil t)))
  944. (progn (goto-char (point-min)) (point))
  945. (cons (match-beginning 0) (match-string 1)))))
  946. (defun org-list-end (indent)
  947. "Return the position of the end of the list.
  948. INDENT is the indentation of the list."
  949. (save-excursion
  950. (catch 'exit
  951. (while (or (looking-at org-list-beginning-re)
  952. (looking-at (concat "^" indent "[ \t]+\\|^$")))
  953. (if (eq (point) (point-max))
  954. (throw 'exit (point-max)))
  955. (forward-line 1))) (point)))
  956. (defun org-list-insert-radio-list ()
  957. "Insert a radio list template appropriate for this major mode."
  958. (interactive)
  959. (let* ((e (assq major-mode org-list-radio-list-templates))
  960. (txt (nth 1 e))
  961. name pos)
  962. (unless e (error "No radio list setup defined for %s" major-mode))
  963. (setq name (read-string "List name: "))
  964. (while (string-match "%n" txt)
  965. (setq txt (replace-match name t t txt)))
  966. (or (bolp) (insert "\n"))
  967. (setq pos (point))
  968. (insert txt)
  969. (goto-char pos)))
  970. (defun org-list-send-list (&optional maybe)
  971. "Send a tranformed version of this list to the receiver position.
  972. With argument MAYBE, fail quietly if no transformation is defined for
  973. this list."
  974. (interactive)
  975. (catch 'exit
  976. (unless (org-at-item-p) (error "Not at a list"))
  977. (save-excursion
  978. (goto-char (car (org-list-item-beginning)))
  979. (beginning-of-line 0)
  980. (unless (looking-at "#\\+ORGLST: *SEND +\\([a-zA-Z0-9_]+\\) +\\([^ \t\r\n]+\\)\\( +.*\\)?")
  981. (if maybe
  982. (throw 'exit nil)
  983. (error "Don't know how to transform this list"))))
  984. (let* ((name (match-string 1))
  985. (item-beginning (org-list-item-beginning))
  986. (transform (intern (match-string 2)))
  987. (txt (buffer-substring-no-properties
  988. (car item-beginning)
  989. (org-list-end (cdr item-beginning))))
  990. (list (org-list-parse-list))
  991. beg)
  992. (unless (fboundp transform)
  993. (error "No such transformation function %s" transform))
  994. (setq txt (funcall transform list))
  995. ;; Find the insertion place
  996. (save-excursion
  997. (goto-char (point-min))
  998. (unless (re-search-forward
  999. (concat "BEGIN RECEIVE ORGLST +" name "\\([ \t]\\|$\\)") nil t)
  1000. (error "Don't know where to insert translated list"))
  1001. (goto-char (match-beginning 0))
  1002. (beginning-of-line 2)
  1003. (setq beg (point))
  1004. (unless (re-search-forward (concat "END RECEIVE ORGLST +" name) nil t)
  1005. (error "Cannot find end of insertion region"))
  1006. (beginning-of-line 1)
  1007. (delete-region beg (point))
  1008. (goto-char beg)
  1009. (insert txt "\n"))
  1010. (message "List converted and installed at receiver location"))))
  1011. (defun org-list-to-generic (list params)
  1012. "Convert a LIST parsed through `org-list-parse-list' to other formats.
  1013. Valid parameters PARAMS are
  1014. :ustart String to start an unordered list
  1015. :uend String to end an unordered list
  1016. :ostart String to start an ordered list
  1017. :oend String to end an ordered list
  1018. :dstart String to start a descriptive list
  1019. :dend String to end a descriptive list
  1020. :dtstart String to start a descriptive term
  1021. :dtend String to end a descriptive term
  1022. :ddstart String to start a description
  1023. :ddend String to end a description
  1024. :splice When set to t, return only list body lines, don't wrap
  1025. them into :[u/o]start and :[u/o]end. Default is nil.
  1026. :istart String to start a list item
  1027. :iend String to end a list item
  1028. :isep String to separate items
  1029. :lsep String to separate sublists
  1030. :cboff String to insert for an unchecked checkbox
  1031. :cbon String to insert for a checked checkbox"
  1032. (interactive)
  1033. (let* ((p params) sublist
  1034. (splicep (plist-get p :splice))
  1035. (ostart (plist-get p :ostart))
  1036. (oend (plist-get p :oend))
  1037. (ustart (plist-get p :ustart))
  1038. (uend (plist-get p :uend))
  1039. (dstart (plist-get p :dstart))
  1040. (dend (plist-get p :dend))
  1041. (dtstart (plist-get p :dtstart))
  1042. (dtend (plist-get p :dtend))
  1043. (ddstart (plist-get p :ddstart))
  1044. (ddend (plist-get p :ddend))
  1045. (istart (plist-get p :istart))
  1046. (iend (plist-get p :iend))
  1047. (isep (plist-get p :isep))
  1048. (lsep (plist-get p :lsep))
  1049. (cbon (plist-get p :cbon))
  1050. (cboff (plist-get p :cboff)))
  1051. (let ((wrapper
  1052. (cond ((eq (car list) 'ordered)
  1053. (concat ostart "\n%s" oend "\n"))
  1054. ((eq (car list) 'unordered)
  1055. (concat ustart "\n%s" uend "\n"))
  1056. ((eq (car list) 'descriptive)
  1057. (concat dstart "\n%s" dend "\n"))))
  1058. rtn term defstart defend)
  1059. (while (setq sublist (pop list))
  1060. (cond ((symbolp sublist) nil)
  1061. ((stringp sublist)
  1062. (when (string-match "^\\(.*\\) ::" sublist)
  1063. (setq term (org-trim (format (concat dtstart "%s" dtend)
  1064. (match-string 1 sublist))))
  1065. (setq sublist (substring sublist (1+ (length term)))))
  1066. (if (string-match "\\[CBON\\]" sublist)
  1067. (setq sublist (replace-match cbon t t sublist)))
  1068. (if (string-match "\\[CBOFF\\]" sublist)
  1069. (setq sublist (replace-match cboff t t sublist)))
  1070. (setq rtn (concat rtn istart term ddstart
  1071. sublist ddend iend isep)))
  1072. (t (setq rtn (concat rtn ;; previous list
  1073. lsep ;; list separator
  1074. (org-list-to-generic sublist p)
  1075. lsep ;; list separator
  1076. )))))
  1077. (format wrapper rtn))))
  1078. (defun org-list-to-latex (list &optional params)
  1079. "Convert LIST into a LaTeX list.
  1080. LIST is as returnd by `org-list-parse-list'. PARAMS is a property list
  1081. with overruling parameters for `org-list-to-generic'."
  1082. (org-list-to-generic
  1083. list
  1084. (org-combine-plists
  1085. '(:splicep nil :ostart "\\begin{enumerate}" :oend "\\end{enumerate}"
  1086. :ustart "\\begin{itemize}" :uend "\\end{itemize}"
  1087. :dstart "\\begin{description}" :dend "\\end{description}"
  1088. :dtstart "[" :dtend "]"
  1089. :ddstart "" :ddend ""
  1090. :istart "\\item " :iend ""
  1091. :isep "\n" :lsep "\n"
  1092. :cbon "\\texttt{[X]}" :cboff "\\texttt{[ ]}")
  1093. params)))
  1094. (defun org-list-to-html (list &optional params)
  1095. "Convert LIST into a HTML list.
  1096. LIST is as returnd by `org-list-parse-list'. PARAMS is a property list
  1097. with overruling parameters for `org-list-to-generic'."
  1098. (org-list-to-generic
  1099. list
  1100. (org-combine-plists
  1101. '(:splicep nil :ostart "<ol>" :oend "</ol>"
  1102. :ustart "<ul>" :uend "</ul>"
  1103. :dstart "<dl>" :dend "</dl>"
  1104. :dtstart "<dt>" :dtend "</dt>"
  1105. :ddstart "<dd>" :ddend "</dd>"
  1106. :istart "<li>" :iend "</li>"
  1107. :isep "\n" :lsep "\n"
  1108. :cbon "<code>[X]</code>" :cboff "<code>[ ]</code>")
  1109. params)))
  1110. (defun org-list-to-texinfo (list &optional params)
  1111. "Convert LIST into a Texinfo list.
  1112. LIST is as returnd by `org-list-parse-list'. PARAMS is a property list
  1113. with overruling parameters for `org-list-to-generic'."
  1114. (org-list-to-generic
  1115. list
  1116. (org-combine-plists
  1117. '(:splicep nil :ostart "@itemize @minus" :oend "@end itemize"
  1118. :ustart "@enumerate" :uend "@end enumerate"
  1119. :dstart "@table" :dend "@end table"
  1120. :dtstart "@item " :dtend "\n"
  1121. :ddstart "" :ddend ""
  1122. :istart "@item\n" :iend ""
  1123. :isep "\n" :lsep "\n"
  1124. :cbon "@code{[X]}" :cboff "@code{[ ]}")
  1125. params)))
  1126. (provide 'org-list)
  1127. ;; arch-tag: 73cf50c1-200f-4d1d-8a53-4e842a5b11c8
  1128. ;;; org-list.el ends here