From mboxrd@z Thu Jan 1 00:00:00 1970 From: Diego Zamboni Subject: Re: Babel: tangling questions Date: Tue, 3 Dec 2019 14:28:12 +0100 Message-ID: References: <87immxenvo.fsf@iki.fi> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000a180540598ccabad" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:43359) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ic8ED-0005zu-O5 for emacs-orgmode@gnu.org; Tue, 03 Dec 2019 08:28:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ic8EA-000195-PG for emacs-orgmode@gnu.org; Tue, 03 Dec 2019 08:28:32 -0500 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]:45986) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ic8E7-00014G-SP for emacs-orgmode@gnu.org; Tue, 03 Dec 2019 08:28:29 -0500 Received: by mail-wr1-x431.google.com with SMTP id j42so3607489wrj.12 for ; Tue, 03 Dec 2019 05:28:25 -0800 (PST) In-Reply-To: <87immxenvo.fsf@iki.fi> 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: Org-mode Cc: Jarmo Hurri --000000000000a180540598ccabad Content-Type: text/plain; charset="UTF-8" Hi Jarmo, 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))) Also, check out my free book "Literate Config", where I discuss some more tips about Literate Programming: https://leanpub.com/lit-config/read Hope this helps, --Diego --000000000000a180540598ccabad Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Jarmo,

1. I want to tangle to the default filename (derived from name of org
=C2=A0 =C2=A0file and programming language). However, the :tangle header ar= gument
=C2=A0 =C2=A0only takes either "yes" or "filename." If = the value is "yes", then
=C2=A0 =C2=A0the filename is deduced automatically. How can I specify a tan= gling
=C2=A0 =C2=A0directory and still have the default filename?

=C2=A0 =C2=A0There was a related question on stack exchange, but it did not= use
=C2=A0 =C2=A0the default filename:
=C2=A0 =C2=A0https://emacs.stackexchange.com/questions/41806/org-babel-set-root-dir-for= -tangled-files

You can specify a full p= ath 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 e= macs-lisp code as the value for :tangle, so you could do something like thi= s:

=C2=A0:tangle (concat "/some/dir/" (f= ile-name-base (file-name-sans-extension (buffer-file-name))) ".ext&quo= t;)

3. Is it possible to tangle automatically on (every) export? I always
=C2=A0 =C2=A0export, but I might forget to tangle, in which case export and= tangle
=C2=A0 =C2=A0would be out of sync.

I us= e the following hook to tangle on every save. I find it indispensable :)

=C2=A0 (add-hook 'org-mode-hook (lambda () (add-hook = 'after-save-hook 'org-babel-tangle
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0'run-at-end 'only-in-org-mode)))
Also, check out my free book "Literate Config", wher= e I discuss some more tips about Literate Programming:=C2=A0https://leanpub.com/lit-config/read
=C2=A0
Hope this helps,
--Diego

--000000000000a180540598ccabad--