7

Consider the following Org file:

#+PROPERTY: tangle "init.el"
#+PROPERTY: noweb yes

* A
#+begin_src elisp
; initialization code
; this *must* come first
#+end_src

* B
#+begin_src emacs-lisp
<<support-functions>>
#+end_src

** Cool Stuff
#+begin_src elisp :noweb-ref "support-functions" :tangle no
(message "willkommen")
#+end_src

** Test
#+begin_src elisp :noweb-ref "support-functions" :tangle no
(message "hi")
#+end_src

yields

(message "willkommen")
(message "hi")

; initialization code
; this *must* come first

yet removing the :tangle header argument on one of the blocks in Cool Stuff fixes the issue, but duplicates code:

; initialization code
; this *must* come first

(message "hi")

(message "willkommen")
(message "hi")

What must I do to ensure correct behavior? I know I could simply turn off tangling for the document and have everything be noweb, but this feels like a workaround rather than a solution.

  • Does this help? Is it possible... – Luke Shimkus Oct 27 '14 at 0:24
  • @KingShimkus I've never used variables in org-babel, but the other answers are almost exactly what I'm doing. – Sean Allred Oct 27 '14 at 0:33
  • I know, I all the answers. Just thought the first answer might serve some use. – Luke Shimkus Oct 27 '14 at 0:35
  • @KingShimkus Ah, well I'd like to not introduce ambiguities in the code. It looks like Org just does a search/replace for the variable/value; if I happen to use the same name… again, it just feels like a hack :) Thanks, though :) – Sean Allred Oct 27 '14 at 0:38
  • No problem, sorry I couldn't of been of more assistance. – Luke Shimkus Oct 27 '14 at 0:47
6

I think the problem is simply that you are using two different ways of specifying the language of the source blocks: emacs-lisp for some and elisp for others. It seems that all the elisp blocks are tangled before all the emacs-lisp ones (alphabetical order?). If you consistently use one or the other, then the order of the blocks in your file is respected:

#+PROPERTY: tangle "init.el"
#+PROPERTY: noweb yes

* A
#+begin_src emacs-lisp
; initialization code
; this *must* come first
#+end_src

* B
#+begin_src emacs-lisp
<<support-functions>>
#+end_src

** Cool Stuff
#+begin_src emacs-lisp :noweb-ref "support-functions" :tangle no
(message "willkommen")
#+end_src

** Test
#+begin_src emacs-lisp :noweb-ref "support-functions" :tangle no
(message "hi")
#+end_src

tangles to

; initialization code
; this *must* come first

(message "willkommen")
(message "hi")
| improve this answer | |
4

There are two problems here. The first is that you are setting the tangle property on the whole document. When you do this, you need to set every block that is a noweb block as :tangle no. It's much easier to set the tangle property on one block and use it as a framework for the entire tangled document. You can see how this works in my example below.

The second problem is your inconsistent source type declarations. the elisp blocks are coming out first because they collate before emacs-lisp. They should all be labelled the same if they are the same language and go in the same file (there are exceptions, of course, such as embedding SQL in PHP or something, but following my first suggestion will help avoid problems.

* A

#+header: :tangle init.el
#+header: :noweb yes
#+begin_src emacs-lisp
  ; initialization code
  ; this *must* come first

  <<support-functions>>
#+end_src

* B

** Cool Stuff

#+name: support-functions
#+begin_src emacs-lisp
  (message "willkommen")
#+end_src

** Test

#+name: support-functions
#+begin_src emacs-lisp
  (message "hi")
#+end_src

Tangles to

; initialization code
; this *must* come first

(message "willkommen")
(message "hi")
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.