emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Getting the components of an item in a plain-list
@ 2023-06-05 10:18 bvchgvbt
  2023-06-05 14:50 ` Ihor Radchenko
  0 siblings, 1 reply; 2+ messages in thread
From: bvchgvbt @ 2023-06-05 10:18 UTC (permalink / raw)
  To: orgmode ml

If I have a plain-list element that looks something like

    (plain-list (:type unordered :begin 260 :end
    571 :contents-begin 260 :contents-end 571 :structure ((260
    2 "- " nil nil nil 338) (338 2 "- " nil nil nil 413) (413
    2 "- " nil nil nil 489) (489 2 "- " nil nil nil
    571)) :post-blank 0 :post-affiliated 260 :parent nil))

I seem to be able to get the items from the list using

    org-element-property :structure

(per the documentation), giving me:

    ((260 2 "- " nil nil nil 338) (338 2 "- " nil nil nil
    413) (413 2 "- " nil nil nil 489) (489 2 "- " nil nil nil
    571))

and then the first list item using `car`, as I expected:

    (260 2 "- " nil nil nil 338)

But if I try to use org-element-property on that, of course it
fails because it's not an element, as I understand it, rather
it's an object(?).

So how do I get the the beginning and end? I can obviously just
do:

    (car list-item) ; head
    (car (last list-item)) ; tail

but I'm wondering if there's a better way.

----

Explanation:
What I'm trying to do overall is to get the various details out
of a list item that might look like:

  - State "DONE"       from "NEXT"       [2023-06-05 Mon 10:54] \\
    example

So I'd like to be able to get the date of the timestamp (this
isn't an absolute requirement, I'm happy enough to just using the
current date), and the "example" text (which, obviously, isn't
always "example"). If I have to use buffer-substring-no-properties
and my car & car (above) then I will, but it would be nice to
know there's an easier/better/more appropriate way of getting at
what I want.

Thanks in advance.


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

* Re: Getting the components of an item in a plain-list
  2023-06-05 10:18 Getting the components of an item in a plain-list bvchgvbt
@ 2023-06-05 14:50 ` Ihor Radchenko
  0 siblings, 0 replies; 2+ messages in thread
From: Ihor Radchenko @ 2023-06-05 14:50 UTC (permalink / raw)
  To: bvchgvbt; +Cc: orgmode ml

bvchgvbt@mail.com writes:

> If I have a plain-list element that looks something like
>
> ...
> I seem to be able to get the items from the list using
>
>     org-element-property :structure
>
>     (260 2 "- " nil nil nil 338)
> ...
> But if I try to use org-element-property on that, of course it
> fails because it's not an element, as I understand it, rather
> it's an object(?).

List structure is a semi-internal property, parsed using very old code,
not fully compatible with the rest of org-element API. Please check
`org-list-struct' and other functions in lisp/org-list.el to find how to
retrieve information about list structure. Or just not use it.

> Explanation:
> What I'm trying to do overall is to get the various details out
> of a list item that might look like:
>
>   - State "DONE"       from "NEXT"       [2023-06-05 Mon 10:54] \\
>     example
>
> So I'd like to be able to get the date of the timestamp (this
> isn't an absolute requirement, I'm happy enough to just using the
> current date), and the "example" text (which, obviously, isn't
> always "example"). If I have to use buffer-substring-no-properties
> and my car & car (above) then I will, but it would be nice to
> know there's an easier/better/more appropriate way of getting at
> what I want.

Here, you should better use `org-element-context' - it will parse on
object level, down to list items, paragraphs, and the containing objects.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


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

end of thread, other threads:[~2023-06-05 14:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-05 10:18 Getting the components of an item in a plain-list bvchgvbt
2023-06-05 14:50 ` Ihor Radchenko

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