emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Specifying the tangle filename based on the source filename?


From: Diego Zamboni
Subject: Re: [O] Specifying the tangle filename based on the source filename?
Date: Sun, 28 Jan 2018 21:15:03 +0100

Hi Jack,

This is very useful. At the moment I’m still keeping my org files next to their 
generated files instead of a single tree, but your code makes me think it 
should be possible to set up a save hook to set the header-args variable for 
each file. I’m already using a save hook to run org-babel-tangle when I save an 
org file, so it shouldn’t be too difficult to add this. I’ll give it a try.

Thanks for the pointer!

Best,
—Diego


> On 28 Jan 2018, at 19:13, Jack Henahan <address@hidden> wrote:
> 
> I do something similar, and I use a snippet like this
> 
> #+begin_src emacs-lisp
>  (defun the-in-the-org-lib-p ()
>    (and (f-this-file)
>         (f-child-of? (f-this-file) the-org-lib-directory)))
> 
>  (defun the-org-lib-hook ()
>    (if (the-in-the-org-lib-p)
>        (progn
>          (setq-local org-babel-default-header-args:emacs-lisp
>                      `((:tangle . ,(f-expand (f-swap-ext (f-filename 
> (f-this-file)) "el") the-lib-directory))
>                        (:noweb . "yes"))))))
> 
>    (add-hook 'org-mode-hook 'the-org-lib-hook)
> #+end_src
> 
> `the-org-lib-directory' points to where all my Org config sources are,
> while `the-lib-directory' points to where the tangled files go. My Org
> files then have a structure like
> 
> org/whatever.org
> 
> * Configuring Whatever Features
> ** Requirements :noexport:
> #+begin_src emacs-lisp
>  ;; -*- lexical-binding: t; -*-
>  ;;; whatever.el --- Whatever functionality
> 
>  (require 'whatever)
> #+end_src
> ** Some Subfeature
> Explain how we use the feature
> #+begin_src emacs-lisp
>  (my-configuration 'stuff)
> #+end_src
> 
> ** Provides :noexport:
> #+begin_src emacs-lisp
>  (provide 'whatever)
> 
>  ;;; whatever.el ends here
> #+end_src
> 
> I have some additional configuration to tangle my lib files on save, and
> to regenerate the top-level documentation so that (in theory) the README
> is always up to date with the configuration. The :noexport: tags remove
> the noise of require and provides when I export.
> 
> Diego Zamboni <address@hidden> writes:
> 
>> Hi,
>> 
>> I’ve been converting many of my configuration files to org-mode to better 
>> document them (examples:
>> https://github.com/zzamboni/dot_emacs/blob/master/init.org, 
>> https://github.com/zzamboni/dot_elvish/blob/master/rc.org). Usually I
>> have a line like the following at the top of each org file:
>> 
>> #+PROPERTY: header-args:emacs-lisp :tangle init.el
>> 
>> So that all the code blocks in the file are, by default, tangled to the 
>> corresponding config file. I was wondering if it might be
>> possible to avoid hardcoding the output file (“init.el” in this example) and 
>> instead derive it from the source filename (“init.org” in
>> this case). I’ve looked a bit through the manual and although I found the 
>> {{{input-file}}} macro, I couldn’t get it to work.
>> 
>> Thanks for any help,
>> —Diego
> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]