1 ;;; org-list.el --- Plain lists for Org-mode
3 ;; Copyright (C) 2004-2015 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Bastien Guerry <bzg@gnu.org>
7 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; Homepage: http://orgmode.org
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; 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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
28 ;; This file contains the code dealing with plain lists in Org-mode.
30 ;; The core concept behind lists is their structure. A structure is
31 ;; a snapshot of the list, in the shape of a data tree (see
32 ;; `org-list-struct').
34 ;; Once the list structure is stored, it is possible to make changes
35 ;; on it that will be mirrored to the real list or to get information
36 ;; about the list, using accessors and methods provided in the
37 ;; library. Most of them require the use of one or two helper
38 ;; functions, namely `org-list-parents-alist' and
39 ;; `org-list-prevs-alist'.
41 ;; Structure is eventually applied to the buffer with
42 ;; `org-list-write-struct'. This function repairs (bullets,
43 ;; indentation, checkboxes) the list in the process. It should be
44 ;; called near the end of any function working on structures.
46 ;; Thus, a function applying to lists should usually follow this
49 ;; 1. Verify point is in a list and grab item beginning (with the same
50 ;; function `org-in-item-p'). If the function requires the cursor
51 ;; to be at item's bullet, `org-at-item-p' is more selective. It
52 ;; is also possible to move point to the closest item with
53 ;; `org-list-search-backward', or `org-list-search-forward',
54 ;; applied to the function `org-item-beginning-re'.
56 ;; 2. Get list structure with `org-list-struct'.
58 ;; 3. Compute one, or both, helper functions,
59 ;; (`org-list-parents-alist', `org-list-prevs-alist') depending on
62 ;; 4. Proceed with the modifications, using methods and accessors.
64 ;; 5. Verify and apply structure to buffer, using
65 ;; `org-list-write-struct'.
67 ;; 6. If changes made to the list might have modified check-boxes,
68 ;; call `org-update-checkbox-count-maybe'.
70 ;; Computing a structure can be a costly operation on huge lists (a
71 ;; few thousand lines long). Thus, code should follow the rule:
72 ;; "collect once, use many". As a corollary, it is usually a bad idea
73 ;; to use directly an interactive function inside the code, as those,
74 ;; being independent entities, read the whole list structure another
84 (defvar org-M-RET-may-split-line
)
85 (defvar org-auto-align-tags
)
86 (defvar org-blank-before-new-entry
)
87 (defvar org-clock-string
)
88 (defvar org-closed-string
)
89 (defvar org-deadline-string
)
90 (defvar org-description-max-indent
)
91 (defvar org-odd-levels-only
)
92 (defvar org-scheduled-string
)
93 (defvar org-ts-regexp
)
94 (defvar org-ts-regexp-both
)
95 (defvar org-drawer-regexp
)
97 (declare-function outline-invisible-p
"outline" (&optional pos
))
98 (declare-function outline-flag-region
"outline" (from to flag
))
99 (declare-function outline-next-heading
"outline" ())
100 (declare-function outline-previous-heading
"outline" ())
102 (declare-function org-at-heading-p
"org" (&optional ignored
))
103 (declare-function org-before-first-heading-p
"org" ())
104 (declare-function org-back-to-heading
"org" (&optional invisible-ok
))
105 (declare-function org-combine-plists
"org" (&rest plists
))
106 (declare-function org-count
"org" (cl-item cl-seq
))
107 (declare-function org-current-level
"org" ())
108 (declare-function org-entry-get
"org"
109 (pom property
&optional inherit literal-nil
))
110 (declare-function org-fix-tags-on-the-fly
"org" ())
111 (declare-function org-get-indentation
"org" (&optional line
))
112 (declare-function org-icompleting-read
"org" (&rest args
))
113 (declare-function org-in-block-p
"org" (names))
114 (declare-function org-in-regexp
"org" (re &optional nlines visually
))
115 (declare-function org-level-increment
"org" ())
116 (declare-function org-narrow-to-subtree
"org" ())
117 (declare-function org-at-heading-p
"org" (&optional invisible-ok
))
118 (declare-function org-previous-line-empty-p
"org" ())
119 (declare-function org-remove-if
"org" (predicate seq
))
120 (declare-function org-reduced-level
"org" (L))
121 (declare-function org-show-subtree
"org" ())
122 (declare-function org-sort-remove-invisible
"org" (S))
123 (declare-function org-time-string-to-seconds
"org" (s))
124 (declare-function org-timer-hms-to-secs
"org-timer" (hms))
125 (declare-function org-timer-item
"org-timer" (&optional arg
))
126 (declare-function org-trim
"org" (s))
127 (declare-function org-uniquify
"org" (list))
129 (declare-function org-inlinetask-goto-beginning
"org-inlinetask" ())
130 (declare-function org-inlinetask-goto-end
"org-inlinetask" ())
131 (declare-function org-inlinetask-in-task-p
"org-inlinetask" ())
132 (declare-function org-inlinetask-outline-regexp
"org-inlinetask" ())
134 (declare-function org-export-string-as
"ox"
135 (string backend
&optional body-only ext-plist
))
137 (declare-function org-element-update-syntax
"org-element" ())
141 ;;; Configuration variables
143 (defgroup org-plain-lists nil
144 "Options concerning plain lists in Org-mode."
145 :tag
"Org Plain lists"
146 :group
'org-structure
)
148 (defcustom org-cycle-include-plain-lists t
149 "When t, make TAB cycle visibility on plain list items.
150 Cycling plain lists works only when the cursor is on a plain list
151 item. When the cursor is on an outline heading, plain lists are
152 treated as text. This is the most stable way of handling this,
153 which is why it is the default.
155 When this is the symbol `integrate', then integrate plain list
156 items when cycling, as if they were children of outline headings.
158 This setting can lead to strange effects when switching visibility
159 to `children', because the first \"child\" in a subtree decides
160 what children should be listed. If that first \"child\" is a
161 plain list item with an implied large level number, all true
162 children and grand children of the outline heading will be
163 exposed in a children' view."
164 :group
'org-plain-lists
167 (const :tag
"Never" nil
)
168 (const :tag
"With cursor in plain list (recommended)" t
)
169 (const :tag
"As children of outline headings" integrate
)))
171 (defcustom org-list-demote-modify-bullet nil
172 "Default bullet type installed when demoting an item.
173 This is an association list, for each bullet type, this alist will point
174 to the bullet that should be used when this item is demoted.
177 (setq org-list-demote-modify-bullet
178 '((\"+\" . \"-\") (\"-\" . \"+\") (\"*\" . \"+\")))
183 + Silence of the Lambs
186 + The Hunt for Red October
192 - Silence of the Lambs
195 - The Hunt for Red October
197 :group
'org-plain-lists
200 (choice :tag
"If the current bullet is "
206 (choice :tag
"demotion will change it to"
213 (defcustom org-plain-list-ordered-item-terminator t
214 "The character that makes a line with leading number an ordered list item.
215 Valid values are ?. and ?\). To get both terminators, use t.
217 This variable needs to be set before org.el is loaded. If you
218 need to make a change while Emacs is running, use the customize
219 interface or run the following code after updating it:
221 \\[org-element-update-syntax]"
222 :group
'org-plain-lists
223 :type
'(choice (const :tag
"dot like in \"2.\"" ?.
)
224 (const :tag
"paren like in \"2)\"" ?\
))
225 (const :tag
"both" t
))
226 :set
(lambda (var val
) (set var val
)
227 (when (featurep 'org-element
) (org-element-update-syntax))))
229 (define-obsolete-variable-alias 'org-alphabetical-lists
230 'org-list-allow-alphabetical
"24.4") ; Since 8.0
231 (defcustom org-list-allow-alphabetical nil
232 "Non-nil means single character alphabetical bullets are allowed.
234 Both uppercase and lowercase are handled. Lists with more than
235 26 items will fallback to standard numbering. Alphabetical
236 counters like \"[@c]\" will be recognized.
238 This variable needs to be set before org.el is loaded. If you
239 need to make a change while Emacs is running, use the customize
240 interface or run the following code after updating it:
242 \\[org-element-update-syntax]"
243 :group
'org-plain-lists
246 :set
(lambda (var val
) (set var val
)
247 (when (featurep 'org-element
) (org-element-update-syntax))))
249 (defcustom org-list-two-spaces-after-bullet-regexp nil
250 "A regular expression matching bullets that should have 2 spaces after them.
251 When nil, no bullet will have two spaces after them. When
252 a string, it will be used as a regular expression. When the
253 bullet type of a list is changed, the new bullet type will be
254 matched against this regexp. If it matches, there will be two
255 spaces instead of one after the bullet in each item of the list."
256 :group
'org-plain-lists
258 (const :tag
"never" nil
)
261 (define-obsolete-variable-alias 'org-empty-line-terminates-plain-lists
262 'org-list-empty-line-terminates-plain-lists
"24.4") ;; Since 8.0
263 (defcustom org-list-empty-line-terminates-plain-lists nil
264 "Non-nil means an empty line ends all plain list levels.
265 Otherwise, two of them will be necessary."
266 :group
'org-plain-lists
269 (defcustom org-list-automatic-rules
'((checkbox . t
)
271 "Non-nil means apply set of rules when acting on lists.
272 By default, automatic actions are taken when using
273 \\[org-meta-return], \\[org-metaright], \\[org-metaleft],
274 \\[org-shiftmetaright], \\[org-shiftmetaleft],
275 \\[org-ctrl-c-minus], \\[org-toggle-checkbox] or
276 \\[org-insert-todo-heading]. You can disable individually these
277 rules by setting them to nil. Valid rules are:
279 checkbox when non-nil, checkbox statistics is updated each time
280 you either insert a new checkbox or toggle a checkbox.
281 indent when non-nil, indenting or outdenting list top-item
282 with its subtree will move the whole list and
283 outdenting a list whose bullet is * to column 0 will
284 change that bullet to \"-\"."
285 :group
'org-plain-lists
287 :type
'(alist :tag
"Sets of rules"
290 (const :tag
"Checkbox" checkbox
)
291 (const :tag
"Indent" indent
))
293 (boolean :tag
"Activate" :value t
)))
295 (defcustom org-list-use-circular-motion nil
296 "Non-nil means commands implying motion in lists should be cyclic.
298 In that case, the item following the last item is the first one,
299 and the item preceding the first item is the last one.
301 This affects the behavior of \\[org-move-item-up],
302 \\[org-move-item-down], \\[org-next-item] and
303 \\[org-previous-item]."
304 :group
'org-plain-lists
308 (defvar org-checkbox-statistics-hook nil
309 "Hook that is run whenever Org thinks checkbox statistics should be updated.
310 This hook runs even if checkbox rule in
311 `org-list-automatic-rules' does not apply, so it can be used to
312 implement alternative ways of collecting statistics
315 (define-obsolete-variable-alias 'org-hierarchical-checkbox-statistics
316 'org-checkbox-hierarchical-statistics
"24.4") ;; Since 8.0
317 (defcustom org-checkbox-hierarchical-statistics t
318 "Non-nil means checkbox statistics counts only the state of direct children.
319 When nil, all boxes below the cookie are counted.
320 This can be set to nil on a per-node basis using a COOKIE_DATA property
321 with the word \"recursive\" in the value."
322 :group
'org-plain-lists
325 (org-defvaralias 'org-description-max-indent
326 'org-list-description-max-indent
) ;; Since 8.0
327 (defcustom org-list-description-max-indent
20
328 "Maximum indentation for the second line of a description list.
329 When the indentation would be larger than this, it will become
330 5 characters instead."
331 :group
'org-plain-lists
334 (defcustom org-list-indent-offset
0
335 "Additional indentation for sub-items in a list.
336 By setting this to a small number, usually 1 or 2, one can more
337 clearly distinguish sub-items in a list."
338 :group
'org-plain-lists
342 (defcustom org-list-radio-list-templates
343 '((latex-mode "% BEGIN RECEIVE ORGLST %n
344 % END RECEIVE ORGLST %n
346 #+ORGLST: SEND %n org-list-to-latex
349 (texinfo-mode "@c BEGIN RECEIVE ORGLST %n
350 @c END RECEIVE ORGLST %n
352 #+ORGLST: SEND %n org-list-to-texinfo
355 (html-mode "<!-- BEGIN RECEIVE ORGLST %n -->
356 <!-- END RECEIVE ORGLST %n -->
358 #+ORGLST: SEND %n org-list-to-html
361 "Templates for radio lists in different major modes.
362 All occurrences of %n in a template will be replaced with the name of the
363 list, obtained by prompting the user."
364 :group
'org-plain-lists
366 (list (symbol :tag
"Major mode")
367 (string :tag
"Format"))))
369 (defvar org-list-forbidden-blocks
'("example" "verse" "src" "ascii" "beamer"
370 "html" "latex" "odt")
371 "Names of blocks where lists are not allowed.
372 Names must be in lower case.")
374 (defvar org-list-export-context
'(block inlinetask
)
375 "Context types where lists will be interpreted during export.
377 Valid types are `drawer', `inlinetask' and `block'. More
378 specifically, type `block' is determined by the variable
379 `org-list-forbidden-blocks'.")
383 ;;; Predicates and regexps
385 (defconst org-list-end-re
(if org-list-empty-line-terminates-plain-lists
"^[ \t]*\n"
387 "Regex corresponding to the end of a list.
388 It depends on `org-list-empty-line-terminates-plain-lists'.")
390 (defconst org-list-full-item-re
391 (concat "^[ \t]*\\(\\(?:[-+*]\\|\\(?:[0-9]+\\|[A-Za-z]\\)[.)]\\)\\(?:[ \t]+\\|$\\)\\)"
392 "\\(?:\\[@\\(?:start:\\)?\\([0-9]+\\|[A-Za-z]\\)\\][ \t]*\\)?"
393 "\\(?:\\(\\[[ X-]\\]\\)\\(?:[ \t]+\\|$\\)\\)?"
394 "\\(?:\\(.*\\)[ \t]+::\\(?:[ \t]+\\|$\\)\\)?")
395 "Matches a list item and puts everything into groups:
399 group 4: description tag")
401 (defun org-item-re ()
402 "Return the correct regular expression for plain lists."
404 ((eq org-plain-list-ordered-item-terminator t
) "[.)]")
405 ((= org-plain-list-ordered-item-terminator ?\
)) ")")
406 ((= org-plain-list-ordered-item-terminator ?.
) "\\.")
408 (alpha (if org-list-allow-alphabetical
"\\|[A-Za-z]" "")))
409 (concat "\\([ \t]*\\([-+]\\|\\(\\([0-9]+" alpha
"\\)" term
410 "\\)\\)\\|[ \t]+\\*\\)\\([ \t]+\\|$\\)")))
412 (defsubst org-item-beginning-re
()
413 "Regexp matching the beginning of a plain list item."
414 (concat "^" (org-item-re)))
416 (defun org-list-at-regexp-after-bullet-p (regexp)
417 "Is point at a list item with REGEXP after bullet?"
420 (goto-char (match-end 0))
421 (let ((counter-re (concat "\\(?:\\[@\\(?:start:\\)?"
422 (if org-list-allow-alphabetical
423 "\\([0-9]+\\|[A-Za-z]\\)"
426 ;; Ignore counter if any
427 (when (looking-at counter-re
) (goto-char (match-end 0))))
428 (looking-at regexp
))))
430 (defun org-list-in-valid-context-p ()
431 "Is point in a context where lists are allowed?"
432 (not (org-in-block-p org-list-forbidden-blocks
)))
434 (defun org-in-item-p ()
435 "Return item beginning position when in a plain list, nil otherwise."
438 (let* ((case-fold-search t
)
439 (context (org-list-context))
440 (lim-up (car context
))
441 (inlinetask-re (and (featurep 'org-inlinetask
)
442 (org-inlinetask-outline-regexp)))
443 (item-re (org-item-re))
444 ;; Indentation isn't meaningful when point starts at an empty
445 ;; line or an inline task.
446 (ind-ref (if (or (looking-at "^[ \t]*$")
447 (and inlinetask-re
(looking-at inlinetask-re
)))
449 (org-get-indentation))))
451 ((eq (nth 2 context
) 'invalid
) nil
)
452 ((looking-at item-re
) (point))
454 ;; Detect if cursor in amidst `org-list-end-re'. First, count
455 ;; number HL of hard lines it takes, then call `org-in-regexp'
456 ;; to compute its boundaries END-BOUNDS. When point is
457 ;; in-between, move cursor before regexp beginning.
458 (let ((hl 0) (i -
1) end-bounds
)
460 (while (setq i
(string-match
461 "[\r\n]" org-list-end-re
(1+ i
)))
463 (setq end-bounds
(org-in-regexp org-list-end-re hl
)))
464 (>= (point) (car end-bounds
))
465 (< (point) (cdr end-bounds
)))
466 (goto-char (car end-bounds
))
468 ;; Look for an item, less indented that reference line.
471 (let ((ind (org-get-indentation)))
473 ;; This is exactly what we want.
474 ((and (looking-at item-re
) (< ind ind-ref
))
475 (throw 'exit
(point)))
476 ;; At upper bound of search or looking at the end of a
477 ;; previous list: search is over.
478 ((<= (point) lim-up
) (throw 'exit nil
))
479 ((looking-at org-list-end-re
) (throw 'exit nil
))
480 ;; Skip blocks, drawers, inline-tasks, blank lines
481 ((and (looking-at "^[ \t]*#\\+end_")
482 (re-search-backward "^[ \t]*#\\+begin_" lim-up t
)))
483 ((and (looking-at "^[ \t]*:END:")
484 (re-search-backward org-drawer-regexp lim-up t
))
486 ((and inlinetask-re
(looking-at inlinetask-re
))
487 (org-inlinetask-goto-beginning)
489 ((looking-at "^[ \t]*$") (forward-line -
1))
490 ;; Text at column 0 cannot belong to a list: stop.
491 ((zerop ind
) (throw 'exit nil
))
492 ;; Normal text less indented than reference line, take
493 ;; it as new reference.
497 (t (forward-line -
1)))))))))))
499 (defun org-at-item-p ()
500 "Is point in a line starting a hand-formatted item?"
503 (and (looking-at (org-item-re)) (org-list-in-valid-context-p))))
505 (defun org-at-item-bullet-p ()
506 "Is point at the bullet of a plain list item?"
508 (not (member (char-after) '(?\ ?
\t)))
509 (< (point) (match-end 0))))
511 (defun org-at-item-timer-p ()
512 "Is point at a line starting a plain list item with a timer?"
513 (org-list-at-regexp-after-bullet-p
514 "\\([0-9]+:[0-9]+:[0-9]+\\)[ \t]+::[ \t]+"))
516 (defun org-at-item-description-p ()
517 "Is point at a description list item?"
518 (org-list-at-regexp-after-bullet-p "\\(\\S-.+\\)[ \t]+::\\([ \t]+\\|$\\)"))
520 (defun org-at-item-checkbox-p ()
521 "Is point at a line starting a plain-list item with a checklet?"
522 (org-list-at-regexp-after-bullet-p "\\(\\[[- X]\\]\\)[ \t]+"))
524 (defun org-at-item-counter-p ()
525 "Is point at a line starting a plain-list item with a counter?"
527 (looking-at org-list-full-item-re
)
532 ;;; Structures and helper functions
534 (defun org-list-context ()
535 "Determine context, and its boundaries, around point.
537 Context will be a cell like (MIN MAX CONTEXT) where MIN and MAX
538 are boundaries and CONTEXT is a symbol among `drawer', `block',
539 `invalid', `inlinetask' and nil.
541 Contexts `block' and `invalid' refer to `org-list-forbidden-blocks'."
544 (org-with-limited-levels
546 (let ((case-fold-search t
) (pos (point)) beg end context-type
547 ;; Get positions of surrounding headings. This is the
549 (lim-up (or (save-excursion (and (ignore-errors (org-back-to-heading t
))
552 (lim-down (or (save-excursion (outline-next-heading)) (point-max))))
553 ;; Is point inside a drawer?
554 (let ((end-re "^[ \t]*:END:")
555 (beg-re org-drawer-regexp
))
556 (when (save-excursion
557 (and (not (looking-at beg-re
))
558 (not (looking-at end-re
))
559 (setq beg
(and (re-search-backward beg-re lim-up t
)
560 (1+ (point-at-eol))))
561 (setq end
(or (and (re-search-forward end-re lim-down t
)
562 (1- (match-beginning 0)))
565 (setq lim-up beg lim-down end context-type
'drawer
)))
566 ;; Is point strictly in a block, and of which type?
567 (let ((block-re "^[ \t]*#\\+\\(begin\\|end\\)_") type
)
568 (when (save-excursion
569 (and (not (looking-at block-re
))
570 (setq beg
(and (re-search-backward block-re lim-up t
)
571 (1+ (point-at-eol))))
572 (looking-at "^[ \t]*#\\+begin_\\(\\S-+\\)")
573 (setq type
(downcase (match-string 1)))
575 (setq end
(or (and (re-search-forward block-re lim-down t
)
579 (equal (downcase (match-string 1)) "end")))
580 (setq lim-up beg lim-down end
581 context-type
(if (member type org-list-forbidden-blocks
)
583 ;; Is point in an inlinetask?
584 (when (and (featurep 'org-inlinetask
)
586 (let* ((beg-re (org-inlinetask-outline-regexp))
587 (end-re (concat beg-re
"END[ \t]*$")))
588 (and (not (looking-at "^\\*+"))
589 (setq beg
(and (re-search-backward beg-re lim-up t
)
590 (1+ (point-at-eol))))
591 (not (looking-at end-re
))
592 (setq end
(and (re-search-forward end-re lim-down t
)
593 (1- (match-beginning 0))))
595 (setq lim-up beg lim-down end context-type
'inlinetask
))
596 ;; Return context boundaries and type.
597 (list lim-up lim-down context-type
))))))
599 (defun org-list-struct ()
600 "Return structure of list at point.
602 A list structure is an alist where key is point at item, and
605 2. bullet with trailing whitespace,
606 3. bullet counter, if any,
608 5. description tag, if any,
609 6. position at item end.
611 Thus the following list, where numbers in parens are
616 5. [@5] sub-item 2 (34)
617 some other text belonging to first item (55)
619 + tag :: description (109)
622 will get the following structure:
624 \(\(1 0 \"- \" nil \"[X]\" nil 97\)
625 \(18 2 \"1. \" nil nil nil 34\)
626 \(34 2 \"5. \" \"5\" nil nil 55\)
627 \(97 0 \"- \" nil nil nil 131\)
628 \(109 2 \"+ \" nil nil \"tag\" 131\)
630 Assume point is at an item."
633 (let* ((case-fold-search t
)
634 (context (org-list-context))
635 (lim-up (car context
))
636 (lim-down (nth 1 context
))
638 (item-re (org-item-re))
639 (inlinetask-re (and (featurep 'org-inlinetask
)
640 (org-inlinetask-outline-regexp)))
641 (beg-cell (cons (point) (org-get-indentation)))
642 itm-lst itm-lst-2 end-lst end-lst-2 struct
645 ;; Return association at point.
647 (looking-at org-list-full-item-re
)
648 (let ((bullet (match-string-no-properties 1)))
652 (match-string-no-properties 2) ; counter
653 (match-string-no-properties 3) ; checkbox
655 (and (save-match-data (string-match "[-+*]" bullet
))
656 (match-string-no-properties 4)))))))
659 ;; Ensure list ends at the first blank line.
661 (skip-chars-backward " \r\t\n")
662 (min (1+ (point-at-eol)) lim-down
)))))
663 ;; 1. Read list from starting item to its beginning, and save
664 ;; top item position and indentation in BEG-CELL. Also store
665 ;; ending position of items in END-LST.
669 (let ((ind (org-get-indentation)))
672 ;; At upward limit: if we ended at an item, store it,
673 ;; else dismiss useless data recorded above BEG-CELL.
677 (if (not (looking-at item-re
))
678 (memq (assq (car beg-cell
) itm-lst
) itm-lst
)
679 (setq beg-cell
(cons (point) ind
))
680 (cons (funcall assoc-at-point ind
) itm-lst
)))))
681 ;; Looking at a list ending regexp. Dismiss useless
682 ;; data recorded above BEG-CELL. Jump to part 2.
683 ((looking-at org-list-end-re
)
686 (memq (assq (car beg-cell
) itm-lst
) itm-lst
))))
687 ;; Point is at an item. Add data to ITM-LST. It may
688 ;; also end a previous item: save it in END-LST. If
689 ;; ind is less or equal than BEG-CELL and there is no
690 ;; end at this ind or lesser, this item becomes the new
692 ((looking-at item-re
)
693 (push (funcall assoc-at-point ind
) itm-lst
)
694 (push (cons ind
(point)) end-lst
)
695 (when (< ind text-min-ind
) (setq beg-cell
(cons (point) ind
)))
697 ;; Skip blocks, drawers, inline tasks, blank lines.
698 ((and (looking-at "^[ \t]*#\\+end_")
699 (re-search-backward "^[ \t]*#\\+begin_" lim-up t
)))
700 ((and (looking-at "^[ \t]*:END:")
701 (re-search-backward org-drawer-regexp lim-up t
))
703 ((and inlinetask-re
(looking-at inlinetask-re
))
704 (org-inlinetask-goto-beginning)
706 ((looking-at "^[ \t]*$")
708 ;; From there, point is not at an item. Interpret
709 ;; line's indentation:
710 ;; - text at column 0 is necessarily out of any list.
711 ;; Dismiss data recorded above BEG-CELL. Jump to
713 ;; - any other case may be an ending position for an
714 ;; hypothetical item above. Store it and proceed.
718 (memq (assq (car beg-cell
) itm-lst
) itm-lst
))))
720 (when (< ind text-min-ind
) (setq text-min-ind ind
))
721 (push (cons ind
(point)) end-lst
)
722 (forward-line -
1)))))))
723 ;; 2. Read list from starting point to its end, that is until we
724 ;; get out of context, or that a non-item line is less or
725 ;; equally indented than BEG-CELL's cdr. Also, store ending
726 ;; position of items in END-LST-2.
729 (let ((ind (org-get-indentation)))
731 ((>= (point) lim-down
)
732 ;; At downward limit: this is de facto the end of the
733 ;; list. Save point as an ending position, and jump to
736 (push (cons 0 (funcall end-before-blank
)) end-lst-2
)))
737 ;; Looking at a list ending regexp. Save point as an
738 ;; ending position and jump to part 3.
739 ((looking-at org-list-end-re
)
740 (throw 'exit
(push (cons 0 (point)) end-lst-2
)))
741 ((looking-at item-re
)
742 ;; Point is at an item. Add data to ITM-LST-2. It may
743 ;; also end a previous item, so save it in END-LST-2.
744 (push (funcall assoc-at-point ind
) itm-lst-2
)
745 (push (cons ind
(point)) end-lst-2
)
747 ;; Skip inline tasks and blank lines along the way
748 ((and inlinetask-re
(looking-at inlinetask-re
))
749 (org-inlinetask-goto-end))
750 ((looking-at "^[ \t]*$")
752 ;; Ind is lesser or equal than BEG-CELL's. The list is
753 ;; over: store point as an ending position and jump to
755 ((<= ind
(cdr beg-cell
))
757 (push (cons 0 (funcall end-before-blank
)) end-lst-2
)))
758 ;; Else, if ind is lesser or equal than previous item's,
759 ;; this is an ending position: store it. In any case,
760 ;; skip block or drawer at point, and move to next line.
762 (when (<= ind
(nth 1 (car itm-lst-2
)))
763 (push (cons ind
(point)) end-lst-2
))
765 ((and (looking-at "^[ \t]*#\\+begin_")
766 (re-search-forward "^[ \t]*#\\+end_" lim-down t
)))
767 ((and (looking-at org-drawer-regexp
)
768 (re-search-forward "^[ \t]*:END:" lim-down t
))))
769 (forward-line 1))))))
770 (setq struct
(append itm-lst
(cdr (nreverse itm-lst-2
)))
771 end-lst
(append end-lst
(cdr (nreverse end-lst-2
))))
772 ;; 3. Associate each item to its end position.
773 (org-list-struct-assoc-end struct end-lst
)
777 (defun org-list-struct-assoc-end (struct end-list
)
778 "Associate proper ending point to items in STRUCT.
780 END-LIST is a pseudo-alist where car is indentation and cdr is
783 This function modifies STRUCT."
784 (let ((endings end-list
))
787 (let ((pos (car elt
))
789 ;; Remove end candidates behind current item.
790 (while (or (<= (cdar endings
) pos
))
792 ;; Add end position to item assoc.
793 (let ((old-end (nthcdr 6 elt
))
794 (new-end (assoc-default ind endings
'<=)))
796 (setcar old-end new-end
)
797 (setcdr elt
(append (cdr elt
) (list new-end
)))))))
800 (defun org-list-prevs-alist (struct)
801 "Return alist between item and previous item in STRUCT."
802 (let ((item-end-alist (mapcar (lambda (e) (cons (car e
) (nth 6 e
)))
805 (let ((prev (car (rassq (car e
) item-end-alist
))))
806 (cons (car e
) prev
)))
809 (defun org-list-parents-alist (struct)
810 "Return alist between item and parent in STRUCT."
811 (let* ((ind-to-ori (list (list (nth 1 (car struct
)))))
812 (top-item (org-list-get-top-point struct
))
813 (prev-pos (list top-item
)))
815 (mapcar (lambda (item)
816 (let ((pos (car item
))
818 (prev-ind (caar ind-to-ori
)))
822 ;; A sub-list is over. Find the associated
823 ;; origin in IND-TO-ORI. If it cannot be
824 ;; found (ill-formed list), set its parent as
825 ;; the first item less indented. If there is
826 ;; none, make it a top-level item.
828 (or (member (assq ind ind-to-ori
) ind-to-ori
)
832 (when (< (car e
) ind
)
833 (throw 'exit
(member e ind-to-ori
))))
836 (cons pos
(cdar ind-to-ori
)))
837 ;; A sub-list starts. Every item at IND will
838 ;; have previous item as its parent.
840 (let ((origin (nth 1 prev-pos
)))
841 (push (cons ind origin
) ind-to-ori
)
843 ;; Another item in the same sub-list: it shares
844 ;; the same parent as the previous item.
845 (t (cons pos
(cdar ind-to-ori
))))))
852 (defsubst org-list-get-nth
(n key struct
)
853 "Return the Nth value of KEY in STRUCT."
854 (nth n
(assq key struct
)))
856 (defun org-list-set-nth (n key struct new
)
857 "Set the Nth value of KEY in STRUCT to NEW.
858 \nThis function modifies STRUCT."
859 (setcar (nthcdr n
(assq key struct
)) new
))
861 (defsubst org-list-get-ind
(item struct
)
862 "Return indentation of ITEM in STRUCT."
863 (org-list-get-nth 1 item struct
))
865 (defun org-list-set-ind (item struct ind
)
866 "Set indentation of ITEM in STRUCT to IND.
867 \nThis function modifies STRUCT."
868 (org-list-set-nth 1 item struct ind
))
870 (defsubst org-list-get-bullet
(item struct
)
871 "Return bullet of ITEM in STRUCT."
872 (org-list-get-nth 2 item struct
))
874 (defun org-list-set-bullet (item struct bullet
)
875 "Set bullet of ITEM in STRUCT to BULLET.
876 \nThis function modifies STRUCT."
877 (org-list-set-nth 2 item struct bullet
))
879 (defsubst org-list-get-counter
(item struct
)
880 "Return counter of ITEM in STRUCT."
881 (org-list-get-nth 3 item struct
))
883 (defsubst org-list-get-checkbox
(item struct
)
884 "Return checkbox of ITEM in STRUCT or nil."
885 (org-list-get-nth 4 item struct
))
887 (defun org-list-set-checkbox (item struct checkbox
)
888 "Set checkbox of ITEM in STRUCT to CHECKBOX.
889 \nThis function modifies STRUCT."
890 (org-list-set-nth 4 item struct checkbox
))
892 (defsubst org-list-get-tag
(item struct
)
893 "Return end position of ITEM in STRUCT."
894 (org-list-get-nth 5 item struct
))
896 (defun org-list-get-item-end (item struct
)
897 "Return end position of ITEM in STRUCT."
898 (org-list-get-nth 6 item struct
))
900 (defun org-list-get-item-end-before-blank (item struct
)
901 "Return point at end of ITEM in STRUCT, before any blank line.
902 Point returned is at end of line."
904 (goto-char (org-list-get-item-end item struct
))
905 (skip-chars-backward " \r\t\n")
908 (defun org-list-get-parent (item struct parents
)
909 "Return parent of ITEM or nil.
910 STRUCT is the list structure. PARENTS is the alist of parents,
911 as returned by `org-list-parents-alist'."
912 (let ((parents (or parents
(org-list-parents-alist struct
))))
913 (cdr (assq item parents
))))
915 (defun org-list-has-child-p (item struct
)
916 "Non-nil if ITEM has a child.
918 STRUCT is the list structure.
920 Value returned is the position of the first child of ITEM."
921 (let ((ind (org-list-get-ind item struct
))
922 (child-maybe (car (nth 1 (member (assq item struct
) struct
)))))
923 (when (and child-maybe
924 (< ind
(org-list-get-ind child-maybe struct
)))
927 (defun org-list-get-next-item (item _struct prevs
)
928 "Return next item in same sub-list as ITEM, or nil.
929 STRUCT is the list structure. PREVS is the alist of previous
930 items, as returned by `org-list-prevs-alist'."
931 (car (rassq item prevs
)))
933 (defun org-list-get-prev-item (item _struct prevs
)
934 "Return previous item in same sub-list as ITEM, or nil.
935 STRUCT is the list structure. PREVS is the alist of previous
936 items, as returned by `org-list-prevs-alist'."
937 (cdr (assq item prevs
)))
939 (defun org-list-get-subtree (item struct
)
940 "List all items having ITEM as a common ancestor, or nil.
941 STRUCT is the list structure."
942 (let* ((item-end (org-list-get-item-end item struct
))
943 (sub-struct (cdr (member (assq item struct
) struct
)))
948 (if (< pos item-end
) (push pos subtree
) (throw 'exit nil
))))
952 (defun org-list-get-all-items (item struct prevs
)
953 "List all items in the same sub-list as ITEM.
954 STRUCT is the list structure. PREVS is the alist of previous
955 items, as returned by `org-list-prevs-alist'."
956 (let ((prev-item item
)
958 before-item after-item
)
959 (while (setq prev-item
(org-list-get-prev-item prev-item struct prevs
))
960 (push prev-item before-item
))
961 (while (setq next-item
(org-list-get-next-item next-item struct prevs
))
962 (push next-item after-item
))
963 (append before-item
(list item
) (nreverse after-item
))))
965 (defun org-list-get-children (item _struct parents
)
966 "List all children of ITEM, or nil.
967 STRUCT is the list structure. PARENTS is the alist of parents,
968 as returned by `org-list-parents-alist'."
970 (while (setq child
(car (rassq item parents
)))
971 (setq parents
(cdr (member (assq child parents
) parents
)))
975 (defun org-list-get-top-point (struct)
976 "Return point at beginning of list.
977 STRUCT is the list structure."
980 (defun org-list-get-bottom-point (struct)
981 "Return point at bottom of list.
982 STRUCT is the list structure."
984 (mapcar (lambda (e) (org-list-get-item-end (car e
) struct
)) struct
)))
986 (defun org-list-get-list-begin (item struct prevs
)
987 "Return point at beginning of sub-list ITEM belongs.
988 STRUCT is the list structure. PREVS is the alist of previous
989 items, as returned by `org-list-prevs-alist'."
990 (let ((first-item item
) prev-item
)
991 (while (setq prev-item
(org-list-get-prev-item first-item struct prevs
))
992 (setq first-item prev-item
))
995 (defalias 'org-list-get-first-item
'org-list-get-list-begin
)
997 (defun org-list-get-last-item (item struct prevs
)
998 "Return point at last item of sub-list ITEM belongs.
999 STRUCT is the list structure. PREVS is the alist of previous
1000 items, as returned by `org-list-prevs-alist'."
1001 (let ((last-item item
) next-item
)
1002 (while (setq next-item
(org-list-get-next-item last-item struct prevs
))
1003 (setq last-item next-item
))
1006 (defun org-list-get-list-end (item struct prevs
)
1007 "Return point at end of sub-list ITEM belongs.
1008 STRUCT is the list structure. PREVS is the alist of previous
1009 items, as returned by `org-list-prevs-alist'."
1010 (org-list-get-item-end (org-list-get-last-item item struct prevs
) struct
))
1012 (defun org-list-get-list-type (item struct prevs
)
1013 "Return the type of the list containing ITEM, as a symbol.
1015 STRUCT is the list structure. PREVS is the alist of previous
1016 items, as returned by `org-list-prevs-alist'.
1018 Possible types are `descriptive', `ordered' and `unordered'. The
1019 type is determined by the first item of the list."
1020 (let ((first (org-list-get-list-begin item struct prevs
)))
1022 ((string-match "[[:alnum:]]" (org-list-get-bullet first struct
)) 'ordered
)
1023 ((org-list-get-tag first struct
) 'descriptive
)
1026 (defun org-list-get-item-number (item struct prevs parents
)
1027 "Return ITEM's sequence number.
1029 STRUCT is the list structure. PREVS is the alist of previous
1030 items, as returned by `org-list-prevs-alist'. PARENTS is the
1031 alist of ancestors, as returned by `org-list-parents-alist'.
1033 Return value is a list of integers. Counters have an impact on
1035 (let ((get-relative-number
1037 (lambda (item struct prevs
)
1038 ;; Return relative sequence number of ITEM in the sub-list
1039 ;; it belongs. STRUCT is the list structure. PREVS is
1040 ;; the alist of previous items.
1041 (let ((seq 0) (pos item
) counter
)
1042 (while (and (not (setq counter
(org-list-get-counter pos struct
)))
1043 (setq pos
(org-list-get-prev-item pos struct prevs
)))
1045 (if (not counter
) (1+ seq
)
1047 ((string-match "[A-Za-z]" counter
)
1048 (+ (- (string-to-char (upcase (match-string 0 counter
))) 64)
1050 ((string-match "[0-9]+" counter
)
1051 (+ (string-to-number (match-string 0 counter
)) seq
))
1053 ;; Cons each parent relative number into return value (OUT).
1054 (let ((out (list (funcall get-relative-number item struct prevs
)))
1056 (while (setq parent
(org-list-get-parent parent struct parents
))
1057 (push (funcall get-relative-number parent struct prevs
) out
))
1065 (defun org-list-search-generic (search re bound noerr
)
1066 "Search a string in valid contexts for lists.
1067 Arguments SEARCH, RE, BOUND and NOERR are similar to those used
1068 in `re-search-forward'."
1070 (let ((origin (point)))
1072 ;; 1. No match: return to origin or bound, depending on NOERR.
1073 (unless (funcall search re bound noerr
)
1074 (throw 'exit
(and (goto-char (if (memq noerr
'(t nil
)) origin bound
))
1076 ;; 2. Match in valid context: return point. Else, continue
1078 (when (org-list-in-valid-context-p) (throw 'exit
(point)))))))
1080 (defun org-list-search-backward (regexp &optional bound noerror
)
1081 "Like `re-search-backward' but stop only where lists are recognized.
1082 Arguments REGEXP, BOUND and NOERROR are similar to those used in
1083 `re-search-backward'."
1084 (org-list-search-generic #'re-search-backward
1085 regexp
(or bound
(point-min)) noerror
))
1087 (defun org-list-search-forward (regexp &optional bound noerror
)
1088 "Like `re-search-forward' but stop only where lists are recognized.
1089 Arguments REGEXP, BOUND and NOERROR are similar to those used in
1090 `re-search-forward'."
1091 (org-list-search-generic #'re-search-forward
1092 regexp
(or bound
(point-max)) noerror
))
1096 ;;; Methods on structures
1098 (defsubst org-list-bullet-string
(bullet)
1099 "Return BULLET with the correct number of whitespaces.
1100 It determines the number of whitespaces to append by looking at
1101 `org-list-two-spaces-after-bullet-regexp'."
1103 (let ((spaces (if (and org-list-two-spaces-after-bullet-regexp
1105 org-list-two-spaces-after-bullet-regexp bullet
))
1108 (if (string-match "\\S-+\\([ \t]*\\)" bullet
)
1109 (replace-match spaces nil nil bullet
1)
1112 (defun org-list-swap-items (beg-A beg-B struct
)
1113 "Swap item starting at BEG-A with item starting at BEG-B in STRUCT.
1115 Blank lines at the end of items are left in place. Item
1116 visibility is preserved. Return the new structure after the
1119 Assume BEG-A is lesser than BEG-B and that BEG-A and BEG-B belong
1120 to the same sub-list.
1122 This function modifies STRUCT."
1124 (let* ((end-A-no-blank (org-list-get-item-end-before-blank beg-A struct
))
1125 (end-B-no-blank (org-list-get-item-end-before-blank beg-B struct
))
1126 (end-A (org-list-get-item-end beg-A struct
))
1127 (end-B (org-list-get-item-end beg-B struct
))
1128 (size-A (- end-A-no-blank beg-A
))
1129 (size-B (- end-B-no-blank beg-B
))
1130 (body-A (buffer-substring beg-A end-A-no-blank
))
1131 (body-B (buffer-substring beg-B end-B-no-blank
))
1132 (between-A-no-blank-and-B (buffer-substring end-A-no-blank beg-B
))
1133 (sub-A (cons beg-A
(org-list-get-subtree beg-A struct
)))
1134 (sub-B (cons beg-B
(org-list-get-subtree beg-B struct
)))
1135 ;; Store overlays responsible for visibility status. We
1136 ;; also need to store their boundaries as they will be
1137 ;; removed from buffer.
1142 (and (>= (overlay-start o
) beg-A
)
1143 (<= (overlay-end o
) end-A
)
1144 (list o
(overlay-start o
) (overlay-end o
))))
1145 (overlays-in beg-A end-A
)))
1148 (and (>= (overlay-start o
) beg-B
)
1149 (<= (overlay-end o
) end-B
)
1150 (list o
(overlay-start o
) (overlay-end o
))))
1151 (overlays-in beg-B end-B
))))))
1152 ;; 1. Move effectively items in buffer.
1154 (delete-region beg-A end-B-no-blank
)
1155 (insert (concat body-B between-A-no-blank-and-B body-A
))
1156 ;; 2. Now modify struct. No need to re-read the list, the
1157 ;; transformation is just a shift of positions. Some special
1158 ;; attention is required for items ending at END-A and END-B
1159 ;; as empty spaces are not moved there. In others words,
1160 ;; item BEG-A will end with whitespaces that were at the end
1161 ;; of BEG-B and the same applies to BEG-B.
1163 (let ((pos (car e
)))
1167 (let ((end-e (nth 6 e
)))
1168 (setcar e
(+ pos
(- end-B-no-blank end-A-no-blank
)))
1169 (setcar (nthcdr 6 e
)
1170 (+ end-e
(- end-B-no-blank end-A-no-blank
)))
1171 (when (= end-e end-A
) (setcar (nthcdr 6 e
) end-B
))))
1173 (let ((end-e (nth 6 e
)))
1174 (setcar e
(- (+ pos beg-A
) beg-B
))
1175 (setcar (nthcdr 6 e
) (+ end-e
(- beg-A beg-B
)))
1176 (when (= end-e end-B
)
1177 (setcar (nthcdr 6 e
)
1178 (+ beg-A size-B
(- end-A end-A-no-blank
))))))
1180 (let ((end-e (nth 6 e
)))
1181 (setcar e
(+ pos
(- size-B size-A
)))
1182 (setcar (nthcdr 6 e
) (+ end-e
(- size-B size-A
))))))))
1183 (setq struct
(sort struct
#'car-less-than-car
))
1184 ;; Restore visibility status, by moving overlays to their new
1186 (dolist (ov (car overlays
))
1189 (+ (nth 1 ov
) (- (+ beg-B
(- size-B size-A
)) beg-A
))
1190 (+ (nth 2 ov
) (- (+ beg-B
(- size-B size-A
)) beg-A
))))
1191 (dolist (ov (cdr overlays
))
1192 (move-overlay (car ov
)
1193 (+ (nth 1 ov
) (- beg-A beg-B
))
1194 (+ (nth 2 ov
) (- beg-A beg-B
))))
1195 ;; Return structure.
1198 (defun org-list-separating-blank-lines-number (pos struct prevs
)
1199 "Return number of blank lines that should separate items in list.
1201 POS is the position of point where `org-list-insert-item' was called.
1203 STRUCT is the list structure. PREVS is the alist of previous
1204 items, as returned by `org-list-prevs-alist'.
1206 Assume point is at item's beginning. If the item is alone, apply
1207 some heuristics to guess the result."
1209 (let ((item (point))
1211 (cdr (assq 'plain-list-item org-blank-before-new-entry
)))
1216 ;; Count blank lines above beginning of line.
1218 (count-lines (goto-char (point-at-bol))
1219 (progn (skip-chars-backward " \r\t\n")
1223 ;; Trivial cases where there should be none.
1224 ((or org-list-empty-line-terminates-plain-lists
(not insert-blank-p
)) 0)
1225 ;; When `org-blank-before-new-entry' says so, it is 1.
1226 ((eq insert-blank-p t
) 1)
1227 ;; `plain-list-item' is 'auto. Count blank lines separating
1228 ;; neighbors' items in list.
1229 (t (let ((next-p (org-list-get-next-item item struct prevs
)))
1231 ;; Is there a next item?
1232 (next-p (goto-char next-p
)
1233 (funcall count-blanks
))
1234 ;; Is there a previous item?
1235 ((org-list-get-prev-item item struct prevs
)
1236 (funcall count-blanks
))
1237 ;; User inserted blank lines, trust him.
1238 ((and (> pos
(org-list-get-item-end-before-blank item struct
))
1239 (> (save-excursion (goto-char pos
)
1240 (setq usr-blank
(funcall count-blanks
)))
1243 ;; Are there blank lines inside the list so far?
1245 (goto-char (org-list-get-top-point struct
))
1246 ;; Do not use `org-list-search-forward' so blank lines
1247 ;; in blocks can be counted in.
1249 "^[ \t]*$" (org-list-get-item-end-before-blank item struct
) t
))
1251 ;; Default choice: no blank line.
1254 (defun org-list-insert-item (pos struct prevs
&optional checkbox after-bullet
)
1255 "Insert a new list item at POS and return the new structure.
1256 If POS is before first character after bullet of the item, the
1257 new item will be created before the current one.
1259 STRUCT is the list structure. PREVS is the alist of previous
1260 items, as returned by `org-list-prevs-alist'.
1262 Insert a checkbox if CHECKBOX is non-nil, and string AFTER-BULLET
1263 after the bullet. Cursor will be after this text once the
1266 This function modifies STRUCT."
1267 (let ((case-fold-search t
))
1268 ;; 1. Get information about list: position of point with regards
1269 ;; to item start (BEFOREP), blank lines number separating items
1270 ;; (BLANK-NB), if we're allowed to (SPLIT-LINE-P).
1271 (let* ((item (progn (goto-char pos
) (goto-char (org-list-get-item-begin))))
1272 (item-end (org-list-get-item-end item struct
))
1273 (item-end-no-blank (org-list-get-item-end-before-blank item struct
))
1276 (looking-at org-list-full-item-re
)
1279 ((not (match-beginning 4)) (match-end 0))
1280 ;; Ignore tag in a non-descriptive list.
1281 ((save-match-data (string-match "[.)]" (match-string 1)))
1282 (match-beginning 4))
1284 (goto-char (match-end 4))
1285 (skip-chars-forward " \t")
1287 (split-line-p (org-get-alist-option org-M-RET-may-split-line
'item
))
1288 (blank-nb (org-list-separating-blank-lines-number
1290 ;; 2. Build the new item to be created. Concatenate same
1291 ;; bullet as item, checkbox, text AFTER-BULLET if
1292 ;; provided, and text cut from point to end of item
1293 ;; (TEXT-CUT) to form item's BODY. TEXT-CUT depends on
1294 ;; BEFOREP and SPLIT-LINE-P. The difference of size
1295 ;; between what was cut and what was inserted in buffer
1296 ;; is stored in SIZE-OFFSET.
1297 (ind (org-list-get-ind item struct
))
1298 (ind-size (if indent-tabs-mode
1299 (+ (/ ind tab-width
) (mod ind tab-width
))
1301 (bullet (org-list-bullet-string (org-list-get-bullet item struct
)))
1302 (box (when checkbox
"[ ]"))
1304 (and (not beforep
) split-line-p
1307 ;; If POS is greater than ITEM-END, then point is
1308 ;; in some white lines after the end of the list.
1309 ;; Those must be removed, or they will be left,
1310 ;; stacking up after the list.
1311 (when (< item-end pos
)
1312 (delete-region (1- item-end
) (point-at-eol)))
1313 (skip-chars-backward " \r\t\n")
1315 (delete-and-extract-region pos item-end-no-blank
))))
1316 (body (concat bullet
(when box
(concat box
" ")) after-bullet
1318 (if (string-match "\\`[ \t]+" text-cut
)
1319 (replace-match "" t t text-cut
)
1321 (item-sep (make-string (1+ blank-nb
) ?
\n))
1322 (item-size (+ ind-size
(length body
) (length item-sep
)))
1323 (size-offset (- item-size
(length text-cut
))))
1324 ;; 4. Insert effectively item into buffer.
1326 (org-indent-to-column ind
)
1327 (insert body item-sep
)
1328 ;; 5. Add new item to STRUCT.
1330 (let ((p (car e
)) (end (nth 6 e
)))
1332 ;; Before inserted item, positions don't change but
1333 ;; an item ending after insertion has its end shifted
1336 (when (> end item
) (setcar (nthcdr 6 e
) (+ end size-offset
))))
1337 ;; Trivial cases where current item isn't split in
1338 ;; two. Just shift every item after new one by
1340 ((or beforep
(not split-line-p
))
1341 (setcar e
(+ p item-size
))
1342 (setcar (nthcdr 6 e
) (+ end item-size
)))
1343 ;; Item is split in two: elements before POS are just
1344 ;; shifted by ITEM-SIZE. In the case item would end
1345 ;; after split POS, ending is only shifted by
1348 (setcar e
(+ p item-size
))
1350 (setcar (nthcdr 6 e
) (+ end item-size
))
1351 (setcar (nthcdr 6 e
) (+ end size-offset
))))
1352 ;; Elements after POS are moved into new item.
1353 ;; Length of ITEM-SEP has to be removed as ITEM-SEP
1354 ;; doesn't appear in buffer yet.
1356 (setcar e
(+ p size-offset
(- item pos
(length item-sep
))))
1357 (if (= end item-end
)
1358 (setcar (nthcdr 6 e
) (+ item item-size
))
1359 (setcar (nthcdr 6 e
)
1361 (- item pos
(length item-sep
))))))
1362 ;; Elements at ITEM-END or after are only shifted by
1364 (t (setcar e
(+ p size-offset
))
1365 (setcar (nthcdr 6 e
) (+ end size-offset
))))))
1367 (push (list item ind bullet nil box nil
(+ item item-size
)) struct
)
1368 (setq struct
(sort struct
(lambda (e1 e2
) (< (car e1
) (car e2
)))))
1369 ;; 6. If not BEFOREP, new item must appear after ITEM, so
1370 ;; exchange ITEM with the next item in list. Position cursor
1371 ;; after bullet, counter, checkbox, and label.
1374 (setq struct
(org-list-swap-items item
(+ item item-size
) struct
))
1375 (goto-char (org-list-get-next-item
1376 item struct
(org-list-prevs-alist struct
))))
1379 (defun org-list-delete-item (item struct
)
1380 "Remove ITEM from the list and return the new structure.
1382 STRUCT is the list structure."
1383 (let* ((end (org-list-get-item-end item struct
))
1384 (beg (if (= (org-list-get-bottom-point struct
) end
)
1385 ;; If ITEM ends with the list, delete blank lines
1389 (skip-chars-backward " \r\t\n")
1390 (min (1+ (point-at-eol)) (point-max)))
1392 ;; Remove item from buffer.
1393 (delete-region beg end
)
1394 ;; Remove item from structure and shift others items accordingly.
1395 ;; Don't forget to shift also ending position when appropriate.
1396 (let ((size (- end beg
)))
1397 (delq nil
(mapcar (lambda (e)
1398 (let ((pos (car e
)))
1401 (let ((end-e (nth 6 e
)))
1405 (append (butlast e
) (list beg
)))
1407 (append (butlast e
) (list (- end-e size
)))))))
1411 (append (butlast (cdr e
))
1412 (list (- (nth 6 e
) size
))))))))
1415 (defun org-list-send-item (item dest struct
)
1416 "Send ITEM to destination DEST.
1418 STRUCT is the list structure.
1420 DEST can have various values.
1422 If DEST is a buffer position, the function will assume it points
1423 to another item in the same list as ITEM, and will move the
1424 latter just before the former.
1426 If DEST is `begin' (respectively `end'), ITEM will be moved at
1427 the beginning (respectively end) of the list it belongs to.
1429 If DEST is a string like \"N\", where N is an integer, ITEM will
1430 be moved at the Nth position in the list.
1432 If DEST is `kill', ITEM will be deleted and its body will be
1433 added to the kill-ring.
1435 If DEST is `delete', ITEM will be deleted.
1437 Visibility of item is preserved.
1439 This function returns, destructively, the new list structure."
1440 (let* ((prevs (org-list-prevs-alist struct
))
1441 (item-end (org-list-get-item-end item struct
))
1442 ;; Grab full item body minus its bullet.
1449 (regexp-quote (org-list-get-bullet item struct
))))
1452 ;; Change DEST into a buffer position. A trick is needed
1453 ;; when ITEM is meant to be sent at the end of the list.
1454 ;; Indeed, by setting locally `org-M-RET-may-split-line' to
1455 ;; nil and insertion point (INS-POINT) to the first line's
1456 ;; end of the last item, we ensure the new item will be
1457 ;; inserted after the last item, and not after any of its
1458 ;; hypothetical sub-items.
1460 ((or (eq dest
'kill
) (eq dest
'delete
)))
1462 (setq dest
(org-list-get-list-begin item struct prevs
)))
1464 (setq dest
(org-list-get-list-end item struct prevs
))
1466 (goto-char (org-list-get-last-item item struct prevs
))
1468 ((string-match "\\`[0-9]+\\'" dest
)
1469 (let* ((all (org-list-get-all-items item struct prevs
))
1471 (index (mod (string-to-number dest
) len
)))
1472 (if (not (zerop index
))
1473 (setq dest
(nth (1- index
) all
))
1474 ;; Send ITEM at the end of the list.
1475 (setq dest
(org-list-get-list-end item struct prevs
))
1478 (org-list-get-last-item item struct prevs
))
1481 (org-M-RET-may-split-line nil
)
1482 ;; Store inner overlays (to preserve visibility).
1483 (overlays (org-remove-if (lambda (o) (or (< (overlay-start o
) item
)
1484 (> (overlay-end o
) item
)))
1485 (overlays-in item item-end
))))
1487 ((eq dest
'delete
) (org-list-delete-item item struct
))
1490 (org-list-delete-item item struct
))
1491 ((and (integerp dest
) (/= item ins-point
))
1492 (setq item
(copy-marker item
))
1493 (setq struct
(org-list-insert-item ins-point struct prevs nil body
))
1494 ;; 1. Structure returned by `org-list-insert-item' may not be
1495 ;; accurate, as it cannot see sub-items included in BODY.
1496 ;; Thus, first compute the real structure so far.
1498 (cons (marker-position item
)
1499 (org-list-get-subtree (marker-position item
) struct
)))
1500 (new-end (org-list-get-item-end (point) struct
))
1501 (old-end (org-list-get-item-end (marker-position item
) struct
))
1503 (shift (- (point) item
)))
1504 ;; 1.1. Remove the item just created in structure.
1505 (setq struct
(delete (assq new-item struct
) struct
))
1506 ;; 1.2. Copy ITEM and any of its sub-items at NEW-ITEM.
1511 (let* ((cell (assq e struct
))
1515 (append (butlast (cdr cell
))
1516 (list (if (= end old-end
)
1520 #'car-less-than-car
)))
1521 ;; 2. Restore inner overlays.
1522 (dolist (o overlays
)
1524 (+ (overlay-start o
) (- (point) item
))
1525 (+ (overlay-end o
) (- (point) item
))))
1526 ;; 3. Eventually delete extra copy of the item and clean marker.
1527 (prog1 (org-list-delete-item (marker-position item
) struct
)
1528 (move-marker item nil
)))
1531 (defun org-list-struct-outdent (start end struct parents
)
1532 "Outdent items between positions START and END.
1534 STRUCT is the list structure. PARENTS is the alist of items'
1535 parents, as returned by `org-list-parents-alist'.
1537 START is included, END excluded."
1540 (let* ((item (car cell
))
1541 (parent (cdr cell
)))
1543 ;; Item not yet in zone: keep association.
1544 ((< item start
) cell
)
1545 ;; Item out of zone: follow associations in ACC.
1547 (let ((convert (and parent
(assq parent acc
))))
1548 (if convert
(cons item
(cdr convert
)) cell
)))
1549 ;; Item has no parent: error
1551 (error "Cannot outdent top-level items"))
1552 ;; Parent is outdented: keep association.
1554 (push (cons parent item
) acc
) cell
)
1556 ;; Parent isn't outdented: reparent to grand-parent.
1557 (let ((grand-parent (org-list-get-parent
1558 parent struct parents
)))
1559 (push (cons parent item
) acc
)
1560 (cons item grand-parent
))))))))
1561 (mapcar out parents
)))
1563 (defun org-list-struct-indent (start end struct parents prevs
)
1564 "Indent items between positions START and END.
1566 STRUCT is the list structure. PARENTS is the alist of parents
1567 and PREVS is the alist of previous items, returned by,
1568 respectively, `org-list-parents-alist' and
1569 `org-list-prevs-alist'.
1571 START is included and END excluded.
1573 STRUCT may be modified if `org-list-demote-modify-bullet' matches
1574 bullets between START and END."
1576 (set-assoc (lambda (cell) (push cell acc
) cell
))
1577 (change-bullet-maybe
1582 ;; Normalize ordered bullets.
1583 (let ((bul (org-trim
1584 (org-list-get-bullet item struct
))))
1585 (cond ((string-match "[A-Z]\\." bul
) "A.")
1586 ((string-match "[A-Z])" bul
) "A)")
1587 ((string-match "[a-z]\\." bul
) "a.")
1588 ((string-match "[a-z])" bul
) "a)")
1589 ((string-match "[0-9]\\." bul
) "1.")
1590 ((string-match "[0-9])" bul
) "1)")
1592 org-list-demote-modify-bullet
))))
1593 (when new-bul-p
(org-list-set-bullet item struct new-bul-p
))))))
1596 (let* ((item (car cell
))
1597 (parent (cdr cell
)))
1599 ;; Item not yet in zone: keep association.
1600 ((< item start
) cell
)
1602 ;; Item out of zone: follow associations in ACC.
1603 (let ((convert (assq parent acc
)))
1604 (if convert
(cons item
(cdr convert
)) cell
)))
1606 ;; Item is in zone...
1607 (let ((prev (org-list-get-prev-item item struct prevs
)))
1608 ;; Check if bullet needs to be changed.
1609 (funcall change-bullet-maybe item
)
1611 ;; First item indented but not parent: error
1612 ((and (not prev
) (< parent start
))
1613 (error "Cannot indent the first item of a list"))
1614 ;; First item and parent indented: keep same
1616 ((not prev
) (funcall set-assoc cell
))
1617 ;; Previous item not indented: reparent to it.
1618 ((< prev start
) (funcall set-assoc
(cons item prev
)))
1619 ;; Previous item indented: reparent like it.
1622 (cons item
(cdr (assq prev acc
)))))))))))))
1623 (mapcar ind parents
)))
1627 ;;; Repairing structures
1629 (defun org-list-use-alpha-bul-p (first struct prevs
)
1630 "Non-nil if list starting at FIRST can have alphabetical bullets.
1632 STRUCT is list structure. PREVS is the alist of previous items,
1633 as returned by `org-list-prevs-alist'."
1634 (and org-list-allow-alphabetical
1636 (let ((item first
) (ascii 64) (case-fold-search nil
))
1637 ;; Pretend that bullets are uppercase and check if alphabet
1638 ;; is sufficient, taking counters into account.
1640 (let ((count (org-list-get-counter item struct
)))
1641 ;; Virtually determine current bullet
1642 (if (and count
(string-match "[a-zA-Z]" count
))
1643 ;; Counters are not case-sensitive.
1644 (setq ascii
(string-to-char (upcase count
)))
1645 (setq ascii
(1+ ascii
)))
1646 ;; Test if bullet would be over z or Z.
1649 (setq item
(org-list-get-next-item item struct prevs
)))))
1650 ;; All items checked. All good.
1653 (defun org-list-inc-bullet-maybe (bullet)
1654 "Increment BULLET if applicable."
1655 (let ((case-fold-search nil
))
1657 ;; Num bullet: increment it.
1658 ((string-match "[0-9]+" bullet
)
1660 (number-to-string (1+ (string-to-number (match-string 0 bullet
))))
1662 ;; Alpha bullet: increment it.
1663 ((string-match "[A-Za-z]" bullet
)
1665 (char-to-string (1+ (string-to-char (match-string 0 bullet
))))
1667 ;; Unordered bullet: leave it.
1670 (defun org-list-struct-fix-bul (struct prevs
)
1671 "Verify and correct bullets in STRUCT.
1672 PREVS is the alist of previous items, as returned by
1673 `org-list-prevs-alist'.
1675 This function modifies STRUCT."
1676 (let ((case-fold-search nil
)
1679 ;; Set bullet of ITEM in STRUCT, depending on the type of
1680 ;; first item of the list, the previous bullet and counter
1683 (let* ((prev (org-list-get-prev-item item struct prevs
))
1684 (prev-bul (and prev
(org-list-get-bullet prev struct
)))
1685 (counter (org-list-get-counter item struct
))
1686 (bullet (org-list-get-bullet item struct
))
1687 (alphap (and (not prev
)
1688 (org-list-use-alpha-bul-p item struct prevs
))))
1689 (org-list-set-bullet
1691 (org-list-bullet-string
1693 ;; Alpha counter in alpha list: use counter.
1695 (string-match "[a-zA-Z]" counter
)
1696 (string-match "[a-zA-Z]" prev-bul
))
1697 ;; Use cond to be sure `string-match' is used in
1701 ((string-match "[a-z]" prev-bul
) (downcase counter
))
1702 ((string-match "[A-Z]" prev-bul
) (upcase counter
)))))
1703 (replace-match real-count nil nil prev-bul
)))
1704 ;; Num counter in a num list: use counter.
1706 (string-match "[0-9]+" counter
)
1707 (string-match "[0-9]+" prev-bul
))
1708 (replace-match counter nil nil prev-bul
))
1709 ;; No counter: increase, if needed, previous bullet.
1711 (org-list-inc-bullet-maybe (org-list-get-bullet prev struct
)))
1712 ;; Alpha counter at first item: use counter.
1713 ((and counter
(org-list-use-alpha-bul-p item struct prevs
)
1714 (string-match "[A-Za-z]" counter
)
1715 (string-match "[A-Za-z]" bullet
))
1718 ((string-match "[a-z]" bullet
) (downcase counter
))
1719 ((string-match "[A-Z]" bullet
) (upcase counter
)))))
1720 (replace-match real-count nil nil bullet
)))
1721 ;; Num counter at first item: use counter.
1723 (string-match "[0-9]+" counter
)
1724 (string-match "[0-9]+" bullet
))
1725 (replace-match counter nil nil bullet
))
1726 ;; First bullet is alpha uppercase: use "A".
1727 ((and alphap
(string-match "[A-Z]" bullet
))
1728 (replace-match "A" nil nil bullet
))
1729 ;; First bullet is alpha lowercase: use "a".
1730 ((and alphap
(string-match "[a-z]" bullet
))
1731 (replace-match "a" nil nil bullet
))
1732 ;; First bullet is num: use "1".
1733 ((string-match "\\([0-9]+\\|[A-Za-z]\\)" bullet
)
1734 (replace-match "1" nil nil bullet
))
1735 ;; Not an ordered list: keep bullet.
1737 (mapc fix-bul
(mapcar #'car struct
))))
1739 (defun org-list-struct-fix-ind (struct parents
&optional bullet-size
)
1740 "Verify and correct indentation in STRUCT.
1742 PARENTS is the alist of parents, as returned by
1743 `org-list-parents-alist'.
1745 If numeric optional argument BULLET-SIZE is set, assume all
1746 bullets in list have this length to determine new indentation.
1748 This function modifies STRUCT."
1749 (let* ((ancestor (org-list-get-top-point struct
))
1750 (top-ind (org-list-get-ind ancestor struct
))
1753 (let ((parent (org-list-get-parent item struct parents
)))
1755 ;; Indent like parent + length of parent's bullet +
1758 item struct
(+ (or bullet-size
1760 (org-list-get-bullet parent struct
)))
1761 (org-list-get-ind parent struct
)
1762 org-list-indent-offset
))
1763 ;; If no parent, indent like top-point.
1764 (org-list-set-ind item struct top-ind
))))))
1765 (mapc new-ind
(mapcar #'car
(cdr struct
)))))
1767 (defun org-list-struct-fix-box (struct parents prevs
&optional ordered
)
1768 "Verify and correct checkboxes in STRUCT.
1770 PARENTS is the alist of parents and PREVS is the alist of
1771 previous items, as returned by, respectively,
1772 `org-list-parents-alist' and `org-list-prevs-alist'.
1774 If ORDERED is non-nil, a checkbox can only be checked when every
1775 checkbox before it is checked too. If there was an attempt to
1776 break this rule, the function will return the blocking item. In
1777 all others cases, the return value will be nil.
1779 This function modifies STRUCT."
1780 (let ((all-items (mapcar #'car struct
))
1785 (mapcar (lambda (child)
1786 (org-list-get-checkbox child struct
))
1787 (org-list-get-children item struct parents
))))
1788 (org-list-set-checkbox
1791 ((and (member "[ ]" box-list
) (member "[X]" box-list
)) "[-]")
1792 ((member "[-]" box-list
) "[-]")
1793 ((member "[X]" box-list
) "[X]")
1794 ((member "[ ]" box-list
) "[ ]")
1795 ;; Parent has no boxed child: leave box as-is.
1796 (t (org-list-get-checkbox item struct
))))))))
1798 ;; 1. List all parents with a checkbox.
1801 (let* ((parent (org-list-get-parent e struct parents
))
1802 (parent-box-p (org-list-get-checkbox parent struct
)))
1803 (when (and parent-box-p
(not (memq parent parent-list
)))
1804 (push parent parent-list
))))
1806 ;; 2. Sort those parents by decreasing indentation.
1807 (setq parent-list
(sort parent-list
1809 (> (org-list-get-ind e1 struct
)
1810 (org-list-get-ind e2 struct
)))))
1811 ;; 3. For each parent, get all children's checkboxes to determine
1812 ;; and set its checkbox accordingly.
1813 (mapc set-parent-box parent-list
)
1814 ;; 4. If ORDERED is set, see if we need to uncheck some boxes.
1817 (mapcar (lambda (e) (org-list-get-checkbox e struct
)) all-items
))
1818 (after-unchecked (member "[ ]" box-list
)))
1819 ;; There are boxes checked after an unchecked one: fix that.
1820 (when (member "[X]" after-unchecked
)
1821 (let ((index (- (length struct
) (length after-unchecked
))))
1823 (when (org-list-get-checkbox e struct
)
1824 (org-list-set-checkbox e struct
"[ ]")))
1825 (nthcdr index all-items
))
1826 ;; Verify once again the structure, without ORDERED.
1827 (org-list-struct-fix-box struct parents prevs nil
)
1828 ;; Return blocking item.
1829 (nth index all-items
)))))))
1831 (defun org-list-struct-fix-item-end (struct)
1832 "Verify and correct each item end position in STRUCT.
1834 This function modifies STRUCT."
1835 (let (end-list acc-end
)
1837 (let* ((pos (car e
))
1838 (ind-pos (org-list-get-ind pos struct
))
1839 (end-pos (org-list-get-item-end pos struct
)))
1840 (unless (assq end-pos struct
)
1841 ;; To determine real ind of an ending position that is
1842 ;; not at an item, we have to find the item it belongs
1843 ;; to: it is the last item (ITEM-UP), whose ending is
1844 ;; further than the position we're interested in.
1845 (let ((item-up (assoc-default end-pos acc-end
'>)))
1847 ;; Else part is for the bottom point.
1848 (if item-up
(+ (org-list-get-ind item-up struct
) 2) 0)
1851 (push (cons ind-pos pos
) end-list
)
1852 (push (cons end-pos pos
) acc-end
)))
1854 (setq end-list
(sort end-list
(lambda (e1 e2
) (< (cdr e1
) (cdr e2
)))))
1855 (org-list-struct-assoc-end struct end-list
)))
1857 (defun org-list-struct-apply-struct (struct old-struct
)
1858 "Apply set difference between STRUCT and OLD-STRUCT to the buffer.
1860 OLD-STRUCT is the structure before any modifications, and STRUCT
1861 the structure to be applied. The function will only modify parts
1862 of the list which have changed.
1864 Initial position of cursor is restored after the changes."
1865 (let* ((origin (point-marker))
1866 (inlinetask-re (and (featurep 'org-inlinetask
)
1867 (org-inlinetask-outline-regexp)))
1868 (item-re (org-item-re))
1871 ;; Shift the indentation between END and BEG by DELTA.
1872 ;; Start from the line before END.
1873 (lambda (end beg delta
)
1875 (skip-chars-backward " \r\t\n")
1877 (while (or (> (point) beg
)
1878 (and (= (point) beg
)
1879 (not (looking-at item-re
))))
1881 ;; Skip inline tasks.
1882 ((and inlinetask-re
(looking-at inlinetask-re
))
1883 (org-inlinetask-goto-beginning))
1884 ;; Shift only non-empty lines.
1885 ((org-looking-at-p "^[ \t]*\\S-")
1886 (org-indent-line-to (+ (org-get-indentation) delta
))))
1887 (forward-line -
1)))))
1890 ;; Replace ITEM first line elements with new elements from
1891 ;; STRUCT, if appropriate.
1894 (let* ((new-ind (org-list-get-ind item struct
))
1895 (old-ind (org-get-indentation))
1896 (new-bul (org-list-bullet-string
1897 (org-list-get-bullet item struct
)))
1898 (old-bul (org-list-get-bullet item old-struct
))
1899 (new-box (org-list-get-checkbox item struct
)))
1900 (looking-at org-list-full-item-re
)
1901 ;; a. Replace bullet
1902 (unless (equal old-bul new-bul
)
1903 (replace-match new-bul nil nil nil
1))
1904 ;; b. Replace checkbox.
1906 ((equal (match-string 3) new-box
))
1907 ((and (match-string 3) new-box
)
1908 (replace-match new-box nil nil nil
3))
1910 (looking-at ".*?\\([ \t]*\\[[ X-]\\]\\)")
1911 (replace-match "" nil nil nil
1))
1912 (t (let ((counterp (match-end 2)))
1913 (goto-char (if counterp
(1+ counterp
) (match-end 1)))
1914 (insert (concat new-box
(unless counterp
" "))))))
1915 ;; c. Indent item to appropriate column.
1916 (unless (= new-ind old-ind
)
1917 (delete-region (goto-char (point-at-bol))
1918 (progn (skip-chars-forward " \t") (point)))
1919 (indent-to new-ind
)))))))
1920 ;; 1. First get list of items and position endings. We maintain
1921 ;; two alists: ITM-SHIFT, determining indentation shift needed
1922 ;; at item, and END-LIST, a pseudo-alist where key is ending
1923 ;; position and value point.
1924 (let (end-list acc-end itm-shift all-ends sliced-struct
)
1925 (dolist (e old-struct
)
1926 (let* ((pos (car e
))
1927 (ind-pos (org-list-get-ind pos struct
))
1928 (ind-old (org-list-get-ind pos old-struct
))
1929 (bul-pos (org-list-get-bullet pos struct
))
1930 (bul-old (org-list-get-bullet pos old-struct
))
1931 (ind-shift (- (+ ind-pos
(length bul-pos
))
1932 (+ ind-old
(length bul-old
))))
1933 (end-pos (org-list-get-item-end pos old-struct
)))
1934 (push (cons pos ind-shift
) itm-shift
)
1935 (unless (assq end-pos old-struct
)
1936 ;; To determine real ind of an ending position that
1937 ;; is not at an item, we have to find the item it
1938 ;; belongs to: it is the last item (ITEM-UP), whose
1939 ;; ending is further than the position we're
1941 (let ((item-up (assoc-default end-pos acc-end
#'>)))
1942 (push (cons end-pos item-up
) end-list
)))
1943 (push (cons end-pos pos
) acc-end
)))
1944 ;; 2. Slice the items into parts that should be shifted by the
1945 ;; same amount of indentation. Each slice follow the pattern
1946 ;; (END BEG DELTA). Slices are returned in reverse order.
1947 (setq all-ends
(sort (append (mapcar #'car itm-shift
)
1948 (org-uniquify (mapcar #'car end-list
)))
1950 acc-end
(nreverse acc-end
))
1951 (while (cdr all-ends
)
1952 (let* ((up (pop all-ends
))
1953 (down (car all-ends
))
1954 (itemp (assq up struct
))
1956 (if itemp
(cdr (assq up itm-shift
))
1957 ;; If we're not at an item, there's a child of the
1958 ;; item point belongs to above. Make sure the less
1959 ;; indented line in this slice has the same column
1961 (let* ((child (cdr (assq up acc-end
)))
1962 (ind (org-list-get-ind child struct
))
1963 (min-ind most-positive-fixnum
))
1966 (while (< (point) down
)
1967 ;; Ignore empty lines. Also ignore blocks and
1968 ;; drawers contents.
1969 (unless (org-looking-at-p "[ \t]*$")
1970 (setq min-ind
(min (org-get-indentation) min-ind
))
1972 ((and (looking-at "#\\+BEGIN\\(:\\|_\\S-+\\)")
1974 (format "^[ \t]*#\\+END%s[ \t]*$"
1977 ((and (looking-at org-drawer-regexp
)
1978 (re-search-forward "^[ \t]*:END:[ \t]*$"
1982 (push (list down up delta
) sliced-struct
)))
1983 ;; 3. Shift each slice in buffer, provided delta isn't 0, from
1984 ;; end to beginning. Take a special action when beginning is
1986 (dolist (e sliced-struct
)
1987 (unless (zerop (nth 2 e
)) (apply shift-body-ind e
))
1988 (let* ((beg (nth 1 e
))
1989 (cell (assq beg struct
)))
1990 (unless (or (not cell
) (equal cell
(assq beg old-struct
)))
1991 (funcall modify-item beg
)))))
1992 ;; 4. Go back to initial position and clean marker.
1994 (move-marker origin nil
)))
1996 (defun org-list-write-struct (struct parents
&optional old-struct
)
1997 "Correct bullets, checkboxes and indentation in list at point.
1999 STRUCT is the list structure. PARENTS is the alist of parents,
2000 as returned by `org-list-parents-alist'.
2002 When non-nil, optional argument OLD-STRUCT is the reference
2003 structure of the list. It should be provided whenever STRUCT
2004 doesn't correspond anymore to the real list in buffer."
2005 ;; Order of functions matters here: checkboxes and endings need
2006 ;; correct indentation to be set, and indentation needs correct
2009 ;; 0. Save a copy of structure before modifications
2010 (let ((old-struct (or old-struct
(copy-tree struct
))))
2011 ;; 1. Set a temporary, but coherent with PARENTS, indentation in
2012 ;; order to get items endings and bullets properly
2013 (org-list-struct-fix-ind struct parents
2)
2014 ;; 2. Fix each item end to get correct prevs alist.
2015 (org-list-struct-fix-item-end struct
)
2016 ;; 3. Get bullets right.
2017 (let ((prevs (org-list-prevs-alist struct
)))
2018 (org-list-struct-fix-bul struct prevs
)
2019 ;; 4. Now get real indentation.
2020 (org-list-struct-fix-ind struct parents
)
2021 ;; 5. Eventually fix checkboxes.
2022 (org-list-struct-fix-box struct parents prevs
))
2023 ;; 6. Apply structure modifications to buffer.
2024 (org-list-struct-apply-struct struct old-struct
)))
2030 (defun org-apply-on-list (function init-value
&rest args
)
2031 "Call FUNCTION on each item of the list at point.
2032 FUNCTION must be called with at least one argument: INIT-VALUE,
2033 that will contain the value returned by the function at the
2034 previous item, plus ARGS extra arguments.
2036 FUNCTION is applied on items in reverse order.
2038 As an example, \(org-apply-on-list \(lambda \(result\) \(1+ result\)\) 0\)
2039 will return the number of items in the current list.
2041 Sublists of the list are skipped. Cursor is always at the
2042 beginning of the item."
2043 (let* ((struct (org-list-struct))
2044 (prevs (org-list-prevs-alist struct
))
2045 (item (copy-marker (point-at-bol)))
2046 (all (org-list-get-all-items (marker-position item
) struct prevs
))
2050 (setq value
(apply function value args
)))
2053 (move-marker item nil
)
2056 (defun org-list-set-item-visibility (item struct view
)
2057 "Set visibility of ITEM in STRUCT to VIEW.
2059 Possible values are: `folded', `children' or `subtree'. See
2060 `org-cycle' for more information."
2063 (let ((item-end (org-list-get-item-end-before-blank item struct
)))
2065 (outline-flag-region (save-excursion (goto-char item
) (point-at-eol))
2067 ((eq view
'children
)
2068 ;; First show everything.
2069 (org-list-set-item-visibility item struct
'subtree
)
2070 ;; Then fold every child.
2071 (let* ((parents (org-list-parents-alist struct
))
2072 (children (org-list-get-children item struct parents
)))
2074 (org-list-set-item-visibility e struct
'folded
))
2078 (let ((item-end (org-list-get-item-end item struct
)))
2079 (outline-flag-region item item-end nil
)))))
2081 (defun org-list-item-body-column (item)
2082 "Return column at which body of ITEM should start."
2085 (looking-at "[ \t]*\\(\\S-+\\)\\(.*[ \t]+::\\)?\\([ \t]+\\|$\\)")
2086 (if (match-beginning 2)
2087 (let ((start (1+ (match-end 2)))
2088 (ind (org-get-indentation)))
2089 (if (> start
(+ ind org-description-max-indent
)) (+ ind
5) start
))
2090 (+ (progn (goto-char (match-end 1)) (current-column))
2091 (if (and org-list-two-spaces-after-bullet-regexp
2092 (org-string-match-p org-list-two-spaces-after-bullet-regexp
2099 ;;; Interactive functions
2101 (defalias 'org-list-get-item-begin
'org-in-item-p
)
2103 (defun org-beginning-of-item ()
2104 "Go to the beginning of the current item.
2105 Throw an error when not in a list."
2107 (let ((begin (org-in-item-p)))
2108 (if begin
(goto-char begin
) (error "Not in an item"))))
2110 (defun org-beginning-of-item-list ()
2111 "Go to the beginning item of the current list or sublist.
2112 Throw an error when not in a list."
2114 (let ((begin (org-in-item-p)))
2116 (error "Not in an item")
2118 (let* ((struct (org-list-struct))
2119 (prevs (org-list-prevs-alist struct
)))
2120 (goto-char (org-list-get-list-begin begin struct prevs
))))))
2122 (defun org-end-of-item-list ()
2123 "Go to the end of the current list or sublist.
2124 Throw an error when not in a list."
2126 (let ((begin (org-in-item-p)))
2128 (error "Not in an item")
2130 (let* ((struct (org-list-struct))
2131 (prevs (org-list-prevs-alist struct
)))
2132 (goto-char (org-list-get-list-end begin struct prevs
))))))
2134 (defun org-end-of-item ()
2135 "Go to the end of the current item.
2136 Throw an error when not in a list."
2138 (let ((begin (org-in-item-p)))
2140 (error "Not in an item")
2142 (let ((struct (org-list-struct)))
2143 (goto-char (org-list-get-item-end begin struct
))))))
2145 (defun org-previous-item ()
2146 "Move to the beginning of the previous item.
2147 Throw an error when not in a list. Also throw an error when at
2148 first item, unless `org-list-use-circular-motion' is non-nil."
2150 (let ((item (org-in-item-p)))
2152 (error "Not in an item")
2154 (let* ((struct (org-list-struct))
2155 (prevs (org-list-prevs-alist struct
))
2156 (prevp (org-list-get-prev-item item struct prevs
)))
2158 (prevp (goto-char prevp
))
2159 (org-list-use-circular-motion
2160 (goto-char (org-list-get-last-item item struct prevs
)))
2161 (t (error "On first item")))))))
2163 (defun org-next-item ()
2164 "Move to the beginning of the next item.
2165 Throw an error when not in a list. Also throw an error when at
2166 last item, unless `org-list-use-circular-motion' is non-nil."
2168 (let ((item (org-in-item-p)))
2170 (error "Not in an item")
2172 (let* ((struct (org-list-struct))
2173 (prevs (org-list-prevs-alist struct
))
2174 (prevp (org-list-get-next-item item struct prevs
)))
2176 (prevp (goto-char prevp
))
2177 (org-list-use-circular-motion
2178 (goto-char (org-list-get-first-item item struct prevs
)))
2179 (t (error "On last item")))))))
2181 (defun org-move-item-down ()
2182 "Move the item at point down, i.e. swap with following item.
2183 Sub-items (items with larger indentation) are considered part of
2184 the item, so this really moves item trees."
2186 (unless (org-at-item-p) (error "Not at an item"))
2187 (let* ((col (current-column))
2188 (item (point-at-bol))
2189 (struct (org-list-struct))
2190 (prevs (org-list-prevs-alist struct
))
2191 (next-item (org-list-get-next-item (point-at-bol) struct prevs
)))
2192 (unless (or next-item org-list-use-circular-motion
)
2193 (user-error "Cannot move this item further down"))
2195 (setq struct
(org-list-send-item item
'begin struct
))
2196 (setq struct
(org-list-swap-items item next-item struct
))
2198 (org-list-get-next-item item struct
(org-list-prevs-alist struct
))))
2199 (org-list-write-struct struct
(org-list-parents-alist struct
))
2200 (org-move-to-column col
)))
2202 (defun org-move-item-up ()
2203 "Move the item at point up, i.e. swap with previous item.
2204 Sub-items (items with larger indentation) are considered part of
2205 the item, so this really moves item trees."
2207 (unless (org-at-item-p) (error "Not at an item"))
2208 (let* ((col (current-column))
2209 (item (point-at-bol))
2210 (struct (org-list-struct))
2211 (prevs (org-list-prevs-alist struct
))
2212 (prev-item (org-list-get-prev-item (point-at-bol) struct prevs
)))
2213 (unless (or prev-item org-list-use-circular-motion
)
2214 (user-error "Cannot move this item further up"))
2216 (setq struct
(org-list-send-item item
'end struct
))
2217 (setq struct
(org-list-swap-items prev-item item struct
)))
2218 (org-list-write-struct struct
(org-list-parents-alist struct
))
2219 (org-move-to-column col
)))
2221 (defun org-insert-item (&optional checkbox
)
2222 "Insert a new item at the current level.
2223 If cursor is before first character after bullet of the item, the
2224 new item will be created before the current one.
2226 If CHECKBOX is non-nil, add a checkbox next to the bullet.
2228 Return t when things worked, nil when we are not in an item, or
2230 (let ((itemp (org-in-item-p))
2232 ;; If cursor isn't is a list or if list is invisible, return nil.
2233 (unless (or (not itemp
)
2236 (outline-invisible-p)))
2239 (org-at-item-timer-p))
2240 ;; Timer list: delegate to `org-timer-item'.
2241 (progn (org-timer-item) t
)
2242 (let* ((struct (save-excursion (goto-char itemp
)
2244 (prevs (org-list-prevs-alist struct
))
2245 ;; If we're in a description list, ask for the new term.
2246 (desc (when (eq (org-list-get-list-type itemp struct prevs
)
2249 (setq struct
(org-list-insert-item pos struct prevs checkbox desc
))
2250 (org-list-write-struct struct
(org-list-parents-alist struct
))
2251 (when checkbox
(org-update-checkbox-count-maybe))
2252 (looking-at org-list-full-item-re
)
2253 (goto-char (if (and (match-beginning 4)
2255 (string-match "[.)]" (match-string 1))))
2258 (if desc
(backward-char 1))
2261 (defun org-list-repair ()
2262 "Fix indentation, bullets and checkboxes in the list at point."
2264 (unless (org-at-item-p) (error "This is not a list"))
2265 (let* ((struct (org-list-struct))
2266 (parents (org-list-parents-alist struct
)))
2267 (org-list-write-struct struct parents
)))
2269 (defun org-cycle-list-bullet (&optional which
)
2270 "Cycle through the different itemize/enumerate bullets.
2271 This cycle the entire list level through the sequence:
2273 `-' -> `+' -> `*' -> `1.' -> `1)'
2275 If WHICH is a valid string, use that as the new bullet. If WHICH
2276 is an integer, 0 means `-', 1 means `+' etc. If WHICH is
2277 `previous', cycle backwards."
2279 (unless (org-at-item-p) (error "Not at an item"))
2282 (let* ((struct (org-list-struct))
2283 (parents (org-list-parents-alist struct
))
2284 (prevs (org-list-prevs-alist struct
))
2285 (list-beg (org-list-get-first-item (point) struct prevs
))
2286 (bullet (org-list-get-bullet list-beg struct
))
2287 (alpha-p (org-list-use-alpha-bul-p list-beg struct prevs
))
2288 (case-fold-search nil
)
2290 ((string-match "[a-z]\\." bullet
) "a.")
2291 ((string-match "[a-z])" bullet
) "a)")
2292 ((string-match "[A-Z]\\." bullet
) "A.")
2293 ((string-match "[A-Z])" bullet
) "A)")
2294 ((string-match "\\." bullet
) "1.")
2295 ((string-match ")" bullet
) "1)")
2296 (t (org-trim bullet
))))
2297 ;; Compute list of possible bullets, depending on context.
2300 ;; *-bullets are not allowed at column 0.
2301 (unless (looking-at "\\S-") '("*"))
2302 ;; Description items cannot be numbered.
2303 (unless (or (eq org-plain-list-ordered-item-terminator ?\
))
2304 (org-at-item-description-p))
2306 (unless (or (eq org-plain-list-ordered-item-terminator ?.
)
2307 (org-at-item-description-p))
2309 (unless (or (not alpha-p
)
2310 (eq org-plain-list-ordered-item-terminator ?\
))
2311 (org-at-item-description-p))
2313 (unless (or (not alpha-p
)
2314 (eq org-plain-list-ordered-item-terminator ?.
)
2315 (org-at-item-description-p))
2317 (len (length bullet-list
))
2318 (item-index (- len
(length (member current bullet-list
))))
2319 (get-value (lambda (index) (nth (mod index len
) bullet-list
)))
2321 ((member which bullet-list
) which
)
2322 ((numberp which
) (funcall get-value which
))
2323 ((eq 'previous which
) (funcall get-value
(1- item-index
)))
2324 (t (funcall get-value
(1+ item-index
))))))
2325 ;; Use a short variation of `org-list-write-struct' as there's
2326 ;; no need to go through all the steps.
2327 (let ((old-struct (copy-tree struct
)))
2328 (org-list-set-bullet list-beg struct
(org-list-bullet-string new
))
2329 (org-list-struct-fix-bul struct prevs
)
2330 (org-list-struct-fix-ind struct parents
)
2331 (org-list-struct-apply-struct struct old-struct
)))))
2333 (defun org-toggle-checkbox (&optional toggle-presence
)
2334 "Toggle the checkbox in the current line.
2335 With prefix arg TOGGLE-PRESENCE, add or remove checkboxes. With
2336 double prefix, set checkbox to [-].
2338 When there is an active region, toggle status or presence of the
2339 first checkbox there, and make every item inside have the same
2340 status or presence, respectively.
2342 If the cursor is in a headline, apply this to all checkbox items
2343 in the text below the heading, taking as reference the first item
2344 in subtree, ignoring drawers."
2351 (keyword-re (concat "^[ \t]*\\<\\(" org-scheduled-string
2352 "\\|" org-deadline-string
2353 "\\|" org-closed-string
2354 "\\|" org-clock-string
"\\)"
2355 " *[[<]\\([^]>]+\\)[]>]"))
2356 (orderedp (org-entry-get nil
"ORDERED"))
2358 ;; In a region, start at first item in region.
2360 ((org-region-active-p)
2361 (let ((limit (region-end)))
2362 (goto-char (region-beginning))
2363 (if (org-list-search-forward (org-item-beginning-re) limit t
)
2364 (setq lim-up
(point-at-bol))
2365 (error "No item in region"))
2366 (setq lim-down
(copy-marker limit
))))
2368 ;; On an heading, start at first item after drawers and
2369 ;; time-stamps (scheduled, etc.).
2370 (let ((limit (save-excursion (outline-next-heading) (point))))
2372 (while (or (looking-at org-drawer-regexp
)
2373 (looking-at keyword-re
))
2374 (if (looking-at keyword-re
)
2376 (re-search-forward "^[ \t]*:END:" limit nil
)))
2377 (if (org-list-search-forward (org-item-beginning-re) limit t
)
2378 (setq lim-up
(point-at-bol))
2379 (error "No item in subtree"))
2380 (setq lim-down
(copy-marker limit
))))
2381 ;; Just one item: set SINGLEP flag.
2384 (setq lim-up
(point-at-bol)
2385 lim-down
(copy-marker (point-at-eol))))
2386 (t (error "Not at an item or heading, and no active region"))))
2387 ;; Determine the checkbox going to be applied to all items
2392 (let ((cbox (and (org-at-item-checkbox-p) (match-string 1))))
2394 ((equal toggle-presence
'(16)) "[-]")
2395 ((equal toggle-presence
'(4))
2396 (unless cbox
"[ ]"))
2397 ((equal "[X]" cbox
) "[ ]")
2399 ;; When an item is found within bounds, grab the full list at
2400 ;; point structure, then: (1) set check-box of all its items
2401 ;; within bounds to REF-CHECKBOX, (2) fix check-boxes of the
2402 ;; whole list, (3) move point after the list.
2404 (while (and (< (point) lim-down
)
2405 (org-list-search-forward (org-item-beginning-re)
2407 (let* ((struct (org-list-struct))
2408 (struct-copy (copy-tree struct
))
2409 (parents (org-list-parents-alist struct
))
2410 (prevs (org-list-prevs-alist struct
))
2411 (bottom (copy-marker (org-list-get-bottom-point struct
)))
2412 (items-to-toggle (org-remove-if
2413 (lambda (e) (or (< e lim-up
) (> e lim-down
)))
2414 (mapcar #'car struct
))))
2415 (mapc (lambda (e) (org-list-set-checkbox
2417 ;; If there is no box at item, leave as-is
2418 ;; unless function was called with C-u prefix.
2419 (let ((cur-box (org-list-get-checkbox e struct
)))
2420 (if (or cur-box
(equal toggle-presence
'(4)))
2424 (setq block-item
(org-list-struct-fix-box
2425 struct parents prevs orderedp
))
2426 ;; Report some problems due to ORDERED status of subtree.
2427 ;; If only one box was being checked, throw an error, else,
2428 ;; only signal problems.
2430 ((and singlep block-item
(> lim-up block-item
))
2432 "Checkbox blocked because of unchecked box at line %d"
2433 (org-current-line block-item
)))
2436 "Checkboxes were removed due to unchecked box at line %d"
2437 (org-current-line block-item
))))
2439 (move-marker bottom nil
)
2440 (org-list-struct-apply-struct struct struct-copy
)))
2441 (move-marker lim-down nil
)))
2442 (org-update-checkbox-count-maybe))
2444 (defun org-reset-checkbox-state-subtree ()
2445 "Reset all checkboxes in an entry subtree."
2447 (if (org-before-first-heading-p)
2448 (error "Not inside a tree")
2451 (org-narrow-to-subtree)
2453 (goto-char (point-min))
2454 (let ((end (point-max)))
2455 (while (< (point) end
)
2456 (when (org-at-item-checkbox-p)
2457 (replace-match "[ ]" t t nil
1))
2458 (beginning-of-line 2)))
2459 (org-update-checkbox-count-maybe 'all
)))))
2461 (defun org-update-checkbox-count (&optional all
)
2462 "Update the checkbox statistics in the current section.
2464 This will find all statistic cookies like [57%] and [6/12] and
2465 update them with the current numbers.
2467 With optional prefix argument ALL, do this for the whole buffer."
2469 (org-with-wide-buffer
2470 (let* ((cookie-re "\\(\\(\\[[0-9]*%\\]\\)\\|\\(\\[[0-9]*/[0-9]*\\]\\)\\)")
2471 (box-re "^[ \t]*\\([-+*]\\|\\([0-9]+\\|[A-Za-z]\\)[.)]\\)[ \t]+\
2472 \\(?:\\[@\\(?:start:\\)?\\([0-9]+\\|[A-Za-z]\\)\\][ \t]*\\)?\\(\\[[- X]\\]\\)")
2474 (or (not org-checkbox-hierarchical-statistics
)
2475 (string-match "\\<recursive\\>"
2476 (or (org-entry-get nil
"COOKIE_DATA") ""))))
2477 (within-inlinetask (and (not all
)
2478 (featurep 'org-inlinetask
)
2479 (org-inlinetask-in-task-p)))
2480 (end (cond (all (point-max))
2482 (save-excursion (outline-next-heading) (point)))
2484 (org-with-limited-levels (outline-next-heading))
2487 (lambda (item structs recursivep
)
2488 ;; Return number of checked boxes and boxes of all types
2489 ;; in all structures in STRUCTS. If RECURSIVEP is
2490 ;; non-nil, also count boxes in sub-lists. If ITEM is
2491 ;; nil, count across the whole structure, else count only
2492 ;; across subtree whose ancestor is ITEM.
2493 (let ((c-on 0) (c-all 0))
2494 (dolist (s structs
(list c-on c-all
))
2495 (let* ((pre (org-list-prevs-alist s
))
2496 (par (org-list-parents-alist s
))
2499 ((and recursivep item
) (org-list-get-subtree item s
))
2500 (recursivep (mapcar #'car s
))
2501 (item (org-list-get-children item s par
))
2502 (t (org-list-get-all-items
2503 (org-list-get-top-point s
) s pre
))))
2504 (cookies (delq nil
(mapcar
2506 (org-list-get-checkbox e s
))
2508 (incf c-all
(length cookies
))
2509 (incf c-on
(org-count "[X]" cookies
)))))))
2512 (cond (all (goto-char (point-min)))
2513 (within-inlinetask (org-back-to-heading t
))
2514 (t (org-with-limited-levels (outline-previous-heading))))
2515 ;; Build an alist for each cookie found. The key is the position
2516 ;; at beginning of cookie and values ending position, format of
2517 ;; cookie, number of checked boxes to report and total number of
2519 (while (re-search-forward cookie-re end t
)
2520 (let ((context (save-excursion (backward-char)
2521 (save-match-data (org-element-context)))))
2522 (when (eq (org-element-type context
) 'statistics-cookie
)
2525 (list (match-beginning 1) (match-end 1) (match-end 2))
2527 (org-element-lineage
2529 '(drawer center-block dynamic-block inlinetask plain-list
2530 quote-block special-block verse-block
)))
2531 (beg (if container
(org-element-property :begin container
)
2533 (org-with-limited-levels (outline-previous-heading))
2535 (or (cdr (assq beg cache
))
2539 (if container
(org-element-property :end container
)
2541 (org-with-limited-levels (outline-next-heading))
2544 (while (re-search-forward box-re end t
)
2545 (let ((element (org-element-at-point)))
2546 (when (eq (org-element-type element
) 'item
)
2547 (push (org-element-property :structure element
)
2549 (goto-char (org-element-property
2551 (org-element-property :parent
2553 ;; Cache count for cookies applying to the same
2554 ;; area. Then return it.
2556 (funcall count-boxes
2557 (and (eq (org-element-type container
)
2559 (org-element-property
2560 :contents-begin container
))
2563 (push (cons beg count
) cache
)
2566 ;; Apply alist to buffer.
2567 (dolist (cookie cookies-list
)
2568 (let* ((beg (car cookie
))
2569 (end (nth 1 cookie
))
2570 (percent (nth 2 cookie
))
2571 (checked (nth 3 cookie
))
2572 (total (nth 4 cookie
)))
2575 (if percent
(format "[%d%%]" (/ (* 100 checked
) (max 1 total
)))
2576 (format "[%d/%d]" checked total
)))
2577 (delete-region (point) (+ (point) (- end beg
)))
2578 (when org-auto-align-tags
(org-fix-tags-on-the-fly)))))))
2580 (defun org-get-checkbox-statistics-face ()
2581 "Select the face for checkbox statistics.
2582 The face will be `org-done' when all relevant boxes are checked.
2583 Otherwise it will be `org-todo'."
2585 (if (equal (match-string 1) "100%")
2586 'org-checkbox-statistics-done
2587 'org-checkbox-statistics-todo
)
2588 (if (and (> (match-end 2) (match-beginning 2))
2589 (equal (match-string 2) (match-string 3)))
2590 'org-checkbox-statistics-done
2591 'org-checkbox-statistics-todo
)))
2593 (defun org-update-checkbox-count-maybe (&optional all
)
2594 "Update checkbox statistics unless turned off by user.
2595 With an optional argument ALL, update them in the whole buffer."
2596 (when (cdr (assq 'checkbox org-list-automatic-rules
))
2597 (org-update-checkbox-count all
))
2598 (run-hooks 'org-checkbox-statistics-hook
))
2600 (defvar org-last-indent-begin-marker
(make-marker))
2601 (defvar org-last-indent-end-marker
(make-marker))
2602 (defun org-list-indent-item-generic (arg no-subtree struct
)
2603 "Indent a local list item including its children.
2604 When number ARG is a negative, item will be outdented, otherwise
2605 it will be indented.
2607 If a region is active, all items inside will be moved.
2609 If NO-SUBTREE is non-nil, only indent the item itself, not its
2612 STRUCT is the list structure.
2614 Return t if successful."
2616 (let* ((regionp (org-region-active-p))
2617 (rbeg (and regionp
(region-beginning)))
2618 (rend (and regionp
(region-end)))
2619 (top (org-list-get-top-point struct
))
2620 (parents (org-list-parents-alist struct
))
2621 (prevs (org-list-prevs-alist struct
))
2622 ;; Are we going to move the whole list?
2625 (= top
(point-at-bol))
2626 (cdr (assq 'indent org-list-automatic-rules
))
2629 "First item of list cannot move without its subtree")
2631 ;; Determine begin and end points of zone to indent. If moving
2632 ;; more than one item, save them for subsequent moves.
2633 (unless (and (memq last-command
'(org-shiftmetaright org-shiftmetaleft
))
2634 (memq this-command
'(org-shiftmetaright org-shiftmetaleft
)))
2637 (set-marker org-last-indent-begin-marker rbeg
)
2638 (set-marker org-last-indent-end-marker rend
))
2639 (set-marker org-last-indent-begin-marker
(point-at-bol))
2640 (set-marker org-last-indent-end-marker
2642 (specialp (org-list-get-bottom-point struct
))
2643 (no-subtree (1+ (point-at-bol)))
2644 (t (org-list-get-item-end (point-at-bol) struct
))))))
2645 (let* ((beg (marker-position org-last-indent-begin-marker
))
2646 (end (marker-position org-last-indent-end-marker
)))
2648 ;; Special case: moving top-item with indent rule.
2650 (let* ((level-skip (org-level-increment))
2651 (offset (if (< arg
0) (- level-skip
) level-skip
))
2652 (top-ind (org-list-get-ind beg struct
))
2653 (old-struct (copy-tree struct
)))
2654 (if (< (+ top-ind offset
) 0)
2655 (error "Cannot outdent beyond margin")
2656 ;; Change bullet if necessary.
2657 (when (and (= (+ top-ind offset
) 0)
2659 (org-list-get-bullet beg struct
)))
2660 (org-list-set-bullet beg struct
2661 (org-list-bullet-string "-")))
2662 ;; Shift every item by OFFSET and fix bullets. Then
2663 ;; apply changes to buffer.
2665 (let ((ind (org-list-get-ind (car e
) struct
)))
2666 (org-list-set-ind (car e
) struct
(+ ind offset
))))
2668 (org-list-struct-fix-bul struct prevs
)
2669 (org-list-struct-apply-struct struct old-struct
))))
2672 ;; If only one item is moved, it mustn't have a child.
2675 (org-list-has-child-p beg struct
))
2676 ;; If a subtree or region is moved, the last item
2677 ;; of the subtree mustn't have a child.
2678 (let ((last-item (caar
2681 (lambda (e) (>= (car e
) end
))
2683 (org-list-has-child-p last-item struct
))))
2684 (error "Cannot outdent an item without its children"))
2689 (org-list-struct-outdent beg end struct parents
)
2690 (org-list-struct-indent beg end struct parents prevs
))))
2691 (org-list-write-struct struct new-parents
))
2692 (org-update-checkbox-count-maybe))))))
2695 (defun org-outdent-item ()
2696 "Outdent a local list item, but not its children.
2697 If a region is active, all items inside will be moved."
2699 (let ((regionp (org-region-active-p)))
2701 ((or (org-at-item-p)
2703 (save-excursion (goto-char (region-beginning))
2705 (let ((struct (if (not regionp
) (org-list-struct)
2706 (save-excursion (goto-char (region-beginning))
2707 (org-list-struct)))))
2708 (org-list-indent-item-generic -
1 t struct
)))
2709 (regionp (error "Region not starting at an item"))
2710 (t (error "Not at an item")))))
2712 (defun org-indent-item ()
2713 "Indent a local list item, but not its children.
2714 If a region is active, all items inside will be moved."
2716 (let ((regionp (org-region-active-p)))
2718 ((or (org-at-item-p)
2720 (save-excursion (goto-char (region-beginning))
2722 (let ((struct (if (not regionp
) (org-list-struct)
2723 (save-excursion (goto-char (region-beginning))
2724 (org-list-struct)))))
2725 (org-list-indent-item-generic 1 t struct
)))
2726 (regionp (error "Region not starting at an item"))
2727 (t (error "Not at an item")))))
2729 (defun org-outdent-item-tree ()
2730 "Outdent a local list item including its children.
2731 If a region is active, all items inside will be moved."
2733 (let ((regionp (org-region-active-p)))
2735 ((or (org-at-item-p)
2737 (save-excursion (goto-char (region-beginning))
2739 (let ((struct (if (not regionp
) (org-list-struct)
2740 (save-excursion (goto-char (region-beginning))
2741 (org-list-struct)))))
2742 (org-list-indent-item-generic -
1 nil struct
)))
2743 (regionp (error "Region not starting at an item"))
2744 (t (error "Not at an item")))))
2746 (defun org-indent-item-tree ()
2747 "Indent a local list item including its children.
2748 If a region is active, all items inside will be moved."
2750 (let ((regionp (org-region-active-p)))
2752 ((or (org-at-item-p)
2754 (save-excursion (goto-char (region-beginning))
2756 (let ((struct (if (not regionp
) (org-list-struct)
2757 (save-excursion (goto-char (region-beginning))
2758 (org-list-struct)))))
2759 (org-list-indent-item-generic 1 nil struct
)))
2760 (regionp (error "Region not starting at an item"))
2761 (t (error "Not at an item")))))
2763 (defvar org-tab-ind-state
)
2764 (defvar org-adapt-indentation
)
2765 (defun org-cycle-item-indentation ()
2766 "Cycle levels of indentation of an empty item.
2767 The first run indents the item, if applicable. Subsequent runs
2768 outdent it at meaningful levels in the list. When done, item is
2769 put back at its original position with its original bullet.
2771 Return t at each successful move."
2772 (when (org-at-item-p)
2773 (let* ((org-adapt-indentation nil
)
2774 (struct (org-list-struct))
2775 (ind (org-list-get-ind (point-at-bol) struct
))
2776 (bullet (org-trim (buffer-substring (point-at-bol) (point-at-eol)))))
2777 ;; Accept empty items or if cycle has already started.
2778 (when (or (eq last-command
'org-cycle-item-indentation
)
2779 (and (save-excursion
2781 (looking-at org-list-full-item-re
))
2782 (>= (match-end 0) (save-excursion
2783 (goto-char (org-list-get-item-end
2784 (point-at-bol) struct
))
2785 (skip-chars-backward " \r\t\n")
2787 (setq this-command
'org-cycle-item-indentation
)
2788 ;; When in the middle of the cycle, try to outdent first. If
2789 ;; it fails, and point is still at initial position, indent.
2790 ;; Else, re-create it at its original position.
2791 (if (eq last-command
'org-cycle-item-indentation
)
2793 ((ignore-errors (org-list-indent-item-generic -
1 t struct
)))
2794 ((and (= ind
(car org-tab-ind-state
))
2795 (ignore-errors (org-list-indent-item-generic 1 t struct
))))
2796 (t (delete-region (point-at-bol) (point-at-eol))
2797 (org-indent-to-column (car org-tab-ind-state
))
2798 (insert (cdr org-tab-ind-state
) " ")
2800 (setq this-command
'identity
)))
2801 ;; If a cycle is starting, remember indentation and bullet,
2802 ;; then try to indent. If it fails, try to outdent.
2803 (setq org-tab-ind-state
(cons ind bullet
))
2805 ((ignore-errors (org-list-indent-item-generic 1 t struct
)))
2806 ((ignore-errors (org-list-indent-item-generic -
1 t struct
)))
2807 (t (user-error "Cannot move item"))))
2810 (defun org-sort-list (&optional with-case sorting-type getkey-func compare-func
)
2812 The cursor may be at any item of the list that should be sorted.
2813 Sublists are not sorted. Checkboxes, if any, are ignored.
2815 Sorting can be alphabetically, numerically, by date/time as given
2816 by a time stamp, by a property or by priority.
2818 Comparing entries ignores case by default. However, with an
2819 optional argument WITH-CASE, the sorting considers case as well.
2821 The command prompts for the sorting type unless it has been given
2822 to the function through the SORTING-TYPE argument, which needs to
2823 be a character, \(?n ?N ?a ?A ?t ?T ?f ?F ?x ?X). Here is the
2824 detailed meaning of each character:
2826 n Numerically, by converting the beginning of the item to a number.
2827 a Alphabetically. Only the first line of item is checked.
2828 t By date/time, either the first active time stamp in the entry, if
2829 any, or by the first inactive one. In a timer list, sort the timers.
2830 x By \"checked\" status of a check list.
2832 Capital letters will reverse the sort order.
2834 If the SORTING-TYPE is ?f or ?F, then GETKEY-FUNC specifies
2835 a function to be called with point at the beginning of the
2836 record. It must return either a string or a number that should
2837 serve as the sorting key for that record. It will then use
2838 COMPARE-FUNC to compare entries.
2840 Sorting is done against the visible part of the headlines, it
2841 ignores hidden links."
2843 (let* ((case-func (if with-case
'identity
'downcase
))
2844 (struct (org-list-struct))
2845 (prevs (org-list-prevs-alist struct
))
2846 (start (org-list-get-list-begin (point-at-bol) struct prevs
))
2847 (end (org-list-get-list-end (point-at-bol) struct prevs
))
2852 "Sort plain list: [a]lpha [n]umeric [t]ime [f]unc [x]checked A/N/T/F/X means reversed:")
2853 (read-char-exclusive))))
2856 (and (= (downcase sorting-type
) ?f
)
2857 (intern (org-icompleting-read "Sort using function: "
2858 obarray
'fboundp t nil nil
))))))
2859 (message "Sorting items...")
2861 (narrow-to-region start end
)
2862 (goto-char (point-min))
2863 (let* ((dcst (downcase sorting-type
))
2864 (case-fold-search nil
)
2865 (now (current-time))
2867 ((= dcst ?a
) 'string
<)
2868 ((= dcst ?f
) compare-func
)
2870 ((= dcst ?x
) 'string
<)))
2871 (next-record (lambda ()
2872 (skip-chars-forward " \r\t\n")
2873 (or (eobp) (beginning-of-line))))
2874 (end-record (lambda ()
2875 (goto-char (org-list-get-item-end-before-blank
2879 (when (looking-at "[ \t]*[-+*0-9.)]+\\([ \t]+\\[[- X]\\]\\)?[ \t]+")
2883 (org-sort-remove-invisible
2884 (buffer-substring (match-end 0) (point-at-eol)))))
2887 (org-sort-remove-invisible
2889 (match-end 0) (point-at-eol)))))
2892 ;; If it is a timer list, convert timer to seconds
2893 ((org-at-item-timer-p)
2894 (org-timer-hms-to-secs (match-string 1)))
2895 ((or (save-excursion
2896 (re-search-forward org-ts-regexp
(point-at-eol) t
))
2897 (save-excursion (re-search-forward org-ts-regexp-both
2899 (org-time-string-to-seconds (match-string 0)))
2900 (t (org-float-time now
))))
2901 ((= dcst ?x
) (or (and (stringp (match-string 1))
2906 (let ((value (funcall getkey-func
)))
2908 (funcall case-func value
)
2910 (error "Invalid key function `%s'" getkey-func
)))
2911 (t (error "Invalid sorting type `%c'" sorting-type
)))))))
2912 (sort-subr (/= dcst sorting-type
)
2918 ;; Read and fix list again, as `sort-subr' probably destroyed
2921 (run-hooks 'org-after-sorting-entries-or-items-hook
)
2922 (message "Sorting items...done")))))
2926 ;;; Send and receive lists
2928 (defun org-list-parse-list (&optional delete
)
2929 "Parse the list at point and maybe DELETE it.
2931 Return a list whose car is a symbol of list type, among
2932 `ordered', `unordered' and `descriptive'. Then, each item is
2933 a list whose car is counter, and cdr are strings and other
2934 sub-lists. Inside strings, check-boxes are replaced by
2935 \"[CBON]\", \"[CBOFF]\" and \"[CBTRANS]\".
2937 For example, the following list:
2942 more text in first item
2948 \(nil \"first item\"
2950 \(nil \"sub-item one\"\)
2951 \(nil \"[CBON] sub-item two\"\)\)
2952 \"more text in first item\"\)
2953 \(3 \"last item\"\)\)
2955 Point is left at list end."
2956 (defvar parse-item
) ;FIXME: Or use `cl-labels' or `letrec'.
2957 (let* ((struct (org-list-struct))
2958 (prevs (org-list-prevs-alist struct
))
2959 (parents (org-list-parents-alist struct
))
2960 (top (org-list-get-top-point struct
))
2961 (bottom (org-list-get-bottom-point struct
))
2965 ;; Return text between BEG and END, trimmed, with
2966 ;; checkboxes replaced.
2968 (let ((text (org-trim (buffer-substring beg end
))))
2969 (if (string-match "\\`\\[\\([-X ]\\)\\]" text
)
2971 (let ((box (match-string 1 text
)))
2973 ((equal box
" ") "CBOFF")
2974 ((equal box
"-") "CBTRANS")
2980 ;; Return a list whose car is list type and cdr a list of
2983 (cons (org-list-get-list-type (car e
) struct prevs
)
2984 (mapcar parse-item e
)))))
2987 ;; Return a list containing counter of item, if any, text
2988 ;; and any sublist inside it.
2990 (let ((start (save-excursion
2992 (looking-at "[ \t]*\\S-+\\([ \t]+\\[@\\(start:\\)?\\([0-9]+\\|[a-zA-Z]\\)\\]\\)?[ \t]*")
2994 ;; Get counter number. For alphabetic counter, get
2995 ;; its position in the alphabet.
2996 (counter (let ((c (org-list-get-counter e struct
)))
2999 ((string-match "[A-Za-z]" c
)
3000 (- (string-to-char (upcase (match-string 0 c
)))
3002 ((string-match "[0-9]+" c
)
3003 (string-to-number (match-string 0 c
))))))
3004 (childp (org-list-has-child-p e struct
))
3005 (end (org-list-get-item-end e struct
)))
3006 ;; If item has a child, store text between bullet and
3007 ;; next child, then recursively parse all sublists. At
3008 ;; the end of each sublist, check for the presence of
3009 ;; text belonging to the original item.
3011 (let* ((children (org-list-get-children e struct parents
))
3012 (body (list (funcall get-text start childp
))))
3014 (let* ((first (car children
))
3015 (sub (org-list-get-all-items first struct prevs
))
3016 (last-c (car (last sub
)))
3017 (last-end (org-list-get-item-end last-c struct
)))
3018 (push (funcall parse-sublist sub
) body
)
3019 ;; Remove children from the list just parsed.
3020 (setq children
(cdr (member last-c children
)))
3021 ;; There is a chunk of text belonging to the
3022 ;; item if last child doesn't end where next
3023 ;; child starts or where item ends.
3024 (unless (= (or (car children
) end
) last-end
)
3025 (push (funcall get-text
3026 last-end
(or (car children
) end
))
3028 (cons counter
(nreverse body
)))
3029 (list counter
(funcall get-text start end
))))))))
3030 ;; Store output, take care of cursor position and deletion of
3031 ;; list, then return output.
3032 (setq out
(funcall parse-sublist
(org-list-get-all-items top struct prevs
)))
3035 (delete-region top bottom
)
3036 (when (and (not (looking-at "[ \t]*$")) (looking-at org-list-end-re
))
3037 (replace-match "")))
3040 (defun org-list-make-subtree ()
3041 "Convert the plain list at point into a subtree."
3043 (if (not (ignore-errors (goto-char (org-in-item-p))))
3044 (error "Not in a list")
3045 (let ((list (save-excursion (org-list-parse-list t
))))
3046 (insert (org-list-to-subtree list
)))))
3048 (defun org-list-insert-radio-list ()
3049 "Insert a radio list template appropriate for this major mode."
3051 (let* ((e (assq major-mode org-list-radio-list-templates
))
3054 (unless e
(error "No radio list setup defined for %s" major-mode
))
3055 (setq name
(read-string "List name: "))
3056 (while (string-match "%n" txt
)
3057 (setq txt
(replace-match name t t txt
)))
3058 (or (bolp) (insert "\n"))
3063 (defun org-list-send-list (&optional maybe
)
3064 "Send a transformed version of this list to the receiver position.
3065 With argument MAYBE, fail quietly if no transformation is defined
3069 (unless (org-at-item-p) (error "Not at a list item"))
3071 (re-search-backward "#\\+ORGLST" nil t
)
3072 (unless (looking-at "\\(?:[ \t]\\)?#\\+ORGLST:[ \t]+SEND[ \t]+\\(\\S-+\\)[ \t]+\\(\\S-+\\)")
3073 (if maybe
(throw 'exit nil
)
3074 (error "Don't know how to transform this list"))))
3075 (let* ((name (match-string 1))
3076 (transform (intern (match-string 2)))
3080 "\\(\\\\end{comment}\\|@end ignore\\|-->\\)" nil t
)
3081 (match-beginning 0)))
3084 (re-search-backward "#\\+ORGLST" nil t
)
3085 (re-search-forward (org-item-beginning-re) bottom-point t
)
3086 (match-beginning 0)))
3087 (plain-list (buffer-substring-no-properties top-point bottom-point
))
3089 (unless (fboundp transform
)
3090 (error "No such transformation function %s" transform
))
3091 (let ((txt (funcall transform plain-list
)))
3092 ;; Find the insertion place
3094 (goto-char (point-min))
3095 (unless (re-search-forward
3096 (concat "BEGIN RECEIVE ORGLST +"
3100 (error "Don't know where to insert translated list"))
3101 (goto-char (match-beginning 0))
3102 (beginning-of-line 2)
3104 (unless (re-search-forward (concat "END RECEIVE ORGLST +" name
) nil t
)
3105 (error "Cannot find end of insertion region"))
3106 (delete-region beg
(point-at-bol))
3109 (message "List converted and installed at receiver location"))))
3111 (defsubst org-list-item-trim-br
(item)
3112 "Trim line breaks in a list ITEM."
3113 (setq item
(replace-regexp-in-string "\n +" " " item
)))
3115 (defun org-list-to-generic (list params
)
3116 "Convert a LIST parsed through `org-list-parse-list' to other formats.
3117 Valid parameters PARAMS are:
3119 :ustart String to start an unordered list
3120 :uend String to end an unordered list
3122 :ostart String to start an ordered list
3123 :oend String to end an ordered list
3125 :dstart String to start a descriptive list
3126 :dend String to end a descriptive list
3127 :dtstart String to start a descriptive term
3128 :dtend String to end a descriptive term
3129 :ddstart String to start a description
3130 :ddend String to end a description
3132 :splice When set to t, return only list body lines, don't wrap
3133 them into :[u/o]start and :[u/o]end. Default is nil.
3135 :istart String to start a list item.
3136 :icount String to start an item with a counter.
3137 :iend String to end a list item
3138 :isep String to separate items
3139 :lsep String to separate sublists
3140 :csep String to separate text from a sub-list
3142 :cboff String to insert for an unchecked check-box
3143 :cbon String to insert for a checked check-box
3144 :cbtrans String to insert for a check-box in transitional state
3146 :nobr Non-nil means remove line breaks in lists items.
3148 Alternatively, each parameter can also be a form returning
3149 a string. These sexp can use keywords `counter' and `depth',
3150 representing respectively counter associated to the current
3151 item, and depth of the current sub-list, starting at 0.
3152 Obviously, `counter' is only available for parameters applying to
3156 (splicep (plist-get p
:splice
))
3157 (ostart (plist-get p
:ostart
))
3158 (oend (plist-get p
:oend
))
3159 (ustart (plist-get p
:ustart
))
3160 (uend (plist-get p
:uend
))
3161 (dstart (plist-get p
:dstart
))
3162 (dend (plist-get p
:dend
))
3163 (dtstart (plist-get p
:dtstart
))
3164 (dtend (plist-get p
:dtend
))
3165 (ddstart (plist-get p
:ddstart
))
3166 (ddend (plist-get p
:ddend
))
3167 (istart (plist-get p
:istart
))
3168 (icount (plist-get p
:icount
))
3169 (iend (plist-get p
:iend
))
3170 (isep (plist-get p
:isep
))
3171 (lsep (plist-get p
:lsep
))
3172 (csep (plist-get p
:csep
))
3173 (cbon (plist-get p
:cbon
))
3174 (cboff (plist-get p
:cboff
))
3175 (cbtrans (plist-get p
:cbtrans
))
3176 (nobr (plist-get p
:nobr
))
3177 export-sublist
; for byte-compiler
3180 ;; Export an item ITEM of type TYPE, at DEPTH. First
3181 ;; string in item is treated in a special way as it can
3182 ;; bring extra information that needs to be processed.
3183 (lambda (item type depth
)
3184 (let* ((counter (pop item
))
3187 ((eq type
'descriptive
)
3188 ;; Stick DTSTART to ISTART by
3189 ;; left-trimming the latter.
3190 (concat (let ((s (eval istart
)))
3191 (or (and (string-match "[ \t\n\r]+\\'" s
)
3192 (replace-match "" t t s
))
3195 ((and counter
(eq type
'ordered
))
3196 (concat (eval icount
) "%s"))
3197 (t (concat (eval istart
) "%s")))
3200 ;; Replace checkbox if any is found.
3202 ((string-match "\\[CBON\\]" first
)
3203 (setq first
(replace-match cbon t t first
)))
3204 ((string-match "\\[CBOFF\\]" first
)
3205 (setq first
(replace-match cboff t t first
)))
3206 ((string-match "\\[CBTRANS\\]" first
)
3207 (setq first
(replace-match cbtrans t t first
))))
3208 ;; Replace line breaks if required
3209 (when nobr
(setq first
(org-list-item-trim-br first
)))
3210 ;; Insert descriptive term if TYPE is `descriptive'.
3211 (when (eq type
'descriptive
)
3213 (string-match "^\\(.*\\)[ \t]+::[ \t]*" first
))
3216 (org-trim (match-string 1 first
)))
3218 (desc (if complete
(substring first
(match-end 0))
3220 (setq first
(concat (eval dtstart
) term
(eval dtend
)
3221 (eval ddstart
) desc
))))
3224 (mapconcat (lambda (e)
3226 (funcall export-sublist e
(1+ depth
))))
3227 item
(or (eval csep
) "")))))))
3230 ;; Export sublist SUB at DEPTH.
3232 (let* ((type (car sub
))
3237 (concat (eval ostart
) "%s" (eval oend
)))
3238 ((eq type
'descriptive
)
3239 (concat (eval dstart
) "%s" (eval dend
)))
3240 (t (concat (eval ustart
) "%s" (eval uend
))))
3242 (format fmt
(mapconcat (lambda (e)
3243 (funcall export-item e type depth
))
3244 items
(or (eval isep
) ""))))))))
3245 (concat (funcall export-sublist list
0) "\n")))
3247 (defun org-list-to-latex (list &optional _params
)
3248 "Convert LIST into a LaTeX list.
3249 LIST is as string representing the list to transform, as Org
3250 syntax. Return converted list as a string."
3252 (org-export-string-as list
'latex t
))
3254 (defun org-list-to-html (list)
3255 "Convert LIST into a HTML list.
3256 LIST is as string representing the list to transform, as Org
3257 syntax. Return converted list as a string."
3259 (org-export-string-as list
'html t
))
3261 (defun org-list-to-texinfo (list &optional _params
)
3262 "Convert LIST into a Texinfo list.
3263 LIST is as string representing the list to transform, as Org
3264 syntax. Return converted list as a string."
3265 (require 'ox-texinfo
)
3266 (org-export-string-as list
'texinfo t
))
3268 (defun org-list-to-subtree (list &optional params
)
3269 "Convert LIST into an Org subtree.
3270 LIST is as returned by `org-list-parse-list'. PARAMS is a property list
3271 with overruling parameters for `org-list-to-generic'."
3272 (defvar get-stars
) (defvar org--blankp
)
3273 (let* ((rule (cdr (assq 'heading org-blank-before-new-entry
)))
3274 (level (org-reduced-level (or (org-current-level) 0)))
3275 (org--blankp (or (eq rule t
)
3276 (and (eq rule
'auto
)
3278 (outline-previous-heading)
3279 (org-previous-line-empty-p)))))
3280 (get-stars ;FIXME: Can't rename without renaming it in org.el as well!
3282 ;; Return the string for the heading, depending on depth D
3283 ;; of current sub-list.
3285 (let ((oddeven-level (+ level d
1)))
3286 (concat (make-string (if org-odd-levels-only
3287 (1- (* 2 oddeven-level
))
3291 (org-list-to-generic
3295 :dtstart
" " :dtend
" "
3296 :istart
(funcall get-stars depth
)
3297 :icount
(funcall get-stars depth
)
3298 :isep
(if org--blankp
"\n\n" "\n")
3299 :csep
(if org--blankp
"\n\n" "\n")
3300 :cbon
"DONE" :cboff
"TODO" :cbtrans
"TODO")
3305 ;;; org-list.el ends here