From mboxrd@z Thu Jan 1 00:00:00 1970 From: Grant Rettke Subject: Re: How to visit every source block and modify it's NAME property with org-element? Date: Mon, 10 Aug 2015 15:59:58 -0500 Message-ID: References: <87oaiganis.fsf@nicolasgoaziou.fr> 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]:52573) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZOuAr-0004gl-DA for emacs-orgmode@gnu.org; Mon, 10 Aug 2015 17:00:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZOuAq-0007Qt-Fg for emacs-orgmode@gnu.org; Mon, 10 Aug 2015 17:00:01 -0400 Received: from mail-wi0-x22d.google.com ([2a00:1450:400c:c05::22d]:35293) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZOuAq-0007Qd-8g for emacs-orgmode@gnu.org; Mon, 10 Aug 2015 17:00:00 -0400 Received: by wicne3 with SMTP id ne3so36958922wic.0 for ; Mon, 10 Aug 2015 13:59:58 -0700 (PDT) In-Reply-To: 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 , "emacs-orgmode@gnu.org" Here is perhaps the final version: - Go to point-min first - Do before tangling - Save buffer =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80 =E2=94=82 (defun help/org-prp-hdln () =E2=94=82 "Visit every Headline. If it doesn't have an ID property then a= dd one and =E2=94=82 assign it a UUID. Attribution: URL `http://article.gmane.org/gmane.emacs.orgmode/99738'" =E2=94=82 (interactive) =E2=94=82 (goto-char (point-min)) =E2=94=82 (dolist (p (nreverse =E2=94=82 (org-element-map (org-element-parse-buffer 'headlin= e) 'headline =E2=94=82 (lambda (headline) (org-element-property :begin h= eadline))))) =E2=94=82 (goto-char p) =E2=94=82 (org-id-get-create)) =E2=94=82 (save-buffer)) =E2=94=82 =E2=94=82 (defun help/org-prp-src-blk () =E2=94=82 "Visit every Source-Block. If it doesn't have a NAME property t= hen add one and =E2=94=82 assign it a UUID. Attribution: URL `http://article.gmane.org/gmane.emacs.orgmode/99740'" =E2=94=82 (interactive) =E2=94=82 (goto-char (point-min)) =E2=94=82 (let ((case-fold-search t)) =E2=94=82 (while (re-search-forward "^\s*#[+]BEGIN_SRC" nil t) =E2=94=82 (let ((element (org-element-at-point))) =E2=94=82 (when (eq (org-element-type element) 'src-block) =E2=94=82 (if (not (org-element-property :name element)) =E2=94=82 (let ((i (org-get-indentation))) =E2=94=82 (beginning-of-line) =E2=94=82 (save-excursion (insert "#+NAME: " (org-id-new) "= \n")) =E2=94=82 (indent-to i) =E2=94=82 (forward-line 2))))))) =E2=94=82 (save-buffer)) =E2=94=82 (add-hook #'org-babel-pre-tangle-hook #'help/org-prp-hdln) =E2=94=82 (add-hook #'org-babel-pre-tangle-hook #'help/org-prp-src-blk) =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80