* can't get org-mode noweb tangle to work
@ 2017-11-25 0:10 Charles R (Charlie) Martin
2017-11-25 0:26 ` Thomas S. Dye
0 siblings, 1 reply; 5+ messages in thread
From: Charles R (Charlie) Martin @ 2017-11-25 0:10 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 974 bytes --]
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):
<<initialize-the-game-board>>
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):
<<initialize-the-game-board>>
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
[-- Attachment #2: Type: text/html, Size: 3764 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: can't get org-mode noweb tangle to work
2017-11-25 0:10 can't get org-mode noweb tangle to work Charles R (Charlie) Martin
@ 2017-11-25 0:26 ` Thomas S. Dye
2017-11-25 0:52 ` Charles R (Charlie) Martin
0 siblings, 1 reply; 5+ messages in thread
From: Thomas S. Dye @ 2017-11-25 0:26 UTC (permalink / raw)
To: Charles R (Charlie) Martin; +Cc: emacs-orgmode
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):
> <<initialize-the-game-board>>
>
> 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):
> <<initialize-the-game-board>>
>
> 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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: can't get org-mode noweb tangle to work
2017-11-25 0:26 ` Thomas S. Dye
@ 2017-11-25 0:52 ` Charles R (Charlie) Martin
2017-11-25 5:38 ` Martin Alsinet
0 siblings, 1 reply; 5+ messages in thread
From: Charles R (Charlie) Martin @ 2017-11-25 0:52 UTC (permalink / raw)
To: Thomas S. Dye; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1924 bytes --]
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):
<<initialize-the-game-board>>
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 <tsd@tsdye.com> 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):
> > <<initialize-the-game-board>>
> >
> > 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):
> > <<initialize-the-game-board>>
> >
> > 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
>
[-- Attachment #2: Type: text/html, Size: 4646 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: can't get org-mode noweb tangle to work
2017-11-25 0:52 ` Charles R (Charlie) Martin
@ 2017-11-25 5:38 ` Martin Alsinet
2017-12-01 4:08 ` Grant Rettke
0 siblings, 1 reply; 5+ messages in thread
From: Martin Alsinet @ 2017-11-25 5:38 UTC (permalink / raw)
To: Charles R (Charlie) Martin; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 3052 bytes --]
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):
> <<initialize-the-game-board>>
>
> 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 <tsd@tsdye.com> 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):
>> > <<initialize-the-game-board>>
>> >
>> > 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):
>> > <<initialize-the-game-board>>
>> >
>> > 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
>>
>
>
[-- Attachment #2: Type: text/html, Size: 6970 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: can't get org-mode noweb tangle to work
2017-11-25 5:38 ` Martin Alsinet
@ 2017-12-01 4:08 ` Grant Rettke
0 siblings, 0 replies; 5+ messages in thread
From: Grant Rettke @ 2017-12-01 4:08 UTC (permalink / raw)
To: Martin Alsinet; +Cc: Charles R (Charlie) Martin, emacs-orgmode@gnu.org
[-- Attachment #1: Type: text/plain, Size: 1741 bytes --]
On Fri, Nov 24, 2017 at 11:38 PM, Martin Alsinet <martin@alsinet.com.ar>
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__ == "__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
«init»
def main(args):
init_board(args)
if __name__ == "__main__":
main(sys.argv)
#+END_SRC
Calling `org-babel-expand-src-block'
[-- Attachment #2: Type: text/html, Size: 3093 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-12-01 16:48 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-25 0:10 can't get org-mode noweb tangle to work Charles R (Charlie) Martin
2017-11-25 0:26 ` Thomas S. Dye
2017-11-25 0:52 ` Charles R (Charlie) Martin
2017-11-25 5:38 ` Martin Alsinet
2017-12-01 4:08 ` Grant Rettke
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.