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: Sun, 9 Aug 2015 20:28:08 -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]:38519) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZObso-0001wh-Ql for emacs-orgmode@gnu.org; Sun, 09 Aug 2015 21:28:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZObsn-00086Z-PV for emacs-orgmode@gnu.org; Sun, 09 Aug 2015 21:28:10 -0400 Received: from mail-wi0-x231.google.com ([2a00:1450:400c:c05::231]:37240) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZObsn-00085J-Ie for emacs-orgmode@gnu.org; Sun, 09 Aug 2015 21:28:09 -0400 Received: by wibhh20 with SMTP id hh20so130289315wib.0 for ; Sun, 09 Aug 2015 18:28:09 -0700 (PDT) In-Reply-To: <87oaiganis.fsf@nicolasgoaziou.fr> 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" On Sun, Aug 9, 2015 at 3:12 AM, Nicolas Goaziou wr= ote: > Probably something like this (untested) > > (let ((case-fold-search t)) That is a valuable example for us to learn from. Right off the bat I wouldn't have though to indent that way, but would have noticed quickly enough when I did= n't account for the case! There were 276 blocks corrected. Here is the final version with a tweaked regex and removed and removal of my original replacement desire. Thank you Nicolas. =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80 =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=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80 if you are unfamiliar with that indent-to bit, here is ax example of what it handled correctly: #+NAME: FD94197F-0A18-480E-8DEA-F5943B860105 #+BEGIN_SRC emacs-lisp (add-to-list 'load-path "~/src/org-mode/lisp") #+END_SRC #+NAME: F4D65E13-0E55-4443-A7A7-13DD64A13051 #+BEGIN_SRC emacs-lisp (add-to-list 'load-path "~/src/org-mode/lisp") #+END_SRC #+NAME: 705F4F89-0431-42A3-A10D-1C528945CAC7 #+BEGIN_SRC emacs-lisp (add-to-list 'load-path "~/src/org-mode/lisp") #+END_SRC #+NAME: 233C2AFF-A257-4091-875C-945E3189AFEB #+BEGIN_SRC emacs-lisp (add-to-list 'load-path "~/src/org-mode/lisp") #+END_SRC #+NAME: FC730EEE-A32B-449D-94EA-EBB750D89204 #+BEGIN_SRC emacs-lisp (add-to-list 'load-path "~/src/org-mode/lisp") #+END_SRC - Foo #+NAME: FD94197F-0A18-480E-8DEA-F5943B860105 #+BEGIN_SRC emacs-lisp (add-to-list 'load-path "~/src/org-mode/lisp") #+END_SRC - Foo #+NAME: FD94197F-0A18-480E-8DEA-F5943B860105 #+BEGIN_SRC emacs-lisp (add-to-list 'load-path "~/src/org-mode/lisp") #+END_SRC - Foo #+NAME: FD94197F-0A18-480E-8DEA-F5943B860105 #+BEGIN_SRC emacs-lisp (add-to-list 'load-path "~/src/org-mode/lisp") #+END_SRC - Foo #+NAME: FD94197F-0A18-480E-8DEA-F5943B860105 #+BEGIN_SRC emacs-lisp (add-to-list 'load-path "~/src/org-mode/lisp") #+END_SRC