From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sebastian Miele Subject: Re: managing repetitive code in export & tangling Date: Tue, 08 Oct 2019 20:53:54 +0000 Message-ID: <87mueb557h.fsf@gmail.com> References: Reply-To: sebastian.miele@gmail.com Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:43919) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHwUZ-00072o-BP for emacs-orgmode@gnu.org; Tue, 08 Oct 2019 16:54:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iHwUX-0001SY-OB for emacs-orgmode@gnu.org; Tue, 08 Oct 2019 16:53:58 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]:43138) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iHwUX-0001R3-E5 for emacs-orgmode@gnu.org; Tue, 08 Oct 2019 16:53:57 -0400 Received: by mail-wr1-x42c.google.com with SMTP id j18so20207769wrq.10 for ; Tue, 08 Oct 2019 13:53:57 -0700 (PDT) Received: from tisch ([2a02:908:175c:4260:5ffc:7882:6024:ca5b]) by smtp.gmail.com with ESMTPSA id g4sm26467117wrw.9.2019.10.08.13.53.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2019 13:53:55 -0700 (PDT) In-reply-to: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org Matt Price 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 > <> > 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 let historians= ["Edward Gibbon", "Leopold von Ranke", "Edward Said", "Joan Scott"]; #+END_SRC ** Repetition: While Loops #+NAME: js-while-hist #+BEGIN_SRC js let i = 0; while (i < historians.length) { console.log(historians[i] + " was a historian."); i+=1; } #+END_SRC #+BEGIN_SRC js <> <> #+END_SRC Best wishes Sebastian