[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How do you name your code blocks?
From: |
Rodrigo Morales |
Subject: |
Re: How do you name your code blocks? |
Date: |
Tue, 16 Feb 2021 20:27:54 -0500 |
User-agent: |
mu4e 1.4.14; emacs 27.1 |
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)