emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Jarmo Hurri <jarmo.hurri@iki.fi>
To: emacs-orgmode@gnu.org
Subject: Re: Babel: tangling questions
Date: Tue, 03 Dec 2019 17:22:28 +0200	[thread overview]
Message-ID: <871rtlo2mj.fsf@iki.fi> (raw)
In-Reply-To: CAGY83EdWU3DOAY+Yvj_Sy9jgs6HegzhHx3oVaz29Nbz2ohW_bQ@mail.gmail.com


Greetings Diego.

Diego Zamboni <diego@zzamboni.org> 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

      reply	other threads:[~2019-12-03 15:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-03  9:53 Babel: tangling questions Jarmo Hurri
2019-12-03 13:28 ` Diego Zamboni
2019-12-03 15:22   ` Jarmo Hurri [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871rtlo2mj.fsf@iki.fi \
    --to=jarmo.hurri@iki.fi \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).