From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jarmo Hurri Subject: Re: Babel: tangling questions Date: Tue, 03 Dec 2019 17:22:28 +0200 Message-ID: <871rtlo2mj.fsf@iki.fi> References: <87immxenvo.fsf@iki.fi> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:54090) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1icA0j-0006cR-T4 for emacs-orgmode@gnu.org; Tue, 03 Dec 2019 10:22:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1icA0e-0001Ip-Re for emacs-orgmode@gnu.org; Tue, 03 Dec 2019 10:22:43 -0500 Received: from 195-159-176-226.customer.powertech.no ([195.159.176.226]:33290 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1icA0d-0001DA-Im for emacs-orgmode@gnu.org; Tue, 03 Dec 2019 10:22:39 -0500 Received: from list by blaine.gmane.org with local (Exim 4.89) (envelope-from ) id 1icA0Z-000eDS-Kt for emacs-orgmode@gnu.org; Tue, 03 Dec 2019 16:22:35 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org Greetings Diego. Diego Zamboni 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