emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Specifying the tangle filename based on the source filename?
@ 2018-01-28 13:54 Diego Zamboni
  2018-01-28 18:13 ` Jack Henahan
  2018-01-28 20:47 ` Grant Rettke
  0 siblings, 2 replies; 5+ messages in thread
From: Diego Zamboni @ 2018-01-28 13:54 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Diego Zamboni

[-- Attachment #1: Type: text/plain, Size: 915 bytes --]

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_emacs/blob/master/init.org>, https://github.com/zzamboni/dot_elvish/blob/master/rc.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


[-- Attachment #2: Type: text/html, Size: 1472 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Specifying the tangle filename based on the source filename?
  2018-01-28 13:54 Specifying the tangle filename based on the source filename? Diego Zamboni
@ 2018-01-28 18:13 ` Jack Henahan
  2018-01-28 20:15   ` Diego Zamboni
  2018-01-28 20:47 ` Grant Rettke
  1 sibling, 1 reply; 5+ messages in thread
From: Jack Henahan @ 2018-01-28 18:13 UTC (permalink / raw)
  To: emacs-orgmode

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Specifying the tangle filename based on the source filename?
  2018-01-28 18:13 ` Jack Henahan
@ 2018-01-28 20:15   ` Diego Zamboni
  0 siblings, 0 replies; 5+ messages in thread
From: Diego Zamboni @ 2018-01-28 20:15 UTC (permalink / raw)
  To: Jack Henahan; +Cc: Diego Zamboni, emacs-orgmode

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 <jhenahan@me.com> 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 <diego@zzamboni.org> 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
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Specifying the tangle filename based on the source filename?
  2018-01-28 13:54 Specifying the tangle filename based on the source filename? Diego Zamboni
  2018-01-28 18:13 ` Jack Henahan
@ 2018-01-28 20:47 ` Grant Rettke
  2018-01-28 21:07   ` Diego Zamboni
  1 sibling, 1 reply; 5+ messages in thread
From: Grant Rettke @ 2018-01-28 20:47 UTC (permalink / raw)
  To: Diego Zamboni; +Cc: Org-mode

[-- Attachment #1: Type: text/plain, Size: 1080 bytes --]

On Sun, Jan 28, 2018 at 7:54 AM, Diego Zamboni <diego@zzamboni.org> wrote:

> 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 macro, I couldn’t get it to
> work.
>
> #+PROPERTY: header-args :tangle (concat (file-name-sans-extension
(buffer-file-name)) ".el")

#+NAME: org_gcr_2018-01-25_mara_5AA14ABD-5F82-4515-893A-B2370B6F4321
#+BEGIN_SRC emacs-lisp
(message "Text")
#+END_SRC

[-- Attachment #2: Type: text/html, Size: 1850 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Specifying the tangle filename based on the source filename?
  2018-01-28 20:47 ` Grant Rettke
@ 2018-01-28 21:07   ` Diego Zamboni
  0 siblings, 0 replies; 5+ messages in thread
From: Diego Zamboni @ 2018-01-28 21:07 UTC (permalink / raw)
  To: Grant Rettke; +Cc: Diego Zamboni, Org-mode

[-- Attachment #1: Type: text/plain, Size: 1393 bytes --]

Ah, this is exactly what I was looking for. Thanks!

—Diego

> On 28 Jan 2018, at 21:47, Grant Rettke <gcr@wisdomandwonder.com> wrote:
> 
> On Sun, Jan 28, 2018 at 7:54 AM, Diego Zamboni <diego@zzamboni.org <mailto:diego@zzamboni.org>> wrote:
> 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_emacs/blob/master/init.org>, https://github.com/zzamboni/dot_elvish/blob/master/rc.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 <http://init.org/>” in this case). I’ve looked a bit through the manual and although I found the macro, I couldn’t get it to work.
> 
> #+PROPERTY: header-args :tangle (concat (file-name-sans-extension (buffer-file-name)) ".el")
> 
> #+NAME: org_gcr_2018-01-25_mara_5AA14ABD-5F82-4515-893A-B2370B6F4321
> #+BEGIN_SRC emacs-lisp
> (message "Text")
> #+END_SRC
>  
> 


[-- Attachment #2: Type: text/html, Size: 2760 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-01-28 21:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-28 13:54 Specifying the tangle filename based on the source filename? Diego Zamboni
2018-01-28 18:13 ` Jack Henahan
2018-01-28 20:15   ` Diego Zamboni
2018-01-28 20:47 ` Grant Rettke
2018-01-28 21:07   ` Diego Zamboni

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).