From: "Kevin M. Stout" <kevin.m.stout@gmail.com>
To: Rodrigo Morales <moralesrodrigo1100@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: How do you name your code blocks?
Date: Tue, 16 Feb 2021 20:58:37 -0500 [thread overview]
Message-ID: <20210217015837.GA21805@cibola.cibola> (raw)
In-Reply-To: <87wnv9b0na.fsf@gmail.com>
On 2021-02-15 14:18, Rodrigo Morales wrote:
> 1. Do you use long names?
Usually. Suppose you were doing a bit of genetic programming. You might have a
function that computes the next generation from the current one. You could
write the following snippet that looks suspiciously like pseudocode:
#+HEADER::noweb-ref genetic/functions
#+BEGIN_SRC python
def next_generation(curr):
<<create a new pool>>
<<admit the elites>>
<<perform crossover, admit the offspring>>
<<perform mutations, admit the mutants>>
return new
#+END_SRC
You would then have a block dedicated to each major part of the evolutionary
step.
> 2. If not, how do you name your code blocks to avoid name conflicts?
I have been over the tangling and noweb expansion code quite a bit lately. The
chief benefit of using #+NAME on a code block is ability to call it. For
example, you might have
#+NAME: generate keymap
#+BEGIN_SRC elisp :var t=keymap
...
#+END_SRC
whose sole purpose is to take a table from elsewhere in an Org file and generate
the code that sets up a keymap. To use it, you might say
#+BEGIN_SRC elisp
<<generate keymap(main keymap)>>
#+END_SRC
For every other purpose, :noweb-ref works better. In newer versions of org,
it's the sole means of accumulating code under a common name in the WEB/Noweb
tradition. In older versions, duplicate #+NAMEs did result in accumulation, but
the behavior was undefined.
A word on syntax: I find
#+BEGIN_SRC language :noweb-ref "block name"
...
#+END_SRC
less readable than
#+HEADER::noweb-ref block name
#+BEGIN_SRC language
...
#+END_SRC
especially when there are further block-specific header args. Either is more
cumbersome to type than the #+NAME syntax, but that can be dealt with using
something like
(add-to-list 'org-structure-template-alist
'("ss" "#+HEADER::noweb-ref ?\n#+BEGIN_SRC\n\n#+END_SRC"))
Then, to set up a safely-named block, <ss followed by Tab will get you
#+HEADER::noweb-ref
#+BEGIN_SRC
#+END_SRC
I hope that helps.
--Kevin M. Stout
next prev parent reply other threads:[~2021-02-17 1:59 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
2021-02-17 6:56 ` Greg Minshall
2021-02-17 20:31 ` Rodrigo Morales
2021-02-17 1:58 ` Kevin M. Stout [this message]
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210217015837.GA21805@cibola.cibola \
--to=kevin.m.stout@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=moralesrodrigo1100@gmail.com \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.