From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Abrahamsen Subject: Re: Getting beginning postiion of a description list Date: Fri, 16 Jan 2015 18:57:01 +0800 Message-ID: <877fwnro1u.fsf@ericabrahamsen.net> References: <87ppafgp1i.fsf@yahoo.fr> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:48794) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YC4Ub-0006uD-G9 for emacs-orgmode@gnu.org; Fri, 16 Jan 2015 05:51:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YC4UX-0005aw-D6 for emacs-orgmode@gnu.org; Fri, 16 Jan 2015 05:51:05 -0500 Received: from plane.gmane.org ([80.91.229.3]:34026) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YC4UX-0005ai-67 for emacs-orgmode@gnu.org; Fri, 16 Jan 2015 05:51:01 -0500 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1YC4UT-0001VQ-Ot for emacs-orgmode@gnu.org; Fri, 16 Jan 2015 11:50:59 +0100 Received: from 114.248.28.210 ([114.248.28.210]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 16 Jan 2015 11:50:57 +0100 Received: from eric by 114.248.28.210 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 16 Jan 2015 11:50:57 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Nicolas Richard writes: > Calvin Young 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.