emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Grant Rettke <gcr@wisdomandwonder.com>
To: Martin Alsinet <martin@alsinet.com.ar>
Cc: "Charles R (Charlie) Martin" <chasrmartin@gmail.com>,
	"emacs-orgmode@gnu.org" <emacs-orgmode@gnu.org>
Subject: Re: can't get org-mode noweb tangle to work
Date: Thu, 30 Nov 2017 22:08:30 -0600	[thread overview]
Message-ID: <CAAjq1md4M_-GfsBdoed4nqo6wWRPr562u6UaE0bfVVq4FPKj5A@mail.gmail.com> (raw)
In-Reply-To: <CABUJmkC1tP0YPrO5Mckura6rqWPhH7wcVy6gKhYqiSrMQ00UwA@mail.gmail.com>

[-- 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 --]

      reply	other threads:[~2017-12-01 16:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [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=CAAjq1md4M_-GfsBdoed4nqo6wWRPr562u6UaE0bfVVq4FPKj5A@mail.gmail.com \
    --to=gcr@wisdomandwonder.com \
    --cc=chasrmartin@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=martin@alsinet.com.ar \
    /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).