Make `org-apply-to-list' more functional.
* lisp/org-list.el (org-apply-to-list): Now a return value is handed at each new call of the function applied. * lisp/org-list.el (org-fix-bullet-type): Use the new `org-apply-to-list' format. * lisp/org-list.el (org-renumber-ordered-list): Use the new `org-apply-to-list' format.
This commit is contained in:
parent
fb5cab814e
commit
ecd5a4b0f1
|
@ -874,7 +874,7 @@ Also, fix the indentation."
|
||||||
(string-match org-list-two-spaces-after-bullet-regexp bullet))
|
(string-match org-list-two-spaces-after-bullet-regexp bullet))
|
||||||
" "))))
|
" "))))
|
||||||
(replace-bullet
|
(replace-bullet
|
||||||
(lambda (counter bullet)
|
(lambda (result bullet)
|
||||||
(let* ((old (progn
|
(let* ((old (progn
|
||||||
(skip-chars-forward " \t")
|
(skip-chars-forward " \t")
|
||||||
(looking-at "\\S-+ *")
|
(looking-at "\\S-+ *")
|
||||||
|
@ -884,7 +884,7 @@ Also, fix the indentation."
|
||||||
;; when bullet lengths are differents, move the whole
|
;; when bullet lengths are differents, move the whole
|
||||||
;; sublist accordingly
|
;; sublist accordingly
|
||||||
(org-shift-item-indentation (- (length bullet) (length old))))))))
|
(org-shift-item-indentation (- (length bullet) (length old))))))))
|
||||||
(org-apply-on-list replace-bullet bullet)
|
(org-apply-on-list replace-bullet nil bullet)
|
||||||
;; fix item numbers if necessary
|
;; fix item numbers if necessary
|
||||||
(when (string-match "[0-9]" bullet) (org-renumber-ordered-list)))))
|
(when (string-match "[0-9]" bullet) (org-renumber-ordered-list)))))
|
||||||
|
|
||||||
|
@ -919,8 +919,9 @@ with something like \"1.\" or \"2)\". Start to count at ARG or 1."
|
||||||
(insert new)
|
(insert new)
|
||||||
;; In case item number went from 9. to 10.
|
;; In case item number went from 9. to 10.
|
||||||
;; or the other way.
|
;; or the other way.
|
||||||
(org-shift-item-indentation (- (length new) (length old)))))))
|
(org-shift-item-indentation (- (length new) (length old)))
|
||||||
(org-apply-on-list renumber-item offset item-fmt))))
|
(1+ counter)))))
|
||||||
|
(org-apply-on-list renumber-item 0 offset item-fmt))))
|
||||||
|
|
||||||
(defun org-maybe-renumber-ordered-list ()
|
(defun org-maybe-renumber-ordered-list ()
|
||||||
"Renumber the ordered list at point if setup allows it.
|
"Renumber the ordered list at point if setup allows it.
|
||||||
|
@ -1187,25 +1188,31 @@ Otherwise it will be `org-todo'."
|
||||||
|
|
||||||
;;; Misc Tools
|
;;; Misc Tools
|
||||||
|
|
||||||
(defun org-apply-on-list (function &rest args)
|
(defun org-apply-on-list (function init-value &rest args)
|
||||||
"Call FUNCTION for each item of a the list under point.
|
"Call FUNCTION for each item of a the list under point.
|
||||||
|
|
||||||
FUNCTION is called with at least one argument : the number of
|
FUNCTION must be called with at least one argument : a return
|
||||||
items visited, starting at 0, plus ARGS extra arguments.
|
value that will contain the value returned by the function at
|
||||||
|
the previous item, plus ARGS extra arguments. INIT-VALUE will be
|
||||||
|
the value passed to the function at the first item of the list.
|
||||||
|
|
||||||
Sublists of the list are skipped. Cursor is always at the
|
As an example, (org-apply-on-list (lambda (result) (1+ result)) 0)
|
||||||
beginning of the item."
|
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."
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(let ((move-down-action
|
(let ((move-down-action
|
||||||
(lambda (pos item-count &rest args)
|
(lambda (pos value &rest args)
|
||||||
(goto-char pos)
|
(goto-char pos)
|
||||||
(apply function item-count args)
|
(let ((return-value (apply function value args))
|
||||||
;; we need to recompute each time end of list in case
|
;; we need to recompute each time end of list in case
|
||||||
;; function modified list.
|
;; function modified list.
|
||||||
(let ((next-p (org-get-next-item pos (org-end-of-item-list))))
|
(next-p (org-get-next-item pos (org-end-of-item-list))))
|
||||||
(when next-p
|
(if next-p
|
||||||
(apply move-down-action next-p (1+ item-count) args))))))
|
(apply move-down-action next-p return-value args)
|
||||||
(apply move-down-action (org-beginning-of-item-list) 0 args))))
|
return-value)))))
|
||||||
|
(apply move-down-action (org-beginning-of-item-list) init-value args))))
|
||||||
|
|
||||||
(defun org-sort-list (&optional with-case sorting-type getkey-func compare-func)
|
(defun org-sort-list (&optional with-case sorting-type getkey-func compare-func)
|
||||||
"Sort plain list items.
|
"Sort plain list items.
|
||||||
|
|
Loading…
Reference in New Issue