emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Grant Rettke <gcr@wisdomandwonder.com>
To: Grant Rettke <gcr@wisdomandwonder.com>,
	"emacs-orgmode@gnu.org" <emacs-orgmode@gnu.org>
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	[thread overview]
Message-ID: <CAAjq1meUgNjH8X-3=S+PQsgRje6d7sr1yL-m222an4x16=RNJA@mail.gmail.com> (raw)
In-Reply-To: <87oaiganis.fsf@nicolasgoaziou.fr>

On Sun, Aug 9, 2015 at 3:12 AM, Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:
> 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 didn'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.

┌────
│ (let ((case-fold-search t))
│   (while (re-search-forward "^\s*#[+]BEGIN_SRC" nil t)
│     (let ((element (org-element-at-point)))
│       (when (eq (org-element-type element) 'src-block)
│         (if (not (org-element-property :name element))
│             (let ((i (org-get-indentation)))
│               (beginning-of-line)
│               (save-excursion (insert "#+NAME: " (org-id-new) "\n"))
│               (indent-to i)
│               (forward-line 2)))))))
└────

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

  reply	other threads:[~2015-08-10  1:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-09  3:06 How to visit every source block and modify it's NAME property with org-element? Grant Rettke
2015-08-09  8:12 ` Nicolas Goaziou
2015-08-10  1:28   ` Grant Rettke [this message]
2015-08-10 20:59     ` Grant Rettke

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

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAAjq1meUgNjH8X-3=S+PQsgRje6d7sr1yL-m222an4x16=RNJA@mail.gmail.com' \
    --to=gcr@wisdomandwonder.com \
    --cc=emacs-orgmode@gnu.org \
    /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 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).