emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Sebastian Miele <sebastian.miele@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: managing repetitive code in export & tangling
Date: Tue, 08 Oct 2019 20:53:54 +0000	[thread overview]
Message-ID: <87mueb557h.fsf@gmail.com> (raw)
In-Reply-To: <CAN_Dec8=ygZZytAbrnfoiZ5vJQ=_RqMriK-+QBg7E9e2JeeheA@mail.gmail.com>

Matt Price <moptop99@gmail.com> writes:

> In my lectures i often have simple examples that build progressively
> over several slides. In order to use klipse properly, but also for
> clarity, I gneerally repeat variable declarations from slide to slide,
> so for instance:
>
> ** Making Lists (Arrays)
>
> +#NAME: js-array-historians
> #+BEGIN_SRC js
> let historians= ["Edward Gibbon", "Leopold von Ranke", "Edward Said", "Joan
> Scott"];
> #+END_SRC
>
> ** Repetition: While Loops
> #+NAME: js-while-hist
> #+begin_src js
> <<js-array-historians>>
> let i = 0;
>
> while (i < historians.length) {
>     console.log(historians[i] + " was a historian.");
>     i+=1;
>   }
> #+end_src
>
> There might then be a sequence of another 5 or 6 slides in which the same
> "historians" array is bound to the same value and used as an example.
>
> This works fine on its own. However, I would also like to tangle all this
> code to a single file per lecture so students can download a git repo and
> play with it directly in a real text editor. Unfortunately, javascript will
> error out if a ~let~ bound variable is  redeclared in the same scope.  I'm
> wondering if there's any way to specify that a noweb reference only be
> included one time in a tangled file. Or if there are cleverer workarounds
> that folks can suggest!

I have not used the exporting facilities of Org by myself, yet. However,
if what you sketch above does already produce expected results, then
something like the following should solve your problem. (The single
angle-bracketed stuff has to be replaced by the appropriate header
args.)

** Making Lists (Arrays)

#+NAME: js-array-historians
#+BEGIN_SRC js <do export, do tangle>
  let historians= ["Edward Gibbon", "Leopold von Ranke", "Edward Said", "Joan Scott"];
#+END_SRC

** Repetition: While Loops

#+NAME: js-while-hist
#+BEGIN_SRC js <dont export, do tangle>
  let i = 0;
  while (i < historians.length) {
      console.log(historians[i] + " was a historian.");
      i+=1;
    }
#+END_SRC

#+BEGIN_SRC js <do export, dont tangle>
  <<js-array-historians>>
  <<js-while-hlist>>
#+END_SRC

Best wishes
Sebastian

      reply	other threads:[~2019-10-08 20:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-08 15:26 managing repetitive code in export & tangling Matt Price
2019-10-08 20:53 ` Sebastian Miele [this message]

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=87mueb557h.fsf@gmail.com \
    --to=sebastian.miele@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).