From mboxrd@z Thu Jan 1 00:00:00 1970 From: Martin Alsinet Subject: Re: can't get org-mode noweb tangle to work Date: Sat, 25 Nov 2017 05:38:50 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="001a11c1663e17364c055ec816da" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:35261) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eITBC-0000ee-Ni for emacs-orgmode@gnu.org; Sat, 25 Nov 2017 00:39:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eITB7-0003hC-T0 for emacs-orgmode@gnu.org; Sat, 25 Nov 2017 00:39:06 -0500 Received: from mail-oi0-f49.google.com ([209.85.218.49]:38845) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eITB7-0003h3-LQ for emacs-orgmode@gnu.org; Sat, 25 Nov 2017 00:39:01 -0500 Received: by mail-oi0-f49.google.com with SMTP id g139so6310681oic.5 for ; Fri, 24 Nov 2017 21:39:01 -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: "Charles R (Charlie) Martin" Cc: emacs-orgmode@gnu.org --001a11c1663e17364c055ec816da Content-Type: text/plain; charset="UTF-8" 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__ == "__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. I hope it helps you Martin On Fri, Nov 24, 2017 at 7:52 PM Charles R (Charlie) Martin < chasrmartin@gmail.com> wrote: > Grumble. Okay, this is sorted/ There are amazing numbers of > not-quite-right examples on the web. > > Thanks, Tom, I now have the below, which works. > > #+TITLE: Console Tic Tac Toe > #+SUBTITLE: A Literate Program in EMACS Org-Mode > #+AUTHOR: Charlie Martin > #+STARTUP: showall > > #+BEGIN_SRC python :tangle yes :noweb yes > import sys > import os > > def main(args): > <> > > if __name__ == "__main__": > main(sys.argv) > #+END_SRC > > #+NAME: initialize-the-game-board > #+BEGIN_SRC python > board = [[-1 for x in range(3)] for y in range(3)] > #+END_SRC > > > > > On Fri, Nov 24, 2017 at 5:26 PM, Thomas S. Dye wrote: > >> Aloha Charlie, >> >> Charles R (Charlie) Martin writes: >> >> > I'm trying to get literate programming with `:noweb` syntax working in >> > org-mode. I think I'm down to about the minimum case: >> > >> > #+TITLE: Console Tic Tac Toe >> > #+SUBTITLE: A Literate Program in EMACS Org-Mode >> > #+AUTHOR: Charlie Martin >> > #+STARTUP: showall >> > >> > #+BEGIN_SRC python :tangle yes :noweb >> > import sys >> > import os >> > >> > def main(args): >> > <> >> > >> > if __name__ == "__main__": >> > main(sys.argv) >> > #+END_SRC >> > >> > #+NAME: initialize-the-game-board >> > #+BEGIN_SRC python :tangle yes :noweb >> > board = [[-1 for x in range(3)] for y in range(3)] >> > #+END_SRC >> > >> > but when I tangle it I get: >> > >> > import sys >> > import os >> > >> > def main(args): >> > <> >> > >> > if __name__ == "__main__": >> > main(sys.argv) >> > >> > board = [[-1 for x in range(3)] for y in range(3)] >> > >> > I've tried permuting the argument, flags, and so on to no avail. >> > >> > EMACS version is 25.3.1 MacOS, org-mode 9.1.3 >> >> I think it should be :noweb yes >> >> hth, >> Tom >> >> -- >> Thomas S. Dye >> http://www.tsdye.com >> > > --001a11c1663e17364c055ec816da Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello Charlie:

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

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

#+BEGI= N_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<= /div>
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 wr= ite the first block into board.py. Then you go into the second block and ru= n it with C-c C-c=C2=A0and 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 an= d you can even build your whole application tangling the source blocks into= files.

The :noweb syntax seems to me to be a temp= lating solution used for a code module problem.

I = hope it helps you


Martin

<= div class=3D"gmail_quote">
On Fri, Nov 24, 2017 at 7:52 PM = Charles R (Charlie) Martin <chasrmartin@gmail.com> wrote:
Grumble. Okay, this is sorted/ There are amazing numbers of n= ot-quite-right examples on the web.

Thanks, Tom, I now have the below, which works.

#+TITLE: Console T= ic Tac Toe
#+SUBTITLE: A Literate Program in EMACS Org-Mode
<= div class=3D"gmail_default">#+AUTHOR: C= harlie Martin
#+STARTUP: showall

#+BEGIN_SRC python :tangle yes :noweb yes
=C2=A0 import sys
= =C2=A0 import os

=C2=A0 def main(args):
=C2=A0 =C2=A0 =C2=A0 <= ;<initialize-the-game-board>>

=C2=A0 if __name__ =3D=3D &= quot;__main__":
=C2=A0 =C2=A0 =C2=A0 main(sys.argv)
#+END_SRC
#+NAME: initialize-the-game-board
#+BEGIN_SRC python=C2=A0
=C2=A0 = board =3D [[-1 for x in range(3)] for y in range(3)]
#+END_SRC


<= /div>


On Fri, No= v 24, 2017 at 5:26 PM, Thomas S. Dye <tsd@tsdye.com> wrote:
<= blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px= #ccc solid;padding-left:1ex">Aloha Charlie,

Charles R (Charlie) Martin writes:

> I'm trying to get literate programming with `:noweb` syntax workin= g in
> org-mode. I think I'm down to about the minimum case:
>
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0#+TITLE: Console Tic Tac Toe
>=C2=A0 =C2=A0 =C2=A0#+SUBTITLE: A Literate Program in EMACS Org-Mode >=C2=A0 =C2=A0 =C2=A0#+AUTHOR: Charlie Martin
>=C2=A0 =C2=A0 =C2=A0#+STARTUP: showall
>
>=C2=A0 =C2=A0 =C2=A0#+BEGIN_SRC python :tangle yes :noweb
>=C2=A0 =C2=A0 =C2=A0 =C2=A0import sys
>=C2=A0 =C2=A0 =C2=A0 =C2=A0import os
>
>=C2=A0 =C2=A0 =C2=A0 =C2=A0def main(args):
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0<<initialize-the-game-bo= ard>>
>
>=C2=A0 =C2=A0 =C2=A0 =C2=A0if __name__ =3D=3D "__main__":
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0main(sys.argv)
>=C2=A0 =C2=A0 =C2=A0#+END_SRC
>
>=C2=A0 =C2=A0 =C2=A0#+NAME: initialize-the-game-board
>=C2=A0 =C2=A0 =C2=A0#+BEGIN_SRC python :tangle yes :noweb
>=C2=A0 =C2=A0 =C2=A0 =C2=A0board =3D [[-1 for x in range(3)] for y in r= ange(3)]
>=C2=A0 =C2=A0 =C2=A0#+END_SRC
>
> but when I tangle it I get:
>
>=C2=A0 =C2=A0 =C2=A0import sys
>=C2=A0 =C2=A0 =C2=A0import os
>
>=C2=A0 =C2=A0 =C2=A0def main(args):
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0<<initialize-the-game-board>= >
>
>=C2=A0 =C2=A0 =C2=A0if __name__ =3D=3D "__main__":
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0main(sys.argv)
>
>=C2=A0 =C2=A0 =C2=A0board =3D [[-1 for x in range(3)] for y in range(3)= ]
>
> I've tried permuting the argument, flags, and so on to no avail. >
> EMACS version is 25.3.1 MacOS, org-mode 9.1.3

I think it should be :noweb yes

hth,
Tom

--
Thomas S. Dye
http:= //www.tsdye.com

--001a11c1663e17364c055ec816da--