emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Include files to be used in literate programming
@ 2010-09-12 17:02 Giorgio Valoti
  2010-09-13 12:47 ` Dan Davison
  2010-09-17 12:51 ` Eric Schulte
  0 siblings, 2 replies; 8+ messages in thread
From: Giorgio Valoti @ 2010-09-12 17:02 UTC (permalink / raw)
  To: emacs-orgmode

Hi all,
I’ve just switched from OmniFocus and began using Org mode. But I also discovered that it can be used for literate programming and I’d like to ask if is there a way to use an included file in the tangling phase. In other words, I have a file which includes a commons.org file, like this:

=== commons.org contents ===
* Variabili comuni
  :PROPERTIES:
  :END:
#+SRCNAME: entity-name
#+BEGIN_SRC :noweb yes
nome_tabella
#+END_SRC


=== main.org contents ===
#+INCLUDE: "commons.org"

* Sezione in SQL
  :PROPERTIES:
  :END:
#+SRCNAME: sql-module
#+BEGIN_SRC sql :tangle module.sql :noweb yes
  select *
  from table <<entity-name>>;
#+END_SRC

<<entity-name>> should come from the commons but it’s not.

Is there a way to expand values from included files?

Thank you in advance.

--
Giorgio Valoti

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

* Re: Include files to be used in literate programming
  2010-09-12 17:02 Include files to be used in literate programming Giorgio Valoti
@ 2010-09-13 12:47 ` Dan Davison
  2010-09-13 15:17   ` Giorgio Valoti
                     ` (2 more replies)
  2010-09-17 12:51 ` Eric Schulte
  1 sibling, 3 replies; 8+ messages in thread
From: Dan Davison @ 2010-09-13 12:47 UTC (permalink / raw)
  To: Giorgio Valoti; +Cc: emacs-orgmode

Giorgio Valoti <giorgio_v@me.com> writes:

> Hi all,
> I’ve just switched from OmniFocus and began using Org mode. But I also discovered that it can be used for literate programming and I’d like to ask if is there a way to use an included file in the tangling phase. In other words, I have a file which includes a commons.org file, like this:
>
> === commons.org contents ===
> * Variabili comuni
>   :PROPERTIES:
>   :END:
> #+SRCNAME: entity-name
> #+BEGIN_SRC :noweb yes
> nome_tabella
> #+END_SRC
>
>
> === main.org contents ===
> #+INCLUDE: "commons.org"
>
> * Sezione in SQL
>   :PROPERTIES:
>   :END:
> #+SRCNAME: sql-module
> #+BEGIN_SRC sql :tangle module.sql :noweb yes
>   select *
>   from table <<entity-name>>;
> #+END_SRC
>
> <<entity-name>> should come from the commons but it’s not.
>
> Is there a way to expand values from included files?

Hi Giorgio,

I don't know of a way currently but I agree that it is desirable. It
does seem temtping to want to use #+INCLUDE for this purpose;
however #+INCLUDE is an /export/ construct, and tangling is not
(technically at least) an Org-mode export method. So some options that
come to my mind are:

1. I am overlooking an existing way of doing this.

2. Implement #+INCLUDE when tangling, optionally or by default.

3. Implement a general way of including blocks of code from other files
   in such a way that they behave as 'normal' code blocks. This would
   have several potentially useful consequences.

4. It seems that it should be possible to get what you want by first
   using `org-export-as-org' followed by `org-babel-tangle'. However,
   `org-export-as-org' doesn't currently include #+INCLUDE'd files. I
   wonder if it should. A hack to do what you want is below (You'll be
   prompted for a file name to save the Org export buffer to.):

#+begin_src emacs-lisp
  (defun ded/org-export-as-org-to-buffer ()
    (interactive)
    (let* ((tmp-file (make-temp-file "org-tangle-with-include"))
           (org-export-preprocess-after-include-files-hook
            `((lambda () (let ((s (buffer-string)))
                           (with-temp-file ,tmp-file (insert s)))))))
      (save-window-excursion (org-export-as-html-to-buffer nil))
      (switch-to-buffer
       (get-buffer-create "*Org Org Export*"))
      (insert-file-contents tmp-file))
    (org-mode))
  
  (defun ded/tangle-with-include-files ()
    (interactive)
    (save-window-excursion
      (ded/org-export-as-org-to-buffer)
      (org-babel-tangle)))
#+end_src

Dan


>
> Thank you in advance.
>
> --
> Giorgio Valoti
>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

* Re: Re: Include files to be used in literate programming
  2010-09-13 12:47 ` Dan Davison
@ 2010-09-13 15:17   ` Giorgio Valoti
  2010-09-13 15:39   ` Rainer M Krug
  2010-09-13 17:05   ` [OT] " Jambunathan K
  2 siblings, 0 replies; 8+ messages in thread
