2

I'm experimenting with Uncle Dave's config which is using a minimum init.el to launch config.org, which is full of elisp babel source blocks. Here's his relevant launching code:

(when (file-readable-p "~/.emacs.d/config.org")
  (org-babel-load-file (expand-file-name "~/.emacs.d/config.org")))

However, I've seen this:

(require 'org)
(require 'ob-tangle)
(org-babel-load-file (expand-file-name "~/.emacs.d/myemacs.org"))

which seems to want (require 'ob-tangle) (See here). The Uncle Dave setup is working fine. I guess I don't know how it's tangling (which means running all the code blocks in the org file, right?) without somehow being told to. But then what is org-babel-tangle-file doing other than running all the code blocks in a file? And then there's the :tangle yes parameter on an individual code block. I'm missing something here.

2

Here's what Nick Dokos (who has helped me often) over at the org-mode mail list says:

...tangling does not run code blocks: it just writes them out to (one or many) different file(s). org-babel-load-file calls org-babel-tangle which is an autoloaded function, so when it is called, emacs arranges to load the file that defines it (i.e. ob-tange.el[c]). So you don't need to to (require 'ob-tangle) separately.

However, I don't know all the ins and outs of tangling in org-mode yet. But I would guess attaching :tangle no to a block would keep it out of the tangle file.

This is what I had been doing -- at least for small bunches of code:

#+name: setup
#+BEGIN_SRC scheme :session ch1
(require math)
#+END_SRC

#+RESULTS: setup

# Local Variables:
# eval: (progn (org-babel-goto-named-src-block "setup") (org-babel-execute-src-block))
# End:

i.e., I'm using Emacs' local file variable capability to have a Racket module loaded, and, as a bonus, start up a REPL session.

Another angle is to use org-mode's Library of Babel capability.

  • Cool trick =) Would you mind expanding on why you have your setup this particular way? I feel I'm missing something that could be useful here. – dangom Apr 3 '18 at 22:17
  • The particular file this #+name: setup and the local file variable is in requires Racket's math module. It wouldn't make any sense to have it start as part of Emacs' general initialization. – 147pm Apr 4 '18 at 2:43
1

The way I configured my init.el as a init.org is similar to the one you are quoting from Uncle Dave. I am not using ob-tangle for parsing all the src blocks to another file using :tangle as a argument. I just bind org-babel-load-file to a key so as to reload it whenI make changes.

(global-set-key (kbd "C-c i")
(lambda() (interactive)(org-babel-load-file "~/.emacs.d/init.org")))
  • Thanks for the tip. Will implement. But what is the difference between org-babel-load-file and tangle stuff? – 147pm Apr 2 '18 at 22:35
  • 1
    I tried to call from the init.org file but it end up with a recursive call. I am therefore not sure how the tangle method works, since in the example that I find online there is no :tangle in the src header. normaly tangling will mean creating the one .el file from all the src blocks in te org file, which is what happens anyway when you call org-babel-load-file – manandearth Apr 3 '18 at 8:56
  • I think I'll ask over at the org-mode mailing list. – 147pm Apr 3 '18 at 12:07
  • please post your findings here @147pm, The documentation is very minimal.. – manandearth Apr 3 '18 at 13:03
  • Yeah, this whole "minimal" org-mode docs then people asking tons of questions that don't really get categorized or summarized into an O'Reilly-style book is a real treadmill. But then Emacs is vast. Alas. – 147pm Apr 3 '18 at 13:11

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.