emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org-element approach to modify or add ID to every headline
@ 2015-08-09  3:01 Grant Rettke
  2015-08-09  7:44 ` Nicolas Goaziou
  0 siblings, 1 reply; 4+ messages in thread
From: Grant Rettke @ 2015-08-09  3:01 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

Good evening,

Emacs 24.4 and Org from Git.

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'?


[provides]
http://orgmode.org/w/?p=org-mode.git;a=blob_plain;f=lisp/org-id.el;hb=HEAD

[This post]
https://stackoverflow.com/questions/13340616/assign-ids-to-every-entry-in-org-mode

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

* Re: org-element approach to modify or add ID to every headline
  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
  2015-08-10  1:23   ` Grant Rettke
  0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Goaziou @ 2015-08-09  7:44 UTC (permalink / raw)
  To: Grant Rettke; +Cc: emacs-orgmode@gnu.org

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

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

* Re: org-element approach to modify or add ID to every headline
  2015-08-09  7:44 ` Nicolas Goaziou
@ 2015-08-10  1:23   ` Grant Rettke
  2015-08-15  1:54     ` Samuel W. Flint
  0 siblings, 1 reply; 4+ messages in thread
From: Grant Rettke @ 2015-08-10  1:23 UTC (permalink / raw)
  To: Grant Rettke, emacs-orgmode@gnu.org

On Sun, Aug 9, 2015 at 2:44 AM, Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:
> Anyway, the following should do:

That works perfectly. Thank you.

Tempted to run it in a on-save hook just to ensure that the document
*always* has IDs. At least for tangle comments.

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

* Re: org-element approach to modify or add ID to every headline
  2015-08-10  1:23   ` Grant Rettke
@ 2015-08-15  1:54     ` Samuel W. Flint
  0 siblings, 0 replies; 4+ messages in thread
From: Samuel W. Flint @ 2015-08-15  1:54 UTC (permalink / raw)
  To: Grant Rettke; +Cc: emacs-orgmode@gnu.org

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

Grant Rettke <gcr@wisdomandwonder.com> writes:

> On Sun, Aug 9, 2015 at 2:44 AM, Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:
>> Anyway, the following should do:
>
> That works perfectly. Thank you.
>
> Tempted to run it in a on-save hook just to ensure that the document
> *always* has IDs. At least for tangle comments.
>

You might try setting `org-id-link-to-org-use-id' to either t or
'create-if-interactive.  I believe I have it set to t, and I get ids
generated when I tangle.

HTH,

Sam

-- 
Samuel W. Flint
4096R/266596F4
      (9477 D23E 389E 40C5 2F10  DE19 68E5 318E 2665 96F4)
(λs.s s) λs.s s

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 818 bytes --]

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

end of thread, other threads:[~2015-08-15  1:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2015-08-10  1:23   ` Grant Rettke
2015-08-15  1:54     ` Samuel W. Flint

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