summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2010-08-28 12:53:19 +0200
committerNicolas Goaziou <n.goaziou@gmail.com>2010-09-01 19:05:56 +0200
commit8e5729c466f4f673519b116152518a9bad5154cf (patch)
tree8d92cc43b207b40cf4cf5e0d24262bd5bd8f5212
parentd05c77d6a5150207b061bea82b39b85de2b020b6 (diff)
downloadorg-mode-8e5729c466f4f673519b116152518a9bad5154cf.tar.gz
Speed optimizations and docstring modifications.
-rw-r--r--lisp/org-html.el8
-rw-r--r--lisp/org-list.el807
2 files changed, 440 insertions, 375 deletions
diff --git a/lisp/org-html.el b/lisp/org-html.el
index 23b2729..df55de0 100644
--- a/lisp/org-html.el
+++ b/lisp/org-html.el
@@ -1495,14 +1495,6 @@ lang=\"%s\" xml:lang=\"%s\">
(setq txt (replace-match "" t t txt)))
(if (<= level (max umax umax-toc))
(setq head-count (+ head-count 1)))
- (when in-local-list
- ;; Close any local lists before inserting a new header line
- (while local-list-type
- (org-close-li (car local-list-type))
- (insert (format "</%sl>\n" (car local-list-type)))
- (pop local-list-type))
- (setq local-list-indent nil
- in-local-list nil))
(setq first-heading-pos (or first-heading-pos (point)))
(org-html-level-start level txt umax
(and org-export-with-toc (<= level umax))
diff --git a/lisp/org-list.el b/lisp/org-list.el
index 8a927db..3adf891 100644
--- a/lisp/org-list.el
+++ b/lisp/org-list.el
@@ -175,7 +175,7 @@ determine lists endings. This is the default method."
"Non-nil means an empty line ends all plain list levels.
This variable only makes sense if `org-list-ending-method' is set
-to regexp or both. This is then equivalent to set
+to `regexp' or `both'. This is then equivalent to set
`org-list-end-regexp' to \"^[ \\t]*$\"."
:group 'org-plain-lists
:type 'boolean)
@@ -294,8 +294,8 @@ of `org-plain-list-ordered-item-terminator'."
(defconst org-item-beginning-re (concat "^" (org-item-re))
"Regexp matching the beginning of a plain list item.")
-(defun org-list-terminator-between (min max &optional firstp)
- "Find the position of a list ender between MIN and MAX, or nil.
+(defun org-list-ending-between (min max &optional firstp)
+ "Find the position of a list ending between MIN and MAX, or nil.
This function looks for `org-list-end-re' outside a block.
If FIRSTP in non-nil, return the point at the beginning of the
@@ -310,7 +310,7 @@ the end of the nearest terminator from MAX."
(list-end-p (progn
(goto-char start)
(funcall search-fun (org-list-end-re) end t))))
- ;; Is there a valid list terminator somewhere ?
+ ;; Is there a valid list ending somewhere ?
(and list-end-p
;; we want to be on the first line of the list ender
(match-beginning 0)))))
@@ -368,10 +368,9 @@ Arguments REGEXP, BOUND and NOERROR are similar to those used in
"Is the cursor inside a plain list?
Plain lists are considered ending when a non-blank line is less
-indented than the previous item within LIMIT.
-
-Return the position of the previous item, if applicable."
+indented than the previous item within LIMIT."
(save-excursion
+ (beginning-of-line)
(cond
;; do not start searching inside a block...
((org-list-maybe-skip-block #'re-search-backward limit))
@@ -380,35 +379,24 @@ Return the position of the previous item, if applicable."
(skip-chars-backward " \r\t\n")
(beginning-of-line)))
(beginning-of-line)
- (or (and (org-at-item-p) (point-at-bol))
+ (or (org-at-item-p)
(let* ((case-fold-search t)
- (pos (point))
(ind-ref (org-get-indentation))
- ;; Is there an item above?
+ ;; Ensure there is at least an item above
(up-item-p (save-excursion
- (goto-char limit)
- (org-search-forward-unenclosed
- org-item-beginning-re pos t))))
+ (org-search-backward-unenclosed
+ org-item-beginning-re limit t))))
(and up-item-p
(catch 'exit
(while t
(cond
- ((looking-at "^[ \t]*:END:")
- (throw 'exit nil))
- ((<= (point) limit)
- (throw 'exit
- (and (org-at-item-p)
- (< (org-get-indentation) ind-ref)
- (point-at-bol))))
+ ((org-at-item-p)
+ (throw 'exit (< (org-get-indentation) ind-ref)))
((looking-at "^[ \t]*$")
(skip-chars-backward " \r\t\n")
(beginning-of-line))
((looking-at "^[ \t]*#\\+end_")
(re-search-backward "^[ \t]*#\\+begin_"))
- ((looking-at org-item-beginning-re)
- (if (< (org-get-indentation) ind-ref)
- (throw 'exit (point-at-bol))
- (forward-line -1)))
(t
(setq ind-ref (min (org-get-indentation) ind-ref))
(forward-line -1))))))))))
@@ -427,84 +415,79 @@ Argument LIMIT specifies the upper-bound of the search."
(last-item-start (save-excursion
(org-search-backward-unenclosed
org-item-beginning-re limit t)))
- (list-ender (org-list-terminator-between
+ (list-ender (org-list-ending-between
last-item-start actual-pos)))
;; We are in a list when we are on an item line or when we can
;; find an item before point and there is no valid list ender
;; between it and the point.
- (and last-item-start
- (not list-ender)))))
+ (and last-item-start (not list-ender)))))
(defun org-list-top-point-with-regexp (limit)
- "Return point at the top level item in a list, or nil if not in a list.
+ "Return point at the top level item in a list.
Argument LIMIT specifies the upper-bound of the search.
List ending is determined by regexp. See
`org-list-ending-method'. for more information."
(save-excursion
- (and (org-list-in-item-p-with-regexp limit)
- (let ((pos (point-at-eol)))
- ;; Is there some list above this one ? If so, go to its ending.
- ;; Otherwise, go back to the heading above or bob.
- (goto-char (or (org-list-terminator-between limit pos) limit))
- ;; From there, search down our list.
- (org-search-forward-unenclosed org-item-beginning-re pos t)
- (point-at-bol)))))
+ (let ((pos (point-at-eol)))
+ ;; Is there some list above this one ? If so, go to its ending.
+ ;; Otherwise, go back to the heading above or bob.
+ (goto-char (or (org-list-ending-between limit pos) limit))
+ ;; From there, search down our list.
+ (org-search-forward-unenclosed org-item-beginning-re pos t)
+ (point-at-bol))))
(defun org-list-bottom-point-with-regexp (limit)
- "Return point just before list ending or nil if not in a list.
+ "Return point just before list ending.
Argument LIMIT specifies the lower-bound of the search.
List ending is determined by regexp. See
`org-list-ending-method'. for more information."
(save-excursion
- (and (org-in-item-p)
- (let ((pos (point)))
- ;; The list ending is either first point matching
- ;; `org-list-end-re', point at first white-line before next
- ;; heading, or eob.
- (or (org-list-terminator-between (min pos limit) limit t) limit)))))
+ (let ((pos (org-get-item-beginning)))
+ ;; The list ending is either first point matching
+ ;; `org-list-end-re', point at first white-line before next
+ ;; heading, or eob.
+ (or (org-list-ending-between (min pos limit) limit t) limit))))
(defun org-list-top-point-with-indent (limit)
- "Return point at the top level in a list, or nil if not in a list.
+ "Return point at the top level in a list.
Argument LIMIT specifies the upper-bound of the search.
List ending is determined by indentation of text. See
`org-list-ending-method'. for more information."
(save-excursion
- (let ((prev-p (org-list-in-item-p-with-indent limit))
- (case-fold-search t))
- (and prev-p
- (let ((item-ref (goto-char prev-p))
- (ind-ref 10000))
- (forward-line -1)
- (catch 'exit
- (while t
- (let ((ind (org-get-indentation)))
- (cond
- ((looking-at "^[ \t]*:END:")
- (throw 'exit item-ref))
- ((<= (point) limit)
- (throw 'exit
- (if (and (org-at-item-p) (< ind ind-ref))
- (point-at-bol)
- item-ref)))
- ((looking-at "^[ \t]*$")
- (skip-chars-backward " \r\t\n")
- (beginning-of-line))
- ((looking-at "^[ \t]*#\\+end_")
- (re-search-backward "^[ \t]*#\\+begin_"))
- ((not (looking-at org-item-beginning-re))
- (setq ind-ref (min ind ind-ref))
- (forward-line -1))
- ((>= ind ind-ref)
- (throw 'exit item-ref))
- (t
- (setq item-ref (point-at-bol) ind-ref 10000)
- (forward-line -1)))))))))))
+ (let ((case-fold-search t))
+ (let ((item-ref (goto-char (org-get-item-beginning)))
+ (ind-ref 10000))
+ (forward-line -1)
+ (catch 'exit
+ (while t
+ (let ((ind (org-get-indentation)))
+ (cond
+ ((looking-at "^[ \t]*:END:")
+ (throw 'exit item-ref))
+ ((<= (point) limit)
+ (throw 'exit
+ (if (and (org-at-item-p) (< ind ind-ref))
+ (point-at-bol)
+ item-ref)))
+ ((looking-at "^[ \t]*$")
+ (skip-chars-backward " \r\t\n")
+ (beginning-of-line))
+ ((looking-at "^[ \t]*#\\+end_")
+ (re-search-backward "^[ \t]*#\\+begin_"))
+ ((not (org-at-item-p))
+ (setq ind-ref (min ind ind-ref))
+ (forward-line -1))
+ ((>= ind ind-ref)
+ (throw 'exit item-ref))
+ (t
+ (setq item-ref (point-at-bol) ind-ref 10000)
+ (forward-line -1))))))))))
(defun org-list-bottom-point-with-indent (limit)
"Return point just before list ending or nil if not in a list.
@@ -514,36 +497,37 @@ Argument LIMIT specifies the lower-bound of the search.
List ending is determined by the indentation of text. See
`org-list-ending-method' for more information."
(save-excursion
- (let* ((beg-item (org-in-item-p))
- (ind-ref (save-excursion
- (when beg-item
- (goto-char beg-item)
- (org-get-indentation))))
- (case-fold-search t))
+ (let ((ind-ref (progn
+ (goto-char (org-get-item-beginning))
+ (org-get-indentation)))
+ (case-fold-search t))
;; do not start inside a block
(org-list-maybe-skip-block #'re-search-forward limit)
(beginning-of-line)
- (and beg-item
- (catch 'exit
- (skip-chars-forward " \t")
- (while t
- (let ((ind (org-get-indentation)))
- (cond
- ((or (>= (point) limit)
- (looking-at ":END:"))
- (throw 'exit (point)))
- ((= (point) (point-at-eol))
- (skip-chars-forward " \r\t\n")
- (beginning-of-line))
- ((org-at-item-p)
- (setq ind-ref (min ind ind-ref))
- (forward-line 1))
- ((<= ind ind-ref)
- (throw 'exit (point-at-bol)))
- ((looking-at "#\\+begin_")
- (re-search-forward "[ \t]*#\\+end_")
- (forward-line 1))
- (t (forward-line 1))))))))))
+ (catch 'exit
+ (skip-chars-forward " \t")
+ (while t
+ (let ((ind (org-get-indentation)))
+ (cond
+ ((or (>= (point) limit)
+ (looking-at ":END:"))
+ (throw 'exit (progn
+ ;; Ensure bottom is just after a
+ ;; non-blank line.
+ (skip-chars-backward " \r\t\n")
+ (min (point-max) (1+ (point-at-eol))))))
+ ((= (point) (point-at-eol))
+ (skip-chars-forward " \r\t\n")
+ (beginning-of-line))
+ ((org-at-item-p)
+ (setq ind-ref (min ind ind-ref))
+ (forward-line 1))
+ ((<= ind ind-ref)
+ (throw 'exit (point-at-bol)))
+ ((looking-at "#\\+begin_")
+ (re-search-forward "[ \t]*#\\+end_")
+ (forward-line 1))
+ (t (forward-line 1)))))))))
(defun org-list-at-regexp-after-bullet-p (regexp)
"Is point at a list item with REGEXP after bullet?"
@@ -561,10 +545,8 @@ Search items using function SEARCH-FUN, from POS to LIMIT. It
uses PRE-MOVE before search. Return nil if no item was found."
(save-excursion
(goto-char pos)
- (let ((ind (progn
- (org-beginning-of-item)
- (org-get-indentation)))
- (start (point-at-bol)))
+ (let* ((start (org-get-item-beginning))
+ (ind (progn (goto-char start) (org-get-indentation))))
;; We don't want to match the current line.
(funcall pre-move)
;; Skip any sublist on the way
@@ -574,6 +556,49 @@ uses PRE-MOVE before search. Return nil if no item was found."
(= (org-get-indentation) ind))
(point-at-bol)))))
+(defun org-list-separating-blank-lines-number (top bottom)
+ "Return number of blank lines that should separate items in list.
+
+TOP and BOTTOM are respectively position of list beginning and
+list ending.
+
+Assume point is at item's beginning. If the item is alone, apply
+some heuristics to guess the result."
+ (save-excursion
+ (let ((insert-blank-p
+ (cdr (assq 'plain-list-item org-blank-before-new-entry)))
+ usr-blank)
+ (cond
+ ;; Trivial cases where there should be none.
+ ((or (and (not (eq org-list-ending-method 'indent))
+ org-empty-line-terminates-plain-lists)
+ (not insert-blank-p)) 0)
+ ;; When `org-blank-before-new-entry' says so, it is 1.
+ ((eq insert-blank-p t) 1)
+ ;; plain-list-item is 'auto. Count blank lines separating
+ ;; neighbours items in list.
+ (t (let ((next-p (org-get-next-item (point) bottom)))
+ (cond
+ ;; Is there a next item?
+ (next-p (goto-char next-p)
+ (org-back-over-empty-lines))
+ ;; Is there a previous item?
+ ((org-get-previous-item (point) top)
+ (org-back-over-empty-lines))
+ ;; User inserted blank lines, trust him
+ ((and (> true-pos (org-end-of-item-before-blank bottom))
+ (> (save-excursion
+ (goto-char true-pos)
+ (skip-chars-backward " \t")
+ (setq usr-blank (org-back-over-empty-lines))) 0))
+ usr-blank)
+ ;; Are there blank lines inside the item ?
+ ((save-excursion
+ (org-search-forward-unenclosed
+ "^[ \t]*$" (org-end-of-item-before-blank bottom) t)) 1)
+ ;; No parent: no blank line.
+ (t 0))))))))
+
(defun org-list-insert-item-generic (pos &optional checkbox after-bullet)
"Insert a new list item at POS.
@@ -596,7 +621,9 @@ function ends."
(re-search-backward "^[ \t]*#\\+\\(begin\\|BEGIN\\)_" nil t)
(end-of-line 0)))
(let* ((true-pos (point))
- (bullet (and (org-beginning-of-item)
+ (top (org-list-top-point))
+ (bottom (copy-marker (org-list-bottom-point)))
+ (bullet (and (goto-char (org-get-item-beginning))
(org-list-bullet-string (org-get-bullet))))
(ind (org-get-indentation))
(before-p (progn
@@ -607,60 +634,33 @@ function ends."
;; Otherwise, text starts after bullet.
(org-at-item-p))
(<= true-pos (match-end 0))))
- ;; Guess number of blank lines used to separate items.
- (blank-lines-nb
- (let ((insert-blank-p
- (cdr (assq 'plain-list-item org-blank-before-new-entry)))
- usr-blank)
- (cond
- ;; Trivial cases where there should be none.
- ((or (and (not (eq org-list-ending-method 'indent))
- org-empty-line-terminates-plain-lists)
- (not insert-blank-p)) 0)
- ;; When `org-blank-before-new-entry' says so, it is 1.
- ((eq insert-blank-p t) 1)
- ;; plain-list-item is 'auto. Count blank lines separating
- ;; neighbours items in list.
- (t (let ((next-p (org-get-next-item (point)
- (org-list-bottom-point))))
- (cond
- ;; Is there a next item?
- (next-p (goto-char next-p)
- (org-back-over-empty-lines))
- ;; Is there a previous item?
- ((not (org-list-first-item-p)) (org-back-over-empty-lines))
- ;; User inserted blank lines, trust him
- ((and (> true-pos (org-end-of-item-before-blank))
- (> (save-excursion
- (goto-char true-pos)
- (skip-chars-backward " \t")
- (setq usr-blank (org-back-over-empty-lines))) 0))
- usr-blank)
- ;; Item alone: count lines separating it from parent, if any
- ((/= (org-list-top-point) (point-at-bol))
- (org-back-over-empty-lines))
- ;; Are there blank lines inside the item ?
- ((save-excursion
- (org-search-forward-unenclosed
- "^[ \t]*$" (org-end-of-item-before-blank) t)) 1)
- ;; No parent: no blank line.
- (t 0)))))))
+ (blank-lines-nb (org-list-separating-blank-lines-number top bottom))
(insert-fun
(lambda (text)
;; insert bullet above item in order to avoid bothering
;; with possible blank lines ending last item.
- (org-beginning-of-item)
+ (goto-char (org-get-item-beginning))
(indent-to-column ind)
(insert (concat bullet (when checkbox "[ ] ") after-bullet))
;; Stay between after-bullet and before text.
(save-excursion
(insert (concat text (make-string (1+ blank-lines-nb) ?\n))))
- (unless before-p (org-move-item-down))
- (when checkbox (org-update-checkbox-count-maybe)))))
+ (unless before-p
+ ;; store bottom: exchanging items doesn't change list
+ ;; bottom point but will modify marker anyway
+ (setq bottom (marker-position bottom))
+ (let ((col (current-column)))
+ (org-list-exchange-items
+ (org-get-item-beginning) (org-get-next-item (point) bottom)
+ bottom)
+ ;; recompute next-item: last sexp modified list
+ (goto-char (org-get-next-item (point) bottom))
+ (org-move-to-column col)))
+ (when checkbox (org-update-checkbox-count-maybe))
+ (org-list-repair nil top bottom))))
(goto-char true-pos)
(cond
- (before-p (funcall insert-fun nil)
- (org-list-repair) t)
+ (before-p (funcall insert-fun nil) t)
;; Can't split item: insert bullet at the end of item.
((not (org-get-alist-option org-M-RET-may-split-line 'item))
(funcall insert-fun nil) t)
@@ -670,7 +670,7 @@ function ends."
(delete-horizontal-space)
;; Get pos again in case previous command modified line.
(let* ((pos (point))
- (end-before-blank (org-end-of-item-before-blank))
+ (end-before-blank (org-end-of-item-before-blank bottom))
(after-text
(when (< pos end-before-blank)
(prog1
@@ -685,7 +685,7 @@ function ends."
(defvar org-last-indent-begin-marker (make-marker))
(defvar org-last-indent-end-marker (make-marker))
-(defun org-list-indent-item-generic (arg no-subtree)
+(defun org-list-indent-item-generic (arg no-subtree top bottom)
"Indent a local list item including its children.
When number ARG is a negative, item will be outdented, otherwise
@@ -696,6 +696,9 @@ If a region is active, all items inside will be moved.
If NO-SUBTREE is non-nil, only indent the item itself, not its
children.
+TOP and BOTTOM are respectively position at item beginning and at
+item ending.
+
Return t if successful."
(let* ((regionp (org-region-active-p))
(rbeg (and regionp (region-beginning)))
@@ -709,8 +712,7 @@ Return t if successful."
(error "Not on an item"))
(t
;; Are we going to move the whole list?
- (let* ((top (org-list-top-point))
- (specialp (and (cdr (assq 'indent org-list-automatic-rules))
+ (let* ((specialp (and (cdr (assq 'indent org-list-automatic-rules))
(not no-subtree)
(= top (point-at-bol)))))
;; Determine begin and end points of zone to indent. If moving
@@ -725,13 +727,14 @@ Return t if successful."
(set-marker org-last-indent-end-marker
(save-excursion
(cond
- (specialp (org-list-bottom-point))
- (no-subtree (org-end-of-item-or-at-child))
- (t (org-end-of-item)))))))
+ (specialp bottom)
+ (no-subtree (org-end-of-item-or-at-child bottom))
+ (t (org-get-end-of-item bottom)))))))
;; Get everything ready
(let* ((beg (marker-position org-last-indent-begin-marker))
(end (marker-position org-last-indent-end-marker))
- (struct (org-list-struct beg end (< arg 0) top (if specialp end)))
+ (struct (org-list-struct
+ beg end top (if specialp end bottom) (< arg 0)))
(origins (org-list-struct-origins struct))
(beg-item (assq beg struct)))
(cond
@@ -751,7 +754,7 @@ Return t if successful."
(let ((anc (car struct)))
(setcdr anc (list (+ (nth 1 anc) offset) "" nil)))
(org-list-struct-fix-struct struct origins)
- (org-list-struct-apply-struct struct))))
+ (org-list-struct-apply-struct struct end))))
;; Forbidden move
((and (< arg 0)
(or (and no-subtree
@@ -760,7 +763,7 @@ Return t if successful."
(let ((last-item (save-excursion
(goto-char end)
(skip-chars-backward " \r\t\n")
- (org-beginning-of-item)
+ (goto-char (org-get-item-beginning))
(org-list-struct-assoc-at-point))))
(org-list-struct-get-child last-item struct))))
(error "Cannot outdent an item without its children"))
@@ -770,7 +773,7 @@ Return t if successful."
(org-list-struct-outdent beg end origins)
(org-list-struct-indent beg end origins struct))))
(org-list-struct-fix-struct struct shifted-ori)
- (org-list-struct-apply-struct struct))))))))))
+ (org-list-struct-apply-struct struct bottom))))))))))
;;; Predicates
@@ -793,14 +796,15 @@ This checks `org-list-ending-method'."
(t (and (org-list-in-item-p-with-regexp bound)
(org-list-in-item-p-with-indent bound)))))))
-(defun org-list-first-item-p ()
+(defun org-list-first-item-p (top)
"Is this item the first item in a plain list?
-Assume point is at an item."
+Assume point is at an item.
+
+TOP is the position of list's top-item."
(save-excursion
(beginning-of-line)
(let ((ind (org-get-indentation)))
- (or (not (org-search-backward-unenclosed
- org-item-beginning-re (org-list-top-point) t))
+ (or (not (org-search-backward-unenclosed org-item-beginning-re top t))
(< (org-get-indentation) ind)))))
(defun org-at-item-p ()
@@ -851,8 +855,17 @@ A checkbox is blocked if all of the following conditions are fulfilled:
;;; Navigate
+;; Every interactive navigation function is derived from a
+;; non-interactive one, which doesn't move point, assumes point is
+;; already in a list and doesn't compute list boundaries.
+
+;; If you plan to use more than one org-list function is some code,
+;; you should therefore first compute list boundaries, and then make
+;; use of non-interactive forms.
+
(defun org-list-top-point ()
- "Return point at the top level in a list, or nil if not in a list."
+ "Return point at the top level in a list.
+Assume point is in a list."
(let* ((prev-head (save-excursion (outline-previous-heading)))
(bound (if prev-head
(or (save-excursion
@@ -869,7 +882,8 @@ A checkbox is blocked if all of the following conditions are fulfilled:
(org-list-top-point-with-indent (or top-re bound)))))))
(defun org-list-bottom-point ()
- "Return point just before list ending or nil if not in a list."
+ "Return point just before list ending.
+Assume point is in a list."
(let* ((next-head (save-excursion
(and (let ((outline-regexp org-outline-regexp))
;; Use default regexp because folding
@@ -879,122 +893,148 @@ A checkbox is blocked if all of the following conditions are fulfilled:
(and (re-search-forward "^[ \t]*:END:" next-head t)
(point-at-bol)))
next-head
- (point-max)))
- (bottom (cond
- ((eq org-list-ending-method 'regexp)
- (org-list-bottom-point-with-regexp limit))
- ((eq org-list-ending-method 'indent)
- (org-list-bottom-point-with-indent limit))
- (t (let ((bottom-re (org-list-bottom-point-with-regexp limit)))
- (org-list-bottom-point-with-indent (or bottom-re limit)))))))
- (when bottom
- (save-excursion
- (goto-char bottom)
- (if (eobp)
- (point)
- (skip-chars-backward " \r\t\n")
- (1+ (point-at-eol)))))))
+ (point-max))))
+ (cond
+ ((eq org-list-ending-method 'regexp)
+ (org-list-bottom-point-with-regexp limit))
+ ((eq org-list-ending-method 'indent)
+ (org-list-bottom-point-with-indent limit))
+ (t (let ((bottom-re (org-list-bottom-point-with-regexp limit)))
+ (org-list-bottom-point-with-indent (or bottom-re limit)))))))
+
+(defun org-get-item-beginning ()
+ "Return position of current item beginning."
+ (save-excursion
+ ;; possibly match current line
+ (end-of-line)
+ (org-search-backward-unenclosed org-item-beginning-re nil t)
+ (point-at-bol)))
(defun org-beginning-of-item ()
"Go to the beginning of the current hand-formatted item.
-If the cursor is not in an item, throw an error. Return point."
+If the cursor is not in an item, throw an error."
(interactive)
- (if (not (org-in-item-p))
- (error "Not in an item")
- ;; Possibly match the current line.
- (end-of-line)
- (org-search-backward-unenclosed org-item-beginning-re nil t)
- (goto-char (point-at-bol))))
+ (if (org-in-item-p)
+ (goto-char (org-get-item-beginning))
+ (error "Not in an item")))
-(defun org-end-of-item ()
- "Go to the end of the current hand-formatted item.
-If the cursor is not in an item, throw an error. Return point."
+(defun org-get-beginning-of-list (top)
+ "Return position of the first item of the current list or sublist.
+TOP is the position at list beginning."
+ (save-excursion
+ (let (prev-p)
+ (while (setq prev-p (org-get-previous-item (point) top))
+ (goto-char prev-p))
+ (point-at-bol))))
+
+(defun org-beginning-of-item-list ()
+ "Go to the beginning item of the current list or sublist.
+Return an error if not in a list."
(interactive)
- (let ((next-p (org-get-next-item (point) (org-list-bottom-point))))
- (if next-p (goto-char next-p) (org-end-of-item-list))))
+ (if (org-in-item-p)
+ (goto-char (org-get-beginning-of-list (org-list-top-point)))
+ (error "Not in an item")))
-(defun org-end-of-item-or-at-child ()
- "Move to the end of the item text, stops before the first child if any."
- (let ((limit (org-list-bottom-point)))
- (end-of-line)
- (goto-char
- (if (org-search-forward-unenclosed org-item-beginning-re limit t)
- (point-at-bol)
- limit))))
+(defun org-get-end-of-list (bottom)
+ "Return position at the end of the current list or sublist.
+BOTTOM is the position at list ending."
+ (save-excursion
+ (goto-char (org-get-item-beginning))
+ (let ((ind (org-get-indentation)))
+ (while (and (/= (point) bottom)
+ (>= (org-get-indentation) ind))
+ (org-search-forward-unenclosed org-item-beginning-re bottom 'move))
+ (if (= (point) bottom) bottom (point-at-bol)))))
-(defun org-end-of-item-before-blank ()
+(defun org-end-of-item-list ()
+ "Go to the end of the current list or sublist.
+If the cursor in not in an item, throw an error."
+ (interactive)
+ (if (org-in-item-p)
+ (goto-char (org-get-end-of-list (org-list-bottom-point)))
+ (error "Not in an item")))
+
+(defun org-get-end-of-item (bottom)
+ "Return position at the end of the current item.
+BOTTOM is the position at list ending."
+ (let* ((next-p (org-get-next-item (point) bottom)))
+ (or next-p (org-get-end-of-list bottom))))
+
+(defun org-end-of-item ()
+ "Go to the end of the current hand-formatted item.
+If the cursor is not in an item, throw an error."
+ (interactive)
+ (if (org-in-item-p)
+ (goto-char (org-get-end-of-item (org-list-bottom-point)))
+ (error "Not in an item")))
+
+(defun org-end-of-item-or-at-child (bottom)
+ "Move to the end of the item, stops before the first child if any.
+BOTTOM is the position at list ending."
+ (end-of-line)
+ (goto-char
+ (if (org-search-forward-unenclosed org-item-beginning-re bottom t)
+ (point-at-bol)
+ (org-get-end-of-item bottom))))
+
+(defun org-end-of-item-before-blank (bottom)
"Return point at end of item, before any blank line.
-Point returned is at eol."
+Point returned is at eol.
+
+BOTTOM is the position at list ending."
(save-excursion
- (org-end-of-item)
+ (goto-char (org-get-end-of-item bottom))
(skip-chars-backward " \r\t\n")
(point-at-eol)))
-(defun org-get-next-item (pos limit)
- "Get the point of the next item at the same level as POS.
-Stop searching at LIMIT. Return nil if no item is found. This
-function does not move point."
- (org-list-get-item-same-level
- #'org-search-forward-unenclosed pos limit #'end-of-line))
-
(defun org-get-previous-item (pos limit)
- "Get the point of the previous item at the same level as POS.
-Stop searching at LIMIT. Return nil if no item is found. This
-function does not move point."
+ "Return point of the previous item at the same level as POS.
+Stop searching at LIMIT. Return nil if no item is found."
(org-list-get-item-same-level
#'org-search-backward-unenclosed pos limit #'beginning-of-line))
-(defun org-next-item ()
- "Move to the beginning of the next item.
-
-Item is at the same level in the current plain list. Error if not
-in a plain list, or if this is the last item in the list."
- (interactive)
- (let ((next-p (org-get-next-item (point) (org-list-bottom-point))))
- (if next-p (goto-char next-p) (error "On last item"))))
-
(defun org-previous-item ()
"Move to the beginning of the previous item.
Item is at the same level in the current plain list. Error if not
in a plain list, or if this is the first item in the list."
(interactive)
- (let ((prev-p (org-get-previous-item (point) (org-list-top-point))))
- (if prev-p (goto-char prev-p) (error "On first item"))))
+ (if (not (org-in-item-p))
+ (error "Not in an item")
+ (let ((prev-p (org-get-previous-item (point) (org-list-top-point))))
+ (if prev-p (goto-char prev-p) (error "On first item")))))
-(defun org-beginning-of-item-list ()
- "Go to the beginning item of the current list or sublist.
-Return point."
- (interactive)
- (let ((limit (org-list-top-point))
- prev-p)
- (while (setq prev-p (org-get-previous-item (point) limit))
- (goto-char prev-p))
- (goto-char (point-at-bol))))
+(defun org-get-next-item (pos limit)
+ "Return point of the next item at the same level as POS.
+Stop searching at LIMIT. Return nil if no item is found."
+ (org-list-get-item-same-level
+ #'org-search-forward-unenclosed pos limit #'end-of-line))
-(defun org-end-of-item-list ()
- "Go to the end of the current list or sublist.
-Return point."
+(defun org-next-item ()
+ "Move to the beginning of the next item.
+
+Item is at the same level in the current plain list. Error if not
+in a plain list, or if this is the last item in the list."
(interactive)
- (org-beginning-of-item)
- (let ((limit (org-list-bottom-point))
- (ind (org-get-indentation)))
- (while (and (/= (point) limit)
- (>= (org-get-indentation) ind))
- (org-search-forward-unenclosed org-item-beginning-re limit 'move))
- (if (= (point) limit) limit (goto-char (point-at-bol)))))
+ (if (not (org-in-item-p))
+ (error "Not in an item")
+ (let ((next-p (org-get-next-item (point) (org-list-bottom-point))))
+ (if next-p (goto-char next-p) (error "On last item")))))
;;; Manipulate
-(defun org-list-exchange-items (beg-A beg-B)
+(defun org-list-exchange-items (beg-A beg-B bottom)
"Swap item starting at BEG-A with item starting at BEG-B.
-Blank lines at the end of items are left in place. Assumes BEG-A
-is lesser than BEG-B."
+Blank lines at the end of items are left in place. Assume BEG-A
+is lesser than BEG-B.
+
+BOTTOM is the position at list ending."
(save-excursion
- (let* ((end-of-item-no-blank (lambda (pos)
- (goto-char pos)
- (goto-char (org-end-of-item-before-blank))))
+ (let* ((end-of-item-no-blank
+ (lambda (pos)
+ (goto-char pos)
+ (goto-char (org-end-of-item-before-blank bottom))))
(end-A-no-blank (funcall end-of-item-no-blank beg-A))
(end-B-no-blank (funcall end-of-item-no-blank beg-B))
(body-A (buffer-substring beg-A end-A-no-blank))
@@ -1010,18 +1050,21 @@ is lesser than BEG-B."
Subitems (items with larger indentation) are considered part of the item,
so this really moves item trees."
(interactive)
- (let ((pos (point))
- (col (current-column))
- (actual-item (org-beginning-of-item))
- (next-item (org-get-next-item (point) (org-list-bottom-point))))
- (if (not next-item)
- (progn
- (goto-char pos)
- (error "Cannot move this item further down"))
- (org-list-exchange-items actual-item next-item)
- (org-list-repair)
- (org-next-item)
- (move-to-column col))))
+ (if (not (org-at-item-p))
+ (error "Not at an item")
+ (let* ((pos (point))
+ (col (current-column))
+ (bottom (org-list-bottom-point))
+ (actual-item (goto-char (org-get-item-beginning)))
+ (next-item (org-get-next-item (point) bottom)))
+ (if (not next-item)
+ (progn
+ (goto-char pos)
+ (error "Cannot move this item further down"))
+ (org-list-exchange-items actual-item next-item bottom)
+ (org-list-repair nil nil bottom)
+ (goto-char (org-get-next-item (point) bottom))
+ (move-to-column col)))))
(defun org-move-item-up ()
"Move the plain list item at point up, i.e. swap with previous item.
@@ -1029,17 +1072,21 @@ so this really moves item trees."
Subitems (items with larger indentation) are considered part of the item,
so this really moves item trees."
(interactive)
- (let ((pos (point))
- (col (current-column))
- (actual-item (org-beginning-of-item))
- (prev-item (org-get-previous-item (point) (org-list-top-point))))
- (if (not prev-item)
- (progn
- (goto-char pos)
- (error "Cannot move this item further up"))
- (org-list-exchange-items prev-item actual-item)
- (org-list-repair)
- (move-to-column col))))
+ (if (not (org-at-item-p))
+ (error "Not at an item")
+ (let* ((pos (point))
+ (col (current-column))
+ (top (org-list-top-point))
+ (bottom (org-list-bottom-point))
+ (actual-item (goto-char (org-get-item-beginning)))
+ (prev-item (org-get-previous-item (point) top)))
+ (if (not prev-item)
+ (progn
+ (goto-char pos)
+ (error "Cannot move this item further up"))
+ (org-list-exchange-items prev-item actual-item bottom)
+ (org-list-repair nil top bottom)
+ (move-to-column col)))))
(defun org-insert-item (&optional checkbox)
"Insert a new item at the current level.
@@ -1054,13 +1101,13 @@ item is invisible."
(unless (or (not (org-in-item-p))
(org-invisible-p))
(if (save-excursion
- (org-beginning-of-item)
+ (goto-char (org-get-item-beginning))
(org-at-item-timer-p))
;; Timer list: delegate to `org-timer-item'.
(progn (org-timer-item) t)
;; if we're in a description list, ask for the new term.
(let ((desc-text (when (save-excursion
- (and (org-beginning-of-item)
+ (and (goto-char (org-get-item-beginning))
(org-at-item-description-p)))
(concat (read-string "Term: ") " :: "))))
;; Don't insert a checkbox if checkbox rule is applied and it
@@ -1077,11 +1124,11 @@ item is invisible."
;; buffer on costly operations like indenting or fixing bullets.
;; It achieves this by taking a snapshot of an interesting part of the
-;; list, in the shape of an alist, with `org-list-struct'.
+;; list, in the shape of an alist, using `org-list-struct'.
-;; It then proceeds to changes directly on the alist. When those are
-;; done, `org-list-struct-apply-struct' applies the changes in the
-;; buffer.
+;; It then proceeds to changes directly on the alist, with the help of
+;; and `org-list-struct-origins'. When those are done,
+;; `org-list-struct-apply-struct' applies the changes to the buffer.
(defun org-list-struct-assoc-at-point ()
"Return the structure association at point.
@@ -1099,7 +1146,7 @@ bullet string and bullet counter, if any."
(and (looking-at "\\[@\\(?:start:\\)?\\([0-9]+\\)\\]")
(match-string 1))))))
-(defun org-list-struct (begin end &optional outdent limit-up limit-down)
+(defun org-list-struct (begin end top bottom &optional outdent)
"Return the structure containing the list between BEGIN and END.
A structure is an alist where key is point of item and values
@@ -1109,17 +1156,14 @@ has items between BEGIN and END along with their common ancestor.
If no such ancestor can be found, the function will add a virtual
ancestor at position 0.
+TOP and BOTTOM are respectively the position of list beginning
+and list ending.
+
If OUTDENT is non-nil, it will also grab all of the parent list
and the grand-parent. Setting OUTDENT to t is mandatory when next
-change is an outdent.
-
-Numbers LIMIT-UP and LIMIT-DOWN are the maximal positions the
-structure can extend to. They default respectively to list's top
-point and bottom point."
+change is an outdent."
(save-excursion
- (let* ((top (or limit-up (org-list-top-point)))
- (bottom (or limit-down (org-list-bottom-point)))
- struct
+ (let* (struct
(extend
(lambda (struct)
(let* ((ind-min (apply 'min (mapcar 'cadr struct)))
@@ -1380,8 +1424,11 @@ END."
(cdr (assq prev acc)))))))))))))
(mapcar ind origins)))
-(defun org-list-struct-apply-struct (struct)
+(defun org-list-struct-apply-struct (struct bottom)
"Apply modifications to list so it mirrors STRUCT.
+
+BOTTOM is position at list ending.
+
Initial position is restored after the changes."
(let* ((pos (copy-marker (point)))
(ancestor (caar struct))
@@ -1398,7 +1445,8 @@ Initial position is restored after the changes."
(new-body-ind (+ (length new-bul) new-ind)))
;; 1. Shift item's body
(unless (= old-body-ind new-body-ind)
- (org-shift-item-indentation (- new-body-ind old-body-ind)))
+ (org-shift-item-indentation
+ (- new-body-ind old-body-ind) bottom))
;; 2. Replace bullet
(unless (equal new-bul old-bul)
(save-excursion
@@ -1432,12 +1480,14 @@ Initial position is restored after the changes."
(t (throw 'exit t)))))
i))
-(defun org-shift-item-indentation (delta)
+(defun org-shift-item-indentation (delta bottom)
"Shift the indentation in current item by DELTA.
-Sub-items are not moved."
+Sub-items are not moved.
+
+BOTTOM is position at list ending."
(save-excursion
(let ((beg (point-at-bol))
- (end (org-end-of-item-or-at-child)))
+ (end (org-end-of-item-or-at-child bottom)))
(beginning-of-line (unless (eolp) 0))
(while (> (point) beg)
(when (looking-at "[ \t]*\\S-")
@@ -1448,24 +1498,36 @@ Sub-items are not moved."
(beginning-of-line 0)))))
(defun org-outdent-item ()
- "Outdent a local list item, but not its children."
+ "Outdent a local list item, but not its children.
+
+If a region is active, all items inside will be moved."
(interactive)
- (org-list-indent-item-generic -1 t))
+ (org-list-indent-item-generic
+ -1 t (org-list-top-point) (org-list-bottom-point)))
(defun org-indent-item ()
- "Indent a local list item, but not its children."
+ "Indent a local list item, but not its children.
+
+If a region is active, all items inside will be moved."
(interactive)
- (org-list-indent-item-generic 1 t))
+ (org-list-indent-item-generic
+ 1 t (org-list-top-point) (org-list-bottom-point)))
(defun org-outdent-item-tree ()
- "Outdent a local list item including its children."
+ "Outdent a local list item including its children.
+
+If a region is active, all items inside will be moved."
(interactive)
- (org-list-indent-item-generic -1 nil))
+ (org-list-indent-item-generic
+ -1 nil (org-list-top-point) (org-list-bottom-point)))
(defun org-indent-item-tree ()
- "Indent a local list item including its children."
+ "Indent a local list item including its children.
+
+If a region is active, all items inside will be moved."
(interactive)
- (org-list-indent-item-generic 1 nil))
+ (org-list-indent-item-generic
+ 1 nil (org-list-top-point) (org-list-bottom-point)))
(defvar org-tab-ind-state)
(defun org-cycle-item-indentation ()
@@ -1475,40 +1537,42 @@ The first run indent the item, if applicable. Subsequents runs
outdent it at meaningful levels in the list. When done, item is
put back at its original position with its original bullet.
-Return t at each successful move.
-
-The item must be empty."
- (let ((org-adapt-indentation nil))
+Return t at each successful move."
+ (let ((org-adapt-indentation nil)
+ (ind (org-get-indentation))
+ (bottom (and (org-at-item-p) (org-list-bottom-point))))
(when (and (or (org-at-item-description-p)
(org-at-item-checkbox-p)
(org-at-item-p))
+ ;; Check that item is really empty
(>= (match-end 0) (save-excursion
- (org-end-of-item-or-at-child)
+ (org-end-of-item-or-at-child bottom)
(skip-chars-backward " \r\t\n")
(point))))
(setq this-command 'org-cycle-item-indentation)
- ;; When in the middle of the cycle, try to outdent first. If it
- ;; fails, and point is still at initial position, indent. Else,
- ;; go back to original position.
- (if (eq last-command 'org-cycle-item-indentation)
+ (let ((top (org-list-top-point)))
+ ;; When in the middle of the cycle, try to outdent first. If it
+ ;; fails, and point is still at initial position, indent. Else,
+ ;; go back to original position.
+ (if (eq last-command 'org-cycle-item-indentation)
+ (cond
+ ((ignore-errors (org-list-indent-item-generic -1 t top bottom)))
+ ((and (= (org-get-indentation) (car org-tab-ind-state))
+ (ignore-errors
+ (org-list-indent-item-generic 1 t top bottom))))
+ (t (back-to-indentation)
+ (indent-to-column (car org-tab-ind-state))
+ (end-of-line)
+ (org-list-repair (cdr org-tab-ind-state))
+ ;; Break cycle
+ (setq this-command 'identity)))
+ ;; If a cycle is starting, remember indentation and bullet,
+ ;; then try to indent. If it fails, try to outdent.
+ (setq org-tab-ind-state (cons ind (org-get-bullet)))
(cond
- ((ignore-errors (org-outdent-item)))
- ((and (= (org-get-indentation) (car org-tab-ind-state))
- (ignore-errors (org-indent-item))))
- (t (back-to-indentation)
- (indent-to-column (car org-tab-ind-state))
- (end-of-line)
- (org-list-repair (cdr org-tab-ind-state))
- ;; Break cycle
- (setq this-command 'identity)))
- ;; If a cycle is starting, remember indentation and bullet,
- ;; then try to indent. If it fails, try to outdent.
- (setq org-tab-ind-state
- (cons (org-get-indentation) (org-get-bullet)))
- (cond
- ((ignore-errors (org-indent-item)))
- ((ignore-errors (org-outdent-item)))
- (t (error "Cannot move item"))))
+ ((ignore-errors (org-list-indent-item-generic 1 t top bottom)))
+ ((ignore-errors (org-list-indent-item-generic -1 t top bottom)))
+ (t (error "Cannot move item")))))
t)))
;;; Bullets
@@ -1544,17 +1608,23 @@ It determines the number of whitespaces to append by looking at
nil nil bullet)
bullet))
-(defun org-list-repair (&optional force-bullet)
+(defun org-list-repair (&optional force-bullet top bottom)
"Make sure all items are correctly indented, with the right bullet.
This function scans the list at point, along with any sublist.
If FORCE-BULLET is a string, ensure all items in list share this
bullet, or a logical successor in the case of an ordered list.
+When non-nil, TOP and BOTTOM specify respectively position of
+list beginning and list ending.
+
Item's body is not indented, only shifted with the bullet."
(interactive)
(unless (org-at-item-p) (error "This is not a list"))
- (let* ((struct (org-list-struct (point-at-bol) (point-at-eol)))
+ (let* ((bottom (or bottom (org-list-bottom-point)))
+ (struct (org-list-struct
+ (point-at-bol) (point-at-eol)
+ (or top (org-list-top-point)) bottom))
(origins (org-list-struct-origins struct))
fixed-struct)
(if (stringp force-bullet)
@@ -1565,7 +1635,7 @@ Item's body is not indented, only shifted with the bullet."
(setq fixed-struct
(cons begin (org-list-struct-fix-struct struct origins))))
(setq fixed-struct (org-list-struct-fix-struct struct origins)))
- (org-list-struct-apply-struct fixed-struct)))
+ (org-list-struct-apply-struct fixed-struct bottom)))
(defun org-cycle-list-bullet (&optional which)
"Cycle through the different itemize/enumerate bullets.
@@ -1577,34 +1647,35 @@ If WHICH is a valid string, use that as the new bullet. If WHICH
is an integer, 0 means `-', 1 means `+' etc. If WHICH is
'previous, cycle backwards."
(interactive "P")
- (org-preserve-lc
- (let* ((bullet (progn (org-beginning-of-item-list)
- (org-get-bullet)))
- (current (cond
- ((string-match "\\." bullet) "1.")
- ((string-match ")" bullet) "1)")
- (t bullet)))
- (bullet-rule-p (cdr (assq 'bullet org-list-automatic-rules)))
- (bullet-list (append '("-" "+" )
- ;; *-bullets are not allowed at column 0
- (unless (and bullet-rule-p
- (looking-at "\\S-")) '("*"))
- ;; Description items cannot be numbered
- (unless (and bullet-rule-p
- (or (eq org-plain-list-ordered-item-terminator ?.)
- (org-at-item-description-p))) '("1)"))
- (unless (and bullet-rule-p
- (or (eq org-plain-list-ordered-item-terminator ?\))
- (org-at-item-description-p))) '("1."))))
- (len (length bullet-list))
- (item-index (- len (length (member current bullet-list))))
- (get-value (lambda (index) (nth (mod index len) bullet-list)))
- (new (cond
- ((member which bullet-list) which)
- ((numberp which) (funcall get-value which))
- ((eq 'previous which) (funcall get-value (1- item-index)))
- (t (funcall get-value (1+ item-index))))))
- (org-list-repair new))))
+ (let* ((top (org-list-top-point))
+ (bullet (save-excursion
+ (goto-char (org-get-beginning-of-list top))
+ (org-get-bullet)))
+ (current (cond
+ ((string-match "\\." bullet) "1.")
+ ((string-match ")" bullet) "1)")
+ (t bullet)))
+ (bullet-rule-p (cdr (assq 'bullet org-list-automatic-rules)))
+ (bullet-list (append '("-" "+" )
+ ;; *-bullets are not allowed at column 0
+ (unless (and bullet-rule-p
+ (looking-at "\\S-")) '("*"))
+ ;; Description items cannot be numbered
+ (unless (and bullet-rule-p
+ (or (eq org-plain-list-ordered-item-terminator ?.)
+ (org-at-item-description-p))) '("1)"))
+ (unless (and bullet-rule-p
+ (or (eq org-plain-list-ordered-item-terminator ?\))
+ (org-at-item-description-p))) '("1."))))
+ (len (length bullet-list))
+ (item-index (- len (length (member current bullet-list))))
+ (get-value (lambda (index) (nth (mod index len) bullet-list)))
+ (new (cond
+ ((member which bullet-list) which)
+ ((numberp which) (funcall get-value which))
+ ((eq 'previous which) (funcall get-value (1- item-index)))
+ (t (funcall get-value (1+ item-index))))))
+ (org-list-repair new top)))
;;; Checkboxes
@@ -1768,7 +1839,7 @@ the whole buffer."
(goto-char startsearch)
(if (org-search-forward-unenclosed re-box lim t)
(progn
- (org-beginning-of-item)
+ (goto-char (org-get-item-beginning))
(setq curr-ind (org-get-indentation))
(setq next-ind curr-ind)
(while (and (bolp) (org-at-item-p)
@@ -1801,7 +1872,7 @@ the whole buffer."
(delete-region (point) (+ (point) (- end-cookie beg-cookie))))
;; update items checkbox if it has one
(when (org-at-item-p)
- (org-beginning-of-item)
+ (goto-char (org-get-item-beginning))
(when (and (> (+ c-on c-off) 0)
(org-search-forward-unenclosed re-box (point-at-eol) t))
(setq beg-cookie (match-beginning 2)
@@ -1846,7 +1917,7 @@ Sublists of the list are skipped. Cursor is always at the
beginning of the item."
(let* ((pos (copy-marker (point)))
(end (copy-marker (org-list-bottom-point)))
- (next-p (copy-marker (save-excursion (org-beginning-of-item-list))))
+ (next-p (copy-marker (org-get-beginning-of-list (org-list-top-point))))
(value init-value))
(while (< next-p end)
(goto-char next-p)
@@ -1885,8 +1956,10 @@ the sorting key for that record. It will then use COMPARE-FUNC to
compare entries."
(interactive "P")
(let* ((case-func (if with-case 'identity 'downcase))
- (start (org-beginning-of-item-list))
- (end (save-excursion (org-end-of-item-list)))
+ (top (org-list-top-point))
+ (bottom (org-list-bottom-point))
+ (start (org-get-beginning-of-list top))
+ (end (org-get-end-of-list bottom))
(sorting-type
(progn
(message
@@ -1911,7 +1984,7 @@ compare entries."
(skip-chars-forward " \r\t\n")
(beginning-of-line)))
(end-record (lambda ()
- (goto-char (org-end-of-item-before-blank))))
+ (goto-char (org-end-of-item-before-blank end))))
(value-to-sort
(lambda ()
(when (looking-at "[ \t]*[-+*0-9.)]+\\([ \t]+\\[[- X]\\]\\)?[ \t]+")
@@ -1946,7 +2019,7 @@ compare entries."
value-to-sort
nil
sort-func)
- (org-list-repair)
+ (org-list-repair nil top bottom)
(run-hooks 'org-after-sorting-entries-or-items-hook)
(message "Sorting items...done")))))
@@ -1968,7 +2041,7 @@ sublevels as a list of strings."
(let* ((indent1 (org-get-indentation))
(nextitem (or (org-get-next-item (point) end) end))
(item (org-trim (buffer-substring (point)
- (org-end-of-item-or-at-child))))
+ (org-end-of-item-or-at-child end))))
(nextindent (if (= (point) end) 0 (org-get-indentation)))
(item (if (string-match
"^\\(?:\\[@\\(?:start:\\)?[0-9]+\\][ \t]*\\)?\\[\\([xX ]\\)\\]"
@@ -2039,7 +2112,7 @@ With argument MAYBE, fail quietly if no transformation is defined for
this list."
(interactive)
(catch 'exit
- (unless (org-at-item-p) (error "Not at a list"))
+ (unless (org-at-item-p) (error "Not at a list item"))
(save-excursion
(re-search-backward "#\\+ORGLST" nil t)
(unless (looking-at "[ \t]*#\\+ORGLST[: \t][ \t]*SEND[ \t]+\\([^ \t\r\n]+\\)[ \t]+\\([^ \t\r\n]+\\)\\([ \t]+.*\\)?")