1

I am planning to (re)organize my ahk code as code blocks into an org file and tangle this file to obtain the source file.

This is my ahk-guivho.org input file, with two code blocks, empty for the sake of this post:

#+TITLE:      AHK config file
+AUTHOR:      Guido Van Hoecke
+EMAIL:       (concat "guivho" at-sign "gmail.com")

#+PROPERTY:  header-args   :tangle ahk-guivho.ahk
#+PROPERTY:  header-args+  :padline yes
#+PROPERTY:  header-args+  :eval never
#+PROPERTY:  header-args+  :eval no
#+PROPERTY:  header-args+  :exports code

* HideWindow - hides the active window
#+BEGIN_SRC ahk
  HideWindow(title="", x=0, y=0) { ;hides the active window
  }


#+END_SRC
* ActivateWindow
#+BEGIN_SRC ahk
  ActivateWindow(title="") {
  }

#+END_SRC

I expect org-babel-tangle to produce a file called ahk-guivho.ahk with two empty subs (HideWindow and ActivateWindow) but it does not.

It simply complains: Tangled 0 code blocks from ahk-guivho.org

I am pretty sure that my org and babel setup is ok: I tangle my .emacs from an org file without any problems.

I do realize that ahk is not among the officially supported languages.

But when I edit a code block from the org file, I get a buffer with ahk-mode as expected.

Do I need to initialize something somewhere to be able to tangle ahk code from an org file?

4
  • You just need to add a :tangle keyword with the path you want - so #+BEGIN_SRC ahk :tangle ahk-guivho.ahk Doing that for both blocks will append as you expect. The tangle path can also be set at the file level – gregoryg Nov 8 '20 at 17:15
  • @gregoryg: the OP has done that with a header-arg specified as a property. It seems though that after adding the #+PROPERTY: lines, he did not refresh the buffer with C-c C-c on at least one of them. I suspect that if he reverts the buffer from the file, everything should work. As a minor point, the #+AUTHOR: and #+EMAIL: lines are missing the initial # but that should not affect the tangling at all (and after the # is added, the buffer needs to be refreshed again with C-c C-c on one of those lines, or the buffer reverted, or saved and killed and the file reopened). – NickD Nov 8 '20 at 21:09
  • @NickD you are right - sorry I missed that. But I tested the file and got the OP's error, but tangling worked when adding the keyword to the code blocks! – gregoryg Nov 8 '20 at 22:48
  • See my answer below for an explanation. – NickD Nov 9 '20 at 3:52
2

I'm pretty sure the problem here is that you did not refresh the buffer before tangling. You can do that by pressing C-c C-c on one of the keyword lines (a line starting with #+), because then Org mode activates changes to in-buffer settings; alternatively, you can save the file and revert the buffer from the file; or save the file, kill the buffer and reopen the file - see In buffer settings in the manual.

Here's an explanation of @gregoryg's findings in the comment: when you first add a #+PROPERTY line in the file (or you cut and paste the OP's Org mode file into a new local file), the #+PROPERTY: settings are NOT active: you need to activate them as pointed out above. So if you try to tangle before activating, you get the Tangled 0 code blocks message. If you then activate them, it all works as it should.

If OTOH you add the :tangle foo header to the code blocks instead, you don't need to activate anything: the babel code parses the code blocks in their entirety and it tangles the two code blocks successfully.

I hope that clarifies the situation.

1
  • This is a very clear explanation and right on the dot! Thank you so much, it works! Hurrah!!! – guivho Nov 9 '20 at 18:23

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.