From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: Grant Rettke <gcr@wisdomandwonder.com>
Cc: "emacs-orgmode@gnu.org" <emacs-orgmode@gnu.org>
Subject: Re: org-element approach to modify or add ID to every headline
Date: Sun, 09 Aug 2015 09:44:06 +0200 [thread overview]
Message-ID: <87si7saou1.fsf@nicolasgoaziou.fr> (raw)
In-Reply-To: <CAAjq1mfhtoAtv6gqnQ6p8cwAG63ORqsQJpNZjsOHq8yBczHTkg@mail.gmail.com> (Grant Rettke's message of "Sat, 8 Aug 2015 22:01:12 -0500")
Hello,
Grant Rettke <gcr@wisdomandwonder.com> 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
next prev parent reply other threads:[~2015-08-09 7:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-09 3:01 org-element approach to modify or add ID to every headline Grant Rettke
2015-08-09 7:44 ` Nicolas Goaziou [this message]
2015-08-10 1:23 ` Grant Rettke
2015-08-15 1:54 ` Samuel W. Flint
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87si7saou1.fsf@nicolasgoaziou.fr \
--to=mail@nicolasgoaziou.fr \
--cc=emacs-orgmode@gnu.org \
--cc=gcr@wisdomandwonder.com \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.