org-list.el 39 KB

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