emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Rodrigo Morales <moralesrodrigo1100@gmail.com>
To: emacs-orgmode@gnu.org
Subject: How to set the name of a source code block programatically?
Date: Mon, 15 Feb 2021 13:56:00 -0500	[thread overview]
Message-ID: <871rdhcg8v.fsf@gmail.com> (raw)

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


At a first glance, this task seems to be easy:

1. Go to the top of the source code block
2. Insert "#+NAME: <<name>>" or replace the current name.
3. Done.

However, there are multiple scenarios. The attached file =main.org=
contains the possible scenarios that the function must cover in order to
be considered usable.

Anyway, I could write the function but before spending time doing that I
was wondering if there exist some solutions out there.

The motivation for this question is to make names of code blocks include
the ID of the current heading so that name clashes doesn'tf occur in Orgf
mode files. Recall that =M-x org-lint= complains when there are two code
blocks with the same name in the same file. This means that if you have
a code block with name =generate-data=, you can't use that same name in
that specific file.


[-- Attachment #2: main.org --]
[-- Type: text/plain, Size: 811 bytes --]

* foo

Some code blocks have neither headers nor names.

#+begin_src dash
ls
#+end_src

#+begin_src dash :noweb yes :results output
ls
#+end_src

Some code blocks only have headers.

#+HEADER: :noweb yes
#+begin_src dash
ls
#+end_src

Some code blocks have multiple headers

#+HEADER: :results output
#+HEADER: :noweb yes
#+begin_src dash
ls
#+end_src

Some code blocks have empty names

#+NAME:
#+begin_src dash
echo a
#+end_src

Some code blocks have names.

#+NAME: ls
#+begin_src dash
ls
#+end_src

Some code blocks have names and headers.

#+NAME: ls
#+HEADER: :results output
#+HEADER: :noweb yes
#+begin_src dash
ls
#+end_src

#+HEADER: :results output
#+NAME: ls
#+HEADER: :noweb yes
#+begin_src dash
ls
#+end_src

#+HEADER: :results output
#+HEADER: :noweb yes
#+NAME: ls
#+begin_src dash
ls
#+end_src

[-- Attachment #3: Type: text/plain, Size: 58 bytes --]


-- 
Greetings,
Rodrigo Morales.

IRC: rdrg109 (freenode)

                 reply	other threads:[~2021-02-15 19:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=871rdhcg8v.fsf@gmail.com \
    --to=moralesrodrigo1100@gmail.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).