emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Getting beginning postiion of a description list
@ 2015-01-15  4:28 Calvin Young
  2015-01-16  2:31 ` John Kitchin
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Calvin Young @ 2015-01-15  4:28 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 704 bytes --]

Hi all,

If my cursor is in a description list item, what's the recommended way of
getting the point at the beginning of the description list text (i.e.,
after the bullet character)? To illustrate, given the following description
list item, I'd like to get the point represented by the pipe character "|":

- |foo :: bar

If I use something like `(org-element-property :contents-begin
(org-element-at-point))`, that gives me the point at the beginning of the
description, not the list item:

- foo :: |bar

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?

Thanks everyone :)

Calvin

[-- Attachment #2: Type: text/html, Size: 924 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Getting beginning postiion of a description list
  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
  2015-01-16 10:58 ` Nicolas Goaziou
  2 siblings, 1 reply; 6+ messages in thread
From: John Kitchin @ 2015-01-16  2:31 UTC (permalink / raw)
  To: Calvin Young; +Cc: emacs-orgmode

This is very un-orgish but it seems to do it. (forward-word) goes to the
end the next recognized word, (backward-word) to the beginning of the
word you are now at the end of, and (backward-char) to get to a
space. You just need org to get you on the list ;)

It seems to work on these.

- foo :: bar    (goto-char (org-element-property :contents-begin (org-element-at-point)))
-     baz :: goo
- 1 egg
- 0.5 cups
- :punc

#+BEGIN_SRC emacs-lisp
(defun gg ()
 (interactive)
 (beginning-of-line)
 (forward-word)
 (backward-word)
 (while (not (looking-at " "))
   (backward-char)))
#+END_SRC


Calvin Young writes:

> Hi all,
>
> If my cursor is in a description list item, what's the recommended way of
> getting the point at the beginning of the description list text (i.e.,
> after the bullet character)? To illustrate, given the following description
> list item, I'd like to get the point represented by the pipe character "|":
>
> - |foo :: bar
>
> If I use something like `(org-element-property :contents-begin
> (org-element-at-point))`, that gives me the point at the beginning of the
> description, not the list item:
>
> - foo :: |bar
>
> 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?
>
> Thanks everyone :)
>
> Calvin

--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Getting beginning postiion of a description list
  2015-01-16  2:31 ` John Kitchin
@ 2015-01-16  5:47   ` Calvin Young
  0 siblings, 0 replies; 6+ messages in thread
From: Calvin Young @ 2015-01-16  5:47 UTC (permalink / raw)
  To: John Kitchin; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 2131 bytes --]

Ah, this makes sense. Unfortunately, an additional constraint I failed to
mention in the first email is that it'd be nice if the solution worked for
numbered lists as well. That solution unfortunately breaks on numbered
lists :(

Is there perhaps another way to accomplish this?

P.S. I just noticed the typo in "position" in the subject of this
thread...apols, how very embarrassing of me.

On Thu, Jan 15, 2015 at 6:31 PM, John Kitchin <johnrkitchin@gmail.com>
wrote:

> This is very un-orgish but it seems to do it. (forward-word) goes to the
> end the next recognized word, (backward-word) to the beginning of the
> word you are now at the end of, and (backward-char) to get to a
> space. You just need org to get you on the list ;)
>
> It seems to work on these.
>
> - foo :: bar    (goto-char (org-element-property :contents-begin
> (org-element-at-point)))
> -     baz :: goo
> - 1 egg
> - 0.5 cups
> - :punc
>
> #+BEGIN_SRC emacs-lisp
> (defun gg ()
>  (interactive)
>  (beginning-of-line)
>  (forward-word)
>  (backward-word)
>  (while (not (looking-at " "))
>    (backward-char)))
> #+END_SRC
>
>
> Calvin Young writes:
>
> > Hi all,
> >
> > If my cursor is in a description list item, what's the recommended way of
> > getting the point at the beginning of the description list text (i.e.,
> > after the bullet character)? To illustrate, given the following
> description
> > list item, I'd like to get the point represented by the pipe character
> "|":
> >
> > - |foo :: bar
> >
> > If I use something like `(org-element-property :contents-begin
> > (org-element-at-point))`, that gives me the point at the beginning of the
> > description, not the list item:
> >
> > - foo :: |bar
> >
> > 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?
> >
> > Thanks everyone :)
> >
> > Calvin
>
> --
> Professor John Kitchin
> Doherty Hall A207F
> Department of Chemical Engineering
> Carnegie Mellon University
> Pittsburgh, PA 15213
> 412-268-7803
> @johnkitchin
> http://kitchingroup.cheme.cmu.edu
>

[-- Attachment #2: Type: text/html, Size: 2910 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Getting beginning postiion of a description list
  2015-01-15  4:28 Getting beginning postiion of a description list Calvin Young
  2015-01-16  2:31 ` John Kitchin
@ 2015-01-16  7:31 ` Nicolas Richard
  2015-01-16 10:57   ` Eric Abrahamsen
  2015-01-16 10:58 ` Nicolas Goaziou
  2 siblings, 1 reply; 6+ messages in thread
From: Nicolas Richard @ 2015-01-16  7:31 UTC (permalink / raw)
  To: Calvin Young; +Cc: emacs-orgmode

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Getting beginning postiion of a description list
  2015-01-16  7:31 ` Nicolas Richard
@ 2015-01-16 10:57   ` Eric Abrahamsen
  0 siblings, 0 replies; 6+ messages in thread
From: Eric Abrahamsen @ 2015-01-16 10:57 UTC (permalink / raw)
  To: emacs-orgmode

Nicolas Richard <theonewiththeevillook@yahoo.fr> writes:

> 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.

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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Getting beginning postiion of a description list
  2015-01-15  4:28 Getting beginning postiion of a description list Calvin Young
  2015-01-16  2:31 ` John Kitchin
  2015-01-16  7:31 ` Nicolas Richard
@ 2015-01-16 10:58 ` Nicolas Goaziou
  2 siblings, 0 replies; 6+ messages in thread
From: Nicolas Goaziou @ 2015-01-16 10:58 UTC (permalink / raw)
  To: Calvin Young; +Cc: emacs-orgmode

Hello,

Calvin Young <calvinwyoung@gmail.com> writes:

> If my cursor is in a description list item, what's the recommended way of
> getting the point at the beginning of the description list text (i.e.,
> after the bullet character)? To illustrate, given the following description
> list item, I'd like to get the point represented by the pipe character "|":
>
> - |foo :: bar
>
> If I use something like `(org-element-property :contents-begin
> (org-element-at-point))`, that gives me the point at the beginning of the
> description, not the list item:
>
> - foo :: |bar
>
> 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?

See `org-special-ctrl-a/e'.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-01-16 10:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2015-01-16 10:57   ` Eric Abrahamsen
2015-01-16 10:58 ` Nicolas Goaziou

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).