From: Giorgio Valoti @ 2010-09-13 15:17 UTC (permalink / raw)
  To: emacs-orgmode


Il giorno 13/set/2010, alle ore 14.47, Dan Davison ha scritto:

> Giorgio Valoti <giorgio_v@me.com> writes:
> […]
>> 
>> Is there a way to expand values from included files?
> 
> Hi Giorgio,
> 
> I don't know of a way currently but I agree that it is desirable. It
> does seem temtping to want to use #+INCLUDE for this purpose;
> however #+INCLUDE is an /export/ construct, and tangling is not
> (technically at least) an Org-mode export method.

Ah, here’s why.

> So some options that
> come to my mind are:
> 
> 1. I am overlooking an existing way of doing this.
> 
> 2. Implement #+INCLUDE when tangling, optionally or by default.
> 
> 3. Implement a general way of including blocks of code from other files
>   in such a way that they behave as 'normal' code blocks. This would
>   have several potentially useful consequences.

What’s the difference between options 2 and 3? I mean, if we #+INCLUDE when tangling how is it different from including code blocks? Or do you see option 3 as a more granular way to refer to external entities, something comparable to a programming language import statement?


> 
> 4. It seems that it should be possible to get what you want by first
>   using `org-export-as-org' followed by `org-babel-tangle'. However,
>   `org-export-as-org' doesn't currently include #+INCLUDE'd files. I
>   wonder if it should. A hack to do what you want is below (You'll be
>   prompted for a file name to save the Org export buffer to.):

Thank you, Dan. It could be a good enough interim solution.


Ciao
--
Giorgio Valoti

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

* Re: Re: Include files to be used in literate programming
  2010-09-13 12:47 ` Dan Davison
  2010-09-13 15:17   ` Giorgio Valoti
@ 2010-09-13 15:39   ` Rainer M Krug
  2010-09-13 17:05   ` [OT] " Jambunathan K
  2 siblings, 0 replies; 8+ messages in thread
From: Rainer M Krug @ 2010-09-13 15:39 UTC (permalink / raw)
  To: Dan Davison; +Cc: emacs-orgmode, Giorgio Valoti

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 13/09/10 14:47, Dan Davison wrote:
> Giorgio Valoti <giorgio_v@me.com> writes:
> 
>> Hi all,
>> I’ve just switched from OmniFocus and began using Org mode. But I also discovered that it can be used for literate programming and I’d like to ask if is there a way to use an included file in the tangling phase. In other words, I have a file which includes a commons.org file, like this:
>>
>> === commons.org contents ===
>> * Variabili comuni
>>   :PROPERTIES:
>>   :END:
>> #+SRCNAME: entity-name
>> #+BEGIN_SRC :noweb yes
>> nome_tabella
>> #+END_SRC
>>
>>
>> === main.org contents ===
>> #+INCLUDE: "commons.org"
>>
>> * Sezione in SQL
>>   :PROPERTIES:
>>   :END:
>> #+SRCNAME: sql-module
>> #+BEGIN_SRC sql :tangle module.sql :noweb yes
>>   select *
>>   from table <<entity-name>>;
>> #+END_SRC
>>
>> <<entity-name>> should come from the commons but it’s not.
>>
>> Is there a way to expand values from included files?
> 
> Hi Giorgio,
> 
> I don't know of a way currently but I agree that it is desirable. It
> does seem temtping to want to use #+INCLUDE for this purpose;
> however #+INCLUDE is an /export/ construct, and tangling is not
> (technically at least) an Org-mode export method. So some options that
> come to my mind are:
> 
> 1. I am overlooking an existing way of doing this.
> 
> 2. Implement #+INCLUDE when tangling, optionally or by default.

I think that using this option, to include org files using the #INCLUDE
and treat them as if they would be part of the original file would be a
good solution, especially for literate programming - e.g. having often
used code blocks in files, work with "org libraries", ...

The only problem might be header properties defined at the beginning of
the #+INCLUDEd file - they should probably be excluded from the
inclusion. Nevertheless, that could probably be handled by an additional
parameter to #+INCLUDE :

#+INCLUDE externalORGfile.org :headers exclude

where "exclude" is the default.

Rainer

> 
> 3. Implement a general way of including blocks of code from other files
>    in such a way that they behave as 'normal' code blocks. This would
>    have several potentially useful consequences.
> 
> 4. It seems that it should be possible to get what you want by first
>    using `org-export-as-org' followed by `org-babel-tangle'. However,
>    `org-export-as-org' doesn't currently include #+INCLUDE'd files. I
>    wonder if it should. A hack to do what you want is below (You'll be
>    prompted for a file name to save the Org export buffer to.):
> 
> #+begin_src emacs-lisp
>   (defun ded/org-export-as-org-to-buffer ()
>     (interactive)
>     (let* ((tmp-file (make-temp-file "org-tangle-with-include"))
>            (org-export-preprocess-after-include-files-hook
>             `((lambda () (let ((s (buffer-string)))
>                            (with-temp-file ,tmp-file (insert s)))))))
>       (save-window-excursion (org-export-as-html-to-buffer nil))
>       (switch-to-buffer
>        (get-buffer-create "*Org Org Export*"))
>       (insert-file-contents tmp-file))
>     (org-mode))
>   
>   (defun ded/tangle-with-include-files ()
>     (interactive)
>     (save-window-excursion
>       (ded/org-export-as-org-to-buffer)
>       (org-babel-tangle)))
> #+end_src
> 
> Dan
> 
> 
>>
>> Thank you in advance.
>>
>> --
>> Giorgio Valoti
>>
>>
>> _______________________________________________
>> Emacs-orgmode mailing list
>> Please use `Reply All' to send replies to the list.
>> Emacs-orgmode@gnu.org
>> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
> 
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode


- -- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Natural Sciences Building
Office Suite 2039
Stellenbosch University
Main Campus, Merriman Avenue
Stellenbosch
South Africa

Tel:        +33 - (0)9 53 10 27 44
Cell:       +27 - (0)8 39 47 90 42
Fax (SA):   +27 - (0)8 65 16 27 82
Fax (D) :   +49 - (0)3 21 21 25 22 44
Fax (FR):   +33 - (0)9 58 10 27 44
email:      Rainer@krugs.de

Skype:      RMkrug
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkyORcsACgkQoYgNqgF2egoZ0gCfai+D1C/2xCprMdBtUadiSFVs
FLQAn3DPIyem4VMwNglzRJTWeWjn5w/T
=M9XP
-----END PGP SIGNATURE-----

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

* [OT] Re: Include files to be used in literate programming
  2010-09-13 12:47 ` Dan Davison
  2010-09-13 15:17   ` Giorgio Valoti
  2010-09-13 15:39   ` Rainer M Krug
@ 2010-09-13 17:05   ` Jambunathan K
  2010-09-13 18:23     ` Dan Davison
  2 siblings, 1 reply; 8+ messages in thread
From: Jambunathan K @ 2010-09-13 17:05 UTC (permalink / raw)
  To: Dan Davison; +Cc: emacs-orgmode

Dan Davison <davison@stats.ox.ac.uk> writes:

[Warning: OT]

>  tangling is not (technically at least) an Org-mode export method. 

This is an implementation artefact (as you have noted). 

From a user-perspective tangling is a specialized form of export.
Exporting as I see it, is indeed an operation that takes some textual
content and transforms it in to some other content and places it in a
specific location. This is irrespective of whether it is done via C-c
C-e.

[Context Switch]

So 

1. Babel macros are (potential) exporters

2. Exporting need not be just limited to publishing to an external file.

   For example, one could export textual content from one Org headline
   to another Org headline and have them edited on day-to-day basis.

   In some sense exporting is something that an Orgmode user would do
   not as a final step of a note-taking workflow but even in the middle
   of or start of it.

Elsewhere, I have argued that Babel could be easily extended to support
the above broader definition of export.

May be in coming days I should be able to make concrete, code-level
suggestions on that would take my prayers further down in your altar
:-).

Meanwhile I invite you to give my posts some thought ... Dan or Eric
could churn out babel code faster and more effectively than I could
possibly could.

Jambunathan K.

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

* Re: [OT] Re: Include files to be used in literate programming
  2010-09-13 17:05   ` [OT] " Jambunathan K
@ 2010-09-13 18:23     ` Dan Davison
  2010-09-13 19:04       ` Jambunathan K
  0 siblings, 1 reply; 8+ messages in thread
From: Dan Davison @ 2010-09-13 18:23 UTC (permalink / raw)
  To: Jambunathan K; +Cc: emacs-orgmode

Jambunathan K <kjambunathan@gmail.com> writes:

> Dan Davison <davison@stats.ox.ac.uk> writes:
>
> [Warning: OT]
>
>>  tangling is not (technically at least) an Org-mode export method. 
>
> This is an implementation artefact (as you have noted). 
>
>From a user-perspective tangling is a specialized form of export.

I think I agree with that. I wonder if it would be helpful to more
formally recognise tangling as a form of export. For example, in one of
the other threads, you were talking about selective tangling. If
tangling were treated as a form of export, presumably that would mean
that tangling would obey the tag-based selective export mechanisms
(variables org-export-select-tags and org-export-exclude-tags), and also
that #+INCLUDE would have the semantics expected by the OP.

[...]

> May be in coming days I should be able to make concrete, code-level
> suggestions on that would take my prayers further down in your altar
> :-).

I've certainly read your recent series of emails and the resulting
discussion. But of course time is the major limiting factor, and I
haven't yet managed to properly get my head round the various ideas that
have been discussed. Would you be able to provide a brief summary of the
series of emails? If you could identify one or a few core proposal(s)
and be explicit about exactly what changes in behaviour you're
suggesting, and whether they would be backwards compatible, that could
be very helpful.

Dan

>
> Meanwhile I invite you to give my posts some thought ... Dan or Eric
> could churn out babel code faster and more effectively than I could
> possibly could.
>
> Jambunathan K.

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

* Re: [OT] Re: Include files to be used in literate programming
  2010-09-13 18:23     ` Dan Davison
@ 2010-09-13 19:04       ` Jambunathan K
  0 siblings, 0 replies; 8+ messages in thread
From: Jambunathan K @ 2010-09-13 19:04 UTC (permalink / raw)
  To: Dan Davison; +Cc: emacs-orgmode

Dan Davison <davison@stats.ox.ac.uk> writes:

>> May be in coming days I should be able to make concrete, code-level
>> suggestions on that would take my prayers further down in your altar
>> :-).
>
> Would you be able to provide a brief summary of the
> series of emails? If you could identify one or a few core proposal(s)
> and be explicit about exactly what changes in behaviour you're
> suggesting, and whether they would be backwards compatible, that could
> be very helpful.

I will definitely do so. 

That said, I have essentially taken an 'example driven approach'. I have
taken user requests that have occurred on this list [1] (which seemed
one-off or export oriented) and asked the following questions -

1. Can I use Babel Src blocks (atleast in theory) to achieve this? What
   changes are required in the Org/Babel core to do it?

2. Can it be expressed in a syntax that is no different from one that
   the org users are already familiar with.

I will followup on my earlier posts with greater clarity ... 

Footnotes :

[1] I have provided links to example user stories in all my earlier
posts. They, IMHO, are potential candidates that could guide one to
expanding Babel in little (if not profound) ways.

Jambunathan K.

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

* Re: Include files to be used in literate programming
  2010-09-12 17:02 Include files to be used in literate programming Giorgio Valoti
  2010-09-13 12:47 ` Dan Davison
@ 2010-09-17 12:51 ` Eric Schulte
  1 sibling, 0 replies; 8+ messages in thread
From: Eric Schulte @ 2010-09-17 12:51 UTC (permalink / raw)
  To: Giorgio Valoti; +Cc: emacs-orgmode

Hi Giorgio,

This is currently not possible as we're not currently expanding
#+include links during tangling.  I agree this would be useful behavior.

This seems to be related to a recent theme on the mailing list of
unifying tangling with the rest of the Org-mode export functionality.
Once/if tangling were treated as an export target, then things like the
expansion of #+include lines would come for free.

Thanks for bringing this up, this will be an important point to keep in
mind while figuring out the future of tangling.

Best -- Eric

Giorgio Valoti <giorgio_v@me.com> writes:

> Hi all,
> I’ve just switched from OmniFocus and began using Org mode. But I also
> discovered that it can be used for literate programming and I’d like
> to ask if is there a way to use an included file in the tangling
> phase. In other words, I have a file which includes a commons.org
> file, like this:
>
> === commons.org contents ===
> * Variabili comuni
>   :PROPERTIES:
>   :END:
> #+SRCNAME: entity-name
> #+BEGIN_SRC :noweb yes
> nome_tabella
> #+END_SRC
>
>
> === main.org contents ===
> #+INCLUDE: "commons.org"
>
> * Sezione in SQL
>   :PROPERTIES:
>   :END:
> #+SRCNAME: sql-module
> #+BEGIN_SRC sql :tangle module.sql :noweb yes
>   select *
>   from table <<entity-name>>;
> #+END_SRC
>
> <<entity-name>> should come from the commons but it’s not.
>
> Is there a way to expand values from included files?
>
> Thank you in advance.
>
> --
> Giorgio Valoti
>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

end of thread, other threads:[~2010-09-17 14:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-12 17:02 Include files to be used in literate programming Giorgio Valoti
2010-09-13 12:47 ` Dan Davison
2010-09-13 15:17   ` Giorgio Valoti
2010-09-13 15:39   ` Rainer M Krug
2010-09-13 17:05   ` [OT] " Jambunathan K
2010-09-13 18:23     ` Dan Davison
2010-09-13 19:04       ` Jambunathan K
2010-09-17 12:51 ` Eric Schulte

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