emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Richard <theonewiththeevillook@yahoo.fr>
To: Calvin Young <calvinwyoung@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: Getting beginning postiion of a description list
Date: Fri, 16 Jan 2015 08:31:05 +0100	[thread overview]
Message-ID: <87ppafgp1i.fsf@yahoo.fr> (raw)
In-Reply-To: <CANniJEwZu8UcvbB6G+0Q+e_ZYQNFUsw9DJxxVg9cfKvSnoSQOw@mail.gmail.com> (Calvin Young's message of "Wed, 14 Jan 2015 20:28:52 -0800")

Calvin Young <calvinwyoung@gmail.com> 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.

-- 
Nicolas Richard

  parent reply	other threads:[~2015-01-16  7:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-15  4:28 Getting beginning postiion of a description list Calvin Young
2015-01-16  2:31 ` John Kitchin
2015-01-16  5:47   ` Calvin Young
2015-01-16  7:31 ` Nicolas Richard [this message]
2015-01-16 10:57   ` Eric Abrahamsen
2015-01-16 10:58 ` Nicolas Goaziou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ppafgp1i.fsf@yahoo.fr \
    --to=theonewiththeevillook@yahoo.fr \
    --cc=calvinwyoung@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).