[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Orgmode] Iterate over list with `org-next-item'
From: |
Nick Dokos |
Subject: |
Re: [Orgmode] Iterate over list with `org-next-item' |
Date: |
Thu, 02 Sep 2010 22:28:07 -0400 |
Zachary Young <address@hidden> wrote:
> I am trying to iterate over a list with `org-next-item'. I just tried:
>
> (ignore-errors (while (equal nil (org-next-item))))
>
> and it worked.
>
> Is there a better way to do this? I'm not very versed in Elisp, and
> `org-next-item' returning `nil' on success, and throwing an error at the end
> of the list is throwing me a bit.
>
It's always a good idea to browse the org-mode code itself for examples: after
all it's been written by (or vetted by) the experts, so it should provide a
good foundation.
I found three examples of org-next-item usage, two of which are shown here
(the third one is a bit subtler):
* org.el:
--8<---------------cut here---------------start------------->8---
(defun org-skip-over-state-notes ()
"Skip past the list of State notes in an entry."
(if (looking-at "\n[ \t]*- State") (forward-char 1))
(while (looking-at "[ \t]*- State")
(condition-case nil
(org-next-item)
(error (org-end-of-item)))))
--8<---------------cut here---------------end--------------->8---
* org-mouse.el:
--8<---------------cut here---------------start------------->8---
(defun org-mouse-for-each-item (function)
(save-excursion
(ignore-errors
(while t (org-previous-item)))
(ignore-errors
(while t
(funcall function)
(org-next-item)))))
--8<---------------cut here---------------end--------------->8---
As you can see, the second almost matches what you came up with, but the
condition is simpler: the code *uses* the error raised to get
out of the (otherwise infinite) loop, so there is no need to check
what org-next-item returns.
HTH
Nick