emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] org-element approach to modify or add ID to every headline


From: Nicolas Goaziou
Subject: Re: [O] org-element approach to modify or add ID to every headline
Date: Sun, 09 Aug 2015 09:44:06 +0200

Hello,

Grant Rettke <address@hidden> writes:

> Goal:
>
> 1) Visit every headline
> 2) If there is an ID property
>    1) Then replace it's value with a UUID
> 3) If there is not an ID property
>    1) Add an ID property and give it a UUID.
>
> `org-uuid' [provides] the functionality to add the ID with a UUID.
>
> [This post] explains how to do it:
>
> ┌────
> │ (require 'org-id)
> │    (save-excursion
> │       (goto-char (point-max))
> │       (while (outline-previous-heading)
> │         (org-id-get-create)))
> └────
>
> What is the best way to do it with `org-element'?

Using `org-element' here would be sub-optimal. Headlines are context
insensitive, i.e., you don't need a parser to find one. 

Anyway, the following should do:

  (dolist (p (nreverse
              (org-element-map (org-element-parse-buffer 'headline) 'headline
                (lambda (headline) (org-element-property :begin headline)))))
    (goto-char p)
    (org-id-get-create))


Regards,

-- 
Nicolas Goaziou



reply via email to

[Prev in Thread] Current Thread [Next in Thread]