summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2010-12-29 17:58:58 +0100
committerNicolas Goaziou <n.goaziou@gmail.com>2011-02-18 12:45:08 +0100
commit9230df2e0de0b4082ad2fc4bf820c74ca86a8fed (patch)
tree32b86c43ab7ba7d162d0b33aafdc2911821512a3
parente2c1ec92a482f91a96220b33466bb85cf72fedc0 (diff)
downloadorg-mode-9230df2e0de0b4082ad2fc4bf820c74ca86a8fed.tar.gz
org-list: rewrite of org-apply-on-list
* lisp/org-list.el (org-apply-on-list): use new structures. Function is now applied in reverse order so modifications do not change positions of items in buffer.
-rw-r--r--lisp/org-list.el19
-rw-r--r--lisp/org-mouse.el9
2 files changed, 17 insertions, 11 deletions
diff --git a/lisp/org-list.el b/lisp/org-list.el
index 2a73fea..4ab70a9 100644
--- a/lisp/org-list.el
+++ b/lisp/org-list.el
@@ -2223,20 +2223,23 @@ FUNCTION must be called with at least one argument: INIT-VALUE,
that will contain the value returned by the function at the
previous item, plus ARGS extra arguments.
+FUNCTION is applied on items in reverse order.
+
As an example, (org-apply-on-list (lambda (result) (1+ result)) 0)
will return the number of items in the current list.
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 (org-get-beginning-of-list (org-list-top-point))))
+ (let* ((struct (org-list-struct))
+ (prevs (org-list-struct-prev-alist struct))
+ (item (copy-marker (point-at-bol)))
+ (all (org-list-get-all-items (marker-position item) struct prevs))
(value init-value))
- (while (< next-p end)
- (goto-char next-p)
- (set-marker next-p (or (org-get-next-item (point) end) end))
- (setq value (apply function value args)))
- (goto-char pos)
+ (mapc (lambda (e)
+ (goto-char e)
+ (setq value (apply function value args)))
+ (nreverse all))
+ (goto-char item)
value))
(defun org-sort-list (&optional with-case sorting-type getkey-func compare-func)
diff --git a/lisp/org-mouse.el b/lisp/org-mouse.el
index ef0de24..b660435 100644
--- a/lisp/org-mouse.el
+++ b/lisp/org-mouse.el
@@ -579,9 +579,12 @@ SCHEDULED: or DEADLINE: or ANYTHINGLIKETHIS:"
(defun org-mouse-for-each-item (funct)
;; Functions called by `org-apply-on-list' need an argument
- (let ((wrap-fun (lambda (c) (funcall funct))))
- (when (org-in-item-p)
- (org-apply-on-list wrap-fun nil))))
+ (let ((wrap-fun (lambda (c) (funcall funct)))
+ (item-beg (org-in-item-p)))
+ (when item-beg
+ (save-excursion
+ (goto-char item-beg)
+ (org-apply-on-list wrap-fun nil)))))
(defun org-mouse-bolp ()
"Return true if there only spaces, tabs, and '*' before point.