From mboxrd@z Thu Jan 1 00:00:00 1970 From: Grant Rettke Subject: Re: can't get org-mode noweb tangle to work Date: Thu, 30 Nov 2017 22:08:30 -0600 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="94eb2c19c9a481e4ce055f3f85ef" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:40385) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eKoTw-00079t-PZ for emacs-orgmode@gnu.org; Fri, 01 Dec 2017 11:48:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eKoTv-0007tA-KD for emacs-orgmode@gnu.org; Fri, 01 Dec 2017 11:48:08 -0500 Received: from mail-lf0-x242.google.com ([2a00:1450:4010:c07::242]:38550) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eKoTv-0007qI-7Y for emacs-orgmode@gnu.org; Fri, 01 Dec 2017 11:48:07 -0500 Received: by mail-lf0-x242.google.com with SMTP id e137so12415063lfg.5 for ; Fri, 01 Dec 2017 08:48:05 -0800 (PST) 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: Martin Alsinet Cc: "Charles R (Charlie) Martin" , "emacs-orgmode@gnu.org" --94eb2c19c9a481e4ce055f3f85ef Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Nov 24, 2017 at 11:38 PM, Martin Alsinet wrote: > Hello Charlie: > > I have found that I like better to use a combination of tangle and import > instead of noweb syntax. > > #+BEGIN_SRC python :tangle board.py > def init_board(args) > return [[-1 for x in range(3)] for y in range(3)] > #+END_SRC > > #+BEGIN_SRC python > import sys > import os > from board import init_board > > def main(args): > init_board(args) > > if __name__ =3D=3D "__main__": > main(sys.argv) > #+END_SRC > > Then, you do a *M-x org-babel-tangle* and org will write the first block > into board.py. Then you go into the second block and run it with *C-c C-c= * and > it will load the init_board function from the tangled file. > > Writing it this way forces you to modularize your code blocks to be able > to call them from other blocks and you can even build your whole > application tangling the source blocks into files. > > The :noweb syntax seems to me to be a templating solution used for a code > module problem. > It can be if you like that style. You can define re-usable and callable source blocks and tangle them to their own file and to other files, too. For example using the example above you can use both approaches: #+NAME: init #+BEGIN_SRC python :tangle board.py :comments no def init_board(args) return [[-1 for x in range(3)] for y in range(3)] #+END_SRC #+NAME: org_gcr_2017-11-30_mara_1BB0EB7B-1693-458D-B1AD-CE44ED9961C1 #+BEGIN_SRC python :comments no :tangle program.py import sys import os =C2=ABinit=C2=BB def main(args): init_board(args) if __name__ =3D=3D "__main__": main(sys.argv) #+END_SRC Calling `org-babel-expand-src-block' --94eb2c19c9a481e4ce055f3f85ef Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Fri, Nov 24, 2017 at 11:38 PM, Martin Al= sinet <martin@alsinet.com.ar> wrote:
Hello Charlie:

<= /div>
I have found that I like better to use a combination of tangle an= d import instead of noweb syntax.

#+BEGIN_SRC python :tangle board.py
def init_board(args)
=C2=A0 =C2=A0 return [[-1 for x in range(3)] for y in range(3)]
#+END_SRC

<= div>#+BEGIN_SRC python
import sys
import = os
from board import init_board = =C2=A0 =C2=A0

def main(args):
=C2=A0 =C2=A0 init_board(args)
=C2=A0 =C2=A0=C2=A0
if __name__ =3D=3D "__main__":
=C2=A0 =C2=A0 main(sys.argv)
#+END_SRC

Then, you do a M-x org-babel-tangle=C2=A0and org will write the f= irst block into board.py. Then you go into the second block and run it with= C-c C-c=C2=A0and it will load the init_board function from the tang= led file.

Writing it this way forces you to modula= rize your code blocks to be able to call them from other blocks and you can= even build your whole application tangling the source blocks into files.

The :noweb syntax seems to me to be a templating so= lution used for a code module problem.

It can be if you like that style. You can define re-usable and call= able source blocks and tangle them to their own file and to other files, to= o. For example using the example above you can use both approaches:

#+NAME: init
#+BEGIN_SRC python :tangle bo= ard.py :comments no
def init_board(args)
=C2=A0 =C2=A0 = return [[-1 for x in range(3)] for y in range(3)]
#+END_SRC
=

#+NAME: org_gcr_2017-11-30_mara_1BB0EB7B-1693-458D-B1AD= -CE44ED9961C1
#+BEGIN_SRC python :comments no :tangle program.py<= /div>
import sys
import os

=C2=ABini= t=C2=BB

def main(args):
=C2=A0 =C2=A0 in= it_board(args)

if __name__ =3D=3D "__main__&q= uot;:
=C2=A0 =C2=A0 main(sys.argv)
#+END_SRC

Calling `org-babel-expand-src-block'=C2=A0
--94eb2c19c9a481e4ce055f3f85ef--