org-list.el 40 KB

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