[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Orgmode] [BABEL] Tangling to a hierarchy of files?
From: |
Eric Schulte |
Subject: |
Re: [Orgmode] [BABEL] Tangling to a hierarchy of files? |
Date: |
Wed, 19 Jan 2011 10:41:25 -0700 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) |
Chris Maier <address@hidden> writes:
> On Wed, Jan 19, 2011 at 5:05 AM, Rainer M Krug <address@hidden> wrote:
>> On 01/19/2011 08:22 AM, Eric Schulte wrote:
>>>
>>> In addition to the solution Charles posted, it is possible to put
>>> arbitrary elisp forms into header arguments, so the following
>>> alternative to your block above will create the directory (if it doesn't
>>> already exist) whenever the block is tangled or evaluated.
>>>
>>> #+begin_src clojure :tangle (prog1 "src/foo.clj" (make-directory "src" "."))
>>> (ns foo)
>>>
>>> (defn my-inc [x]
>>> (+ x 1))
>>> #+end_src
>
> This will do what I'm looking for, thanks!
>
> Is there a place where this and the eval-on-startup trick Charles
> posted are documented? If so, I missed it, and these are both really
> useful to know.
>
We don't currently have a good place in which to collect such tricks,
probably the closest is a file called scraps.org which I use for
stubbing out examples when responding to mailing list questions or doing
development. Each subheading is a short self-contained example. I do
plan on transforming this at some point into either a page on Worg
"Babel Tricks" or into a "Babel a Day" series or some such. The page is
available at the following (notice this dir. trick is at the top)
https://github.com/eschulte/babel-dev/raw/master/scraps.org
If anyone would like to take on the task of transferring this
information into a page on Worg that would be much appreciated! Maybe a
programmatic solution would be best, since I imagine this file will
continue to grow, or maybe I should just move this file to Worg
directly, if the Worg maintainers don't mind a steady trickle of small
commits...
>
>> Would it be possible, to include this into tangling, i.e. if the folder
>> in which the source file should be created does not exist, create it?
>>
>> I remember vaguely a discussion along these lines some time ago, but I
>> don't remember the outcome?
>
> This would be a great feature to have. Eric's embedded Lisp code
> trick will do the job, but I can imagine that it would get cumbersome
> for more complex projects.
>
This issue has come up recently -- also raised (I believe) by a
Clojurian most likely wanted to create a lein directory layout.
The reason that I push back against this, is that I often times
accidentally use a tangle path in which the directory does not exist and
the error notification serves as a useful warning that I either
mis-typed the directory or need to create it.
I would suggest either using the pre-tangle hook, or using my trick
above, which could be made more graceful with the following function
defined...
#+begin_src emacs-lisp
(defun mkdir-p (file &optional dir)
"Create any parent directories of FILE if missing and return FILE."
(make-directory (file-name-directory file) (or dir ".")) file)
#+end_src
However given that there seems to be some wide support for this maybe a
customization variable should be introduce,
e.g. org-babel-tangle-mkdirs-p or somesuch...
Cheers -- Eric
>
> Thanks for all the help, everyone!
>
> Chris
- [Orgmode] [BABEL] Tangling to a hierarchy of files?, Christopher Maier, 2011/01/18
- Re: [Orgmode] [BABEL] Tangling to a hierarchy of files?, Charles C. Berry, 2011/01/19
- Re: [Orgmode] [BABEL] Tangling to a hierarchy of files?, Eric Schulte, 2011/01/19
- Re: [Orgmode] [BABEL] Tangling to a hierarchy of files?, Rainer M Krug, 2011/01/19
- Re: [Orgmode] [BABEL] Tangling to a hierarchy of files?, Chris Maier, 2011/01/19
- Re: [Orgmode] [BABEL] Tangling to a hierarchy of files?, Rainer M Krug, 2011/01/19
- Re: [Orgmode] [BABEL] Tangling to a hierarchy of files?, Charles C. Berry, 2011/01/19
- Re: [Orgmode] [BABEL] Tangling to a hierarchy of files?, Chris Maier, 2011/01/19
- Re: [Orgmode] [BABEL] Tangling to a hierarchy of files?,
Eric Schulte <=
- Re: [Orgmode] [BABEL] Tangling to a hierarchy of files?, Chris Maier, 2011/01/19
- Re: [Orgmode] [BABEL] Tangling to a hierarchy of files?, Eric Schulte, 2011/01/19
- Re: [Orgmode] [BABEL] Tangling to a hierarchy of files?, Rainer M Krug, 2011/01/20
- Re: [Orgmode] [BABEL] Tangling to a hierarchy of files?, Chris Maier, 2011/01/20
- Re: [Orgmode] [BABEL] Tangling to a hierarchy of files?, Christopher Witte, 2011/01/20
- Re: [Orgmode] [BABEL] Tangling to a hierarchy of files?, Eric Schulte, 2011/01/20