org-list.el 40 KB

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