1. I want to tangle to the default filename (derived from name of org
file and programming language). However, the :tangle header argument
only takes either "yes" or "filename." If the value is "yes", then
the filename is deduced automatically. How can I specify a tangling
directory and still have the default filename?
There was a related question on stack exchange, but it did not use
the default filename:
https://emacs.stackexchange.com/questions/41806/org-babel-set-root-dir-for-tangled-files
You can specify a full path as the value of :tangle, but I don't know of a way to specify only the directory.
As a workaround, you can also use emacs-lisp code as the value for :tangle, so you could do something like this:
:tangle (concat "/some/dir/" (file-name-base (file-name-sans-extension (buffer-file-name))) ".ext")
3. Is it possible to tangle automatically on (every) export? I always
export, but I might forget to tangle, in which case export and tangle
would be out of sync.
I use the following hook to tangle on every save. I find it indispensable :)
(add-hook 'org-mode-hook (lambda () (add-hook 'after-save-hook 'org-babel-tangle
'run-at-end 'only-in-org-mode)))
Hope this helps,
--Diego