diff options
author | Nicolas Goaziou <n.goaziou@gmail.com> | 2010-12-29 01:43:20 +0100 |
---|---|---|
committer | Nicolas Goaziou <n.goaziou@gmail.com> | 2011-02-18 12:45:08 +0100 |
commit | 14df1d59d4b3ad73dccf34383b6e19680c9f3e53 (patch) | |
tree | 8b6a14fe9c61a8d9abec296876dcfbae5e73223d | |
parent | c12ce921d7127ac86db6406acaa61400bbaf0e4c (diff) | |
download | org-mode-14df1d59d4b3ad73dccf34383b6e19680c9f3e53.tar.gz |
org-list: various fixes to accessors
* org-list.el (org-list-has-child-p): renamed from org-list-get-child.
Returning first child is only useful as a predicate, as we're
allowing an item to have more than one sub-list.
(org-list-indent-item-generic): use `org-list-has-child-p' instead of
org-list-get-child.
(org-in-item-p): also return item beginning when list starts at
context beginning.
(org-list-get-parent): use of `org-list-struct-parent-alist' helper
function is not optional anymore.
(org-list-get-all-items): shorten code with the help of cl.el.
(org-list-get-children): now returns all children of item, even if
they do not belong to the same list. Renamed from
org-list-get-all-children.
(org-list-get-list-begin): function wasn't return value when item was
already the first item of the list at point.
(org-list-get-list-end): function wasn't return value when item was
already the last item of the list at point.
(org-list-struct-fix-box,org-update-checkbox-count): now uses
`org-list-get-children'.
-rw-r--r-- | lisp/org-list.el | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/lisp/org-list.el b/lisp/org-list.el index 22aedd8..c62319c 100644 --- a/lisp/org-list.el +++ b/lisp/org-list.el @@ -720,7 +720,7 @@ Return t if successful." ;; If only one item is moved, it mustn't have a child (or (and no-subtree (not regionp) - (org-list-get-child beg struct)) + (org-list-has-child-p beg struct)) ;; If a subtree or region is moved, the last item ;; of the subtree mustn't have a child (let ((last-item (caar @@ -728,7 +728,7 @@ Return t if successful." (org-remove-if (lambda (e) (>= (car e) end)) struct))))) - (org-list-get-child last-item struct)))) + (org-list-has-child-p last-item struct)))) (error "Cannot outdent an item without its children")) ;; Normal shifting (t @@ -765,7 +765,7 @@ This checks `org-list-ending-method'." (let ((ind (org-get-indentation))) (cond ((<= (point) lim-up) - (throw 'exit (and (org-at-item-p) (< ind ind-ref)))) + (throw 'exit (and (org-at-item-p) (< ind ind-ref) (point)))) ((and (not (eq org-list-ending-method 'indent)) (looking-at (org-list-end-re))) (throw 'exit nil)) @@ -1288,15 +1288,16 @@ This function modifies STRUCT." (t (cons pos (cdar ind-to-ori)))))) (cdr struct))))) -(defun org-list-get-parent (item struct &optional parents) +(defun org-list-get-parent (item struct parents) "Return parent of ITEM in STRUCT, or nil. -PARENTS, when provided, is the alist of items' parent. See +PARENTS is the alist of items' parent. See `org-list-struct-parent-alist'." (let ((parents (or parents (org-list-struct-parent-alist struct)))) (cdr (assq item parents)))) -(defun org-list-get-child (item struct) - "Return child of ITEM in STRUCT, or nil." +(defun org-list-has-child-p (item struct) + "Return a non-nil value if ITEM in STRUCT has a child. +The value returned is the position of the first child of ITEM." (let ((ind (org-list-get-ind item struct)) (child-maybe (car (nth 1 (member (assq item struct) struct))))) (when (and child-maybe @@ -1338,17 +1339,20 @@ PREVS, when provided, is the alist of previous items. See (next-item item) before-item after-item) (while (setq prev-item (org-list-get-prev-item prev-item struct prevs)) - (setq before-item (cons prev-item before-item))) + (push prev-item before-item)) (while (setq next-item (org-list-get-next-item next-item struct prevs)) - (setq after-item (cons next-item after-item))) + (push next-item after-item)) (append before-item (list item) (nreverse after-item)))) -(defun org-list-get-all-children (item struct prevs) +(defun org-list-get-children (item struct parents) "List all children of ITEM in STRUCT, or nil. -PREVS is the alist of previous items. See -`org-list-struct-prev-alist'." - (let ((child (org-list-get-child item struct))) - (and child (org-list-get-all-items child struct prevs)))) +PARENTS is the alist of items' parent. See +`org-list-struct-parent-alist'." + (let (all) + (while (setq child (car (rassq item parents))) + (setq parents (cdr (member (assq child parents) parents)) + all (cons child all))) + (nreverse all))) (defun org-list-get-top-point (struct) "Return point at beginning of list. @@ -1365,8 +1369,8 @@ STRUCT is the structure of the list." "Return point at beginning of sub-list ITEM belongs. STRUCT is the structure of the list. PREVS is the alist of previous items. See `org-list-struct-prev-alist'." - (let ((prev-item item) first-item) - (while (setq prev-item (org-list-get-prev-item prev-item struct prevs)) + (let ((first-item item) prev-item) + (while (setq prev-item (org-list-get-prev-item first-item struct prevs)) (setq first-item prev-item)) first-item)) @@ -1374,8 +1378,8 @@ previous items. See `org-list-struct-prev-alist'." "Return point at end of sub-list ITEM belongs. STRUCT is the structure of the list. PREVS is the alist of previous items. See `org-list-struct-prev-alist'." - (let ((next-item item) last-item) - (while (setq next-item (org-list-get-next-item next-item struct prevs)) + (let ((last-item item) next-item) + (while (setq next-item (org-list-get-next-item last-item struct prevs)) (setq last-item next-item)) (org-list-get-item-end last-item struct))) @@ -1495,7 +1499,7 @@ This function modifies STRUCT." (let* ((box-list (mapcar (lambda (child) (org-list-get-checkbox child struct)) - (org-list-get-all-children item struct prevs)))) + (org-list-get-children item struct parents)))) (org-list-set-checkbox item struct (cond @@ -2117,11 +2121,12 @@ With optional prefix argument ALL, do this for the whole buffer." (mapc (lambda (s) (let* ((pre (org-list-struct-prev-alist s)) + (par (org-list-struct-parent-alist s)) (items (if recursivep (or (and item (org-list-get-subtree item s)) (mapcar 'car s)) - (or (and item (org-list-get-all-children item s pre)) + (or (and item (org-list-get-children item s par)) (org-list-get-all-items (org-list-get-top-point s) s pre)))) (cookies (delq nil (mapcar |