[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] Getting beginning postiion of a description list
From: |
Eric Abrahamsen |
Subject: |
Re: [O] Getting beginning postiion of a description list |
Date: |
Fri, 16 Jan 2015 18:57:01 +0800 |
User-agent: |
Gnus/5.130012 (Ma Gnus v0.12) Emacs/25.0.50 (gnu/linux) |
Nicolas Richard <address@hidden> writes:
> Calvin Young <address@hidden> writes:
>> How do I need to massage this to give me the beginning of the whole
>> list item? Is there a recommended solution that'd work for both
>> description lists *and* plain lists?
>
> This seems to work for me:
>
> (defun yf/org-beginning-of-item ()
> (let ((element (org-element-at-point)))
> ;; 'plain-list is returned when at the beginning of the first item in the
> list.
> (when (eq 'plain-list (org-element-type element))
> (save-excursion
> (forward-char)
> (setq element (org-element-at-point))))
> ;; look ancestors to find an 'item element.
> (while (and element
> (not
> (eq 'item
> (org-element-type element))))
> (setq element (org-element-property :parent element)))
> (if (not element)
> (error "Not in a list item")
> (goto-char
> (+ (length (org-element-property :bullet element))
> (org-element-property :begin element))))))
>
> Probably one could use the list API directly (from org-list.el) too.
Indeed, I'd definitely go for the org-list stuff. It's a bit confusing
at first, because it isn't like any of the other org code, but it works
well. Try calling `org-list-struct' on a list; that will probably give
you most of what you need.