[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Babel: tangling questions
From: |
Jarmo Hurri |
Subject: |
Re: Babel: tangling questions |
Date: |
Tue, 03 Dec 2019 17:22:28 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) |
Greetings Diego.
Diego Zamboni <address@hidden> writes:
>> 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?
>
> You can specify a full path as the value of :tangle, but I don't know
> of a way to specify only the directory.
For my purposes this would be a nice new feature. Specifying a directory
would imply the default filename.
> 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")
Nice! For this to be practical, I need two additional features.
1. Ability to set "/some/dir/" on a per-file basis.
2. Ability to infer ".ext" from the source block.
I was actually extend your suggestion to a solution with both of these
properties. In my emacs init file I define:
(defun org-default-tangle-file-with-dir-from-property ()
(concat (or (org-entry-get nil "ORG_TANGLE_DIRECTORY" t) ".")
"/"
(file-name-base (file-name-sans-extension (buffer-file-name)))
"."
(let ((lang (car (org-babel-get-src-block-info t))))
(or (cdr (assoc lang org-babel-tangle-lang-exts)) lang))))
Then I set on the top of my org file, for example
#+property: ORG_TANGLE_DIRECTORY ../docs
After this the following works like a charm (at least so far):
:tangle (org-default-tangle-file-with-dir-from-property)
>> 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)))
Good idea, I will explore this.
> Also, check out my free book "Literate Config", where I discuss some
> more tips about Literate Programming:
> https://leanpub.com/lit-config/read
Will do.
> Hope this helps,
Sure did. Thanks!
Jarmo