From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: org-element approach to modify or add ID to every headline Date: Sun, 09 Aug 2015 09:44:06 +0200 Message-ID: <87si7saou1.fsf@nicolasgoaziou.fr> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:42132) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZOLFg-0004zv-1J for emacs-orgmode@gnu.org; Sun, 09 Aug 2015 03:42:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZOLFc-0006EC-RB for emacs-orgmode@gnu.org; Sun, 09 Aug 2015 03:42:39 -0400 Received: from relay3-d.mail.gandi.net ([2001:4b98:c:538::195]:55890) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZOLFc-0006BV-KT for emacs-orgmode@gnu.org; Sun, 09 Aug 2015 03:42:36 -0400 In-Reply-To: (Grant Rettke's message of "Sat, 8 Aug 2015 22:01:12 -0500") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Grant Rettke Cc: "emacs-orgmode@gnu.org" Hello, Grant Rettke 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: > > =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80 > =E2=94=82 (require 'org-id) > =E2=94=82 (save-excursion > =E2=94=82 (goto-char (point-max)) > =E2=94=82 (while (outline-previous-heading) > =E2=94=82 (org-id-get-create))) > =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80 > > 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.=20 Anyway, the following should do: (dolist (p (nreverse (org-element-map (org-element-parse-buffer 'headline) 'headli= ne (lambda (headline) (org-element-property :begin headline)))= )) (goto-char p) (org-id-get-create)) Regards, --=20 Nicolas Goaziou