forked from mirrors/org-mode
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.
This commit is contained in:
parent
e2c1ec92a4
commit
9230df2e0d
|
@ -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)
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue