emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Rodrigo Morales <moralesrodrigo1100@gmail.com>
To: Eric S Fraga <e.fraga@ucl.ac.uk>
Cc: emacs-orgmode@gnu.org
Subject: Re: How do you name your code blocks?
Date: Tue, 16 Feb 2021 20:27:54 -0500	[thread overview]
Message-ID: <87sg5vlbz9.fsf@gmail.com> (raw)
In-Reply-To: <87tuqc43ur.fsf@ucl.ac.uk>


Eric S Fraga <e.fraga@ucl.ac.uk> writes:

> Yes.  Fully qualified and detailed.  And then rely on completion to jump
> to code blocks (using org-babel-goto-named-src-block).

Thanks for the answer. I didn't know about
=org-babel-goto-named-src-block=.

Regarding using fully qualified and detailed names: I feel like it is
not a good idea for the use case I have with Org Mode. I have multiple
big Org files for each programming languages I've used and while using
long names might avoid name conflicts, there would be a time in which a
name conflict would occur because it is necessary to avoid using a name
which has already been used, so for example if I name a code block with
=generate-data-for-plotting=, I can't use that same name again.

For this reason, I was thinking in the following workaround: use use the
ID of the subtree as the prefix of the name of the code blocks. Thus,
name conflicts are less likely to occur (see example below).

#+begin_src org
,* DONE How to get the number of lines in a file?
  :PROPERTIES:
  :ID:       ec1f7066-213c-458e-a0f9-786b722218f4
  :END:

,#+NAME: ec1f7066-213c-458e-a0f9-786b722218f4/create-file
,#+begin_src dash :results silent
cat << EOF > main.txt
first
second
third
EOF
,#+end_src

,* DONE How to print most repeated word in a file?
  :PROPERTIES:
  :ID:       e0768c19-080f-47db-9dc2-3bd00efdd036
  :END:

,#+NAME: e0768c19-080f-47db-9dc2-3bd00efdd036/create-file
,#+begin_src dash :results silent
cat << EOF > main.txt
fizz fizz fizz
buzz buzz buzz buzz
foo
bar bar
EOF
,#+end_src
#+end_src

As we can see above, both =dash= code blocks are given the name
=create-file= because both of them create a file but the ID of the
heading is used a the prefix in order to avoid a name conflict.

Let me know your thoughts on this workaround :)
-- 
Rodrigo Morales.
IRC: rdrg109 (freenode)


  reply	other threads:[~2021-02-17  1:36 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-15 19:18 How do you name your code blocks? Rodrigo Morales
2021-02-16  4:53 ` Greg Minshall
2021-02-17  1:21   ` Rodrigo Morales
2021-02-16 12:03 ` Eric S Fraga
2021-02-17  1:27   ` Rodrigo Morales [this message]
2021-02-17  6:56     ` Greg Minshall
2021-02-17 20:31       ` Rodrigo Morales
2021-02-17  1:58 ` Kevin M. Stout
2021-02-17  9:57   ` Eric S Fraga

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=87sg5vlbz9.fsf@gmail.com \
    --to=moralesrodrigo1100@gmail.com \
    --cc=e.fraga@ucl.ac.uk \
    --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).