emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org-babel noweb-ref
@ 2019-09-29 14:31 edgar
  0 siblings, 0 replies; only message in thread
From: edgar @ 2019-09-29 14:31 UTC (permalink / raw)
  To: emacs-orgmode

Hello dear list,

First of all, this may be related:
- https://lists.gnu.org/archive/html/emacs-orgmode/2018-02/msg00300.html
- https://lists.gnu.org/archive/html/emacs-orgmode/2012-01/msg00044.html

- Emacs: src_emacs-lisp{emacs-version} {{{results(=26.3=)}}}
- Org: src_emacs-lisp{org-version} {{{results(=9.1.14=)}}}
- Parabola GNU/Linux: src_bash{uname -r} {{{results(=5.2.5-gnu-1=)}}}

I prepared the following hoping that it makes the issue clear. Let me 
know :) .

#+CAPTION: This works if ~org-babel-use-quick-and-dirty-noweb-expansion~ 
is ~nil~, but I don't want to import everything from ~libraries~
#+BEGIN_SRC python :tangle routines1.py :noweb yes :shebang # -*- 
coding: utf-8 -*-
   <<libraries>>


   <<routines>>
#+END_SRC

* Explanation with example

- I noticed some differences between the output of tangling and 
previewing org-babel blocks.
- ~org-babel-use-quick-and-dirty-noweb-expansion~ interferes with 
~:noweb~ in a way that I did not expect

I want to know
1. if this is the expected behaviour
2. how I can expand a named block (which has ~#+name: tag~) which is 
inside a subtree (subheading with the ~:noweb-ref~ property)

** Option 1

Set src_emacs-lisp{(setq org-babel-use-quick-and-dirty-noweb-expansion 
nil)}

#+BEGIN_SRC python :tangle /tmp/routines1.py :noweb yes :shebang # -*- 
coding: utf-8 -*-
   <<imp1.py>>


   <<routines>>
#+END_SRC

- Preview shows empty lines instead of ~imp1.py~ and no ~shebang~

   #+BEGIN_SRC python



     def fun1():
         pass


     def fun2():
         pass
   #+END_SRC

- Tangled ~/tmp/routines2.py~ shows ~shebang~, but no ~imp1.py~.

   #+BEGIN_SRC python
     # -*- coding: utf-8 -*-
     def fun1():
         pass


     def fun2():
         pass
   #+END_SRC


*** What I expected

1. Both Preview and tangling to have the same content
2. for ~imp1.py~ to be expanded at the top of the code as ~import numpy 
as np~.

** Option 2

src_emacs-lisp{(setq org-babel-use-quick-and-dirty-noweb-expansion t)}

#+BEGIN_SRC python :tangle /tmp/routines2.py :noweb yes :shebang # -*- 
coding: utf-8 -*-
   <<imp1.py>>


   <<routines>>
#+END_SRC

- Preview shows

   #+BEGIN_SRC python
     import numpy as np


   #+END_SRC

- Tangled ~/tmp/routines2.py~ shows

   #+BEGIN_SRC python
     # -*- coding: utf-8 -*-
     import numpy as np
   #+END_SRC

*** What I expected

According to the manual, ~<<routines>>~ would not be solved correctly 
(as shown), but I expected to have the ~shebang~ in the preview.

A further comment can be made about the extra space (related to 
~:noweb-sep~), but that is minor and I don't care.

** Routines
:PROPERTIES:
:header-args: :noweb-ref routines :noweb-sep "\n\n\n"
:END:

#+NAME: fun1.py
#+BEGIN_SRC python
   def fun1():
       pass
#+END_SRC

#+NAME: fun2.py
#+BEGIN_SRC python
   def fun2():
       pass
#+END_SRC

** Libraries
:PROPERTIES:
:header-args: :noweb-ref libraries
:END:

#+NAME: imp1.py
#+BEGIN_SRC python
   import numpy as np
#+END_SRC

#+NAME: imp2.py
#+BEGIN_SRC python
   import os
#+END_SRC

-------------------------------------------------
This free account was provided by VFEmail.net - report spam to abuse@vfemail.net
 
ONLY AT VFEmail! - Use our Metadata Mitigator to keep your email out of the NSA's hands!
$24.95 ONETIME Lifetime accounts with Privacy Features!  
15GB disk! No bandwidth quotas!
Commercial and Bulk Mail Options!  

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-09-29 14:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-29 14:31 org-babel noweb-ref edgar

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).