emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Is it possible to #+include: src blocks and tangle them too?
@ 2021-04-12 15:35 Ramachandran Lakshmanan
  2021-04-12 21:38 ` Nicolas Goaziou
  2021-04-14  3:23 ` Greg Minshall
  0 siblings, 2 replies; 11+ messages in thread
From: Ramachandran Lakshmanan @ 2021-04-12 15:35 UTC (permalink / raw)
  To: emacs-orgmode

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

I have been wanting to include a number of small Common Lisp snippets in
individual files which I then include into a "master" .org file using:

#+include: "snippet.org" src lisp

Within snippet.org I have a src block such as:

#+NAME: hello_test
#+BEGIN_SRC lisp :tangle yes
(defun hello () :hello)
#+END_SRC

Ideally I would like to have some specific comments that will be part of
the Literate Program I would develop from these individual files.

However, it seems as though tangling doesn't work.  Export does.

I read somewhere that this is not possible in orgmode.  Is this true?  And
if not, can you point me to the right documentation?

Many thanks.

Rama Lakshmanan

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

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

* Re: Is it possible to #+include: src blocks and tangle them too?
  2021-04-12 15:35 Is it possible to #+include: src blocks and tangle them too? Ramachandran Lakshmanan
@ 2021-04-12 21:38 ` Nicolas Goaziou
  2021-04-13  6:31   ` Dr. Arne Babenhauserheide
                     ` (2 more replies)
  2021-04-14  3:23 ` Greg Minshall
  1 sibling, 3 replies; 11+ messages in thread
From: Nicolas Goaziou @ 2021-04-12 21:38 UTC (permalink / raw)
  To: Ramachandran Lakshmanan; +Cc: emacs-orgmode

Hello,

Ramachandran Lakshmanan <rama@tzrl.org> writes:

> I have been wanting to include a number of small Common Lisp snippets in
> individual files which I then include into a "master" .org file using:
>
> #+include: "snippet.org" src lisp
>
> Within snippet.org I have a src block such as:
>

[...]

> I read somewhere that this is not possible in orgmode.  Is this true?  And
> if not, can you point me to the right documentation?

#+include is a keyword specific to export. I doubt it would work with
tangling out of the box.

However, you may try calling `org-export-expand-include-keyword' from
`org-babel-pre-tangle-hook'. Untested.

Regards,
-- 
Nicolas Goaziou


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

* Re: Is it possible to #+include: src blocks and tangle them too?
  2021-04-12 21:38 ` Nicolas Goaziou
@ 2021-04-13  6:31   ` Dr. Arne Babenhauserheide
  2021-04-13  6:59   ` Timothy
  2021-04-14  0:26   ` Kevin M. Stout
  2 siblings, 0 replies; 11+ messages in thread
From: Dr. Arne Babenhauserheide @ 2021-04-13  6:31 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode, Ramachandran Lakshmanan

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


Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Hello,
>
> Ramachandran Lakshmanan <rama@tzrl.org> writes:
>
>> I have been wanting to include a number of small Common Lisp snippets in
>> individual files which I then include into a "master" .org file using:
>>
>> #+include: "snippet.org" src lisp
>>
>> Within snippet.org I have a src block such as:
>>
>
> [...]
>
>> I read somewhere that this is not possible in orgmode.  Is this true?  And
>> if not, can you point me to the right documentation?
>
> #+include is a keyword specific to export. I doubt it would work with
> tangling out of the box.

I tried it but didn’t get it to work. As solution I turned to autotools:

Variable definitions:
https://hg.sr.ht/~arnebab/ews/browse/Hauptdokument/ews30/configure.ac?ref=9b6d7459f2b1#L40
AC_SUBST_FILE(tabelle_kernantriebe)
tabelle_kernantriebe=$srcdir/tabelle-kernantriebe.org

Replacement definition:
https://hg.sr.ht/~arnebab/ews/browse/Hauptdokument/ews30/configure.ac?ref=9b6d7459f2b1#L69
AC_CONFIG_FILES([chargen.org])

Usage:
https://hg.sr.ht/~arnebab/ews/browse/Hauptdokument/ews30/chargen.org.in?ref=9b6d7459f2b1#L552
@tabelle_kernantriebe@

Best wishes,
Arne
-- 
Unpolitisch sein
heißt politisch sein
ohne es zu merken

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 1125 bytes --]

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

* Re: Is it possible to #+include: src blocks and tangle them too?
  2021-04-12 21:38 ` Nicolas Goaziou
  2021-04-13  6:31   ` Dr. Arne Babenhauserheide
@ 2021-04-13  6:59   ` Timothy
  2021-04-14  0:26   ` Kevin M. Stout
  2 siblings, 0 replies; 11+ messages in thread
From: Timothy @ 2021-04-13  6:59 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode, Ramachandran Lakshmanan


Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> #+include is a keyword specific to export. I doubt it would work with
> tangling out of the box.
>
> However, you may try calling `org-export-expand-include-keyword' from
> `org-babel-pre-tangle-hook'. Untested.

Doom has been doing this for a while with config.org tangling:
https://github.com/hlissner/doom-emacs/blob/ce65645fb87ed1b24fb1a46a33f77cf1dcc1c0d5/bin/org-tangle#L155

--
Timothy


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

* Re: Is it possible to #+include: src blocks and tangle them too?
  2021-04-12 21:38 ` Nicolas Goaziou
  2021-04-13  6:31   ` Dr. Arne Babenhauserheide
  2021-04-13  6:59   ` Timothy
@ 2021-04-14  0:26   ` Kevin M. Stout
  2 siblings, 0 replies; 11+ messages in thread
From: Kevin M. Stout @ 2021-04-14  0:26 UTC (permalink / raw)
  To: Ramachandran Lakshmanan; +Cc: emacs-orgmode

On 2021-04-12 23:38, Nicolas Goaziou wrote:

> However, you may try calling `org-export-expand-include-keyword' from
> `org-babel-pre-tangle-hook'. Untested.

I've done this in the past and can verify that it works well.  That said, it by
definition creates cross-talk between org files, with all the potential for name
collisions and the like that that implies.  One could avoid such problems by
adding some kind of prefix to the block names in the included file (maybe
"common/" or "xyzzy-").  (Some kind of automatic prefixing on inclusion might be
cool.)

--Kevin M. Stout


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

* Re: Is it possible to #+include: src blocks and tangle them too?
  2021-04-12 15:35 Is it possible to #+include: src blocks and tangle them too? Ramachandran Lakshmanan
  2021-04-12 21:38 ` Nicolas Goaziou
@ 2021-04-14  3:23 ` Greg Minshall
  2021-04-14  3:48   ` Rama
  1 sibling, 1 reply; 11+ messages in thread
From: Greg Minshall @ 2021-04-14  3:23 UTC (permalink / raw)
  To: Ramachandran Lakshmanan; +Cc: emacs-orgmode

Rama,

another possible solution, though it may not be possible for your setup,
is to "invert" things: centralize all your snippets in snippet.org, with
each *snippet* set to tangle to its individual lisp file.

cheers, Greg


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

* Re: Is it possible to #+include: src blocks and tangle them too?
  2021-04-14  3:23 ` Greg Minshall
@ 2021-04-14  3:48   ` Rama
  2021-04-14  6:33     ` Dr. Arne Babenhauserheide
                       ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Rama @ 2021-04-14  3:48 UTC (permalink / raw)
  To: Greg Minshall; +Cc: emacs-orgmode

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

Thank you, Greg, this is certainly a logical suggestion, but I didn’t explain why I would have these blocks in individual files - I will explain very quickly here.

Basically I am developing my Lisp code using the ASDF package manager and so I have a few different files in a source tree. I haven’t been able to fully work with Donald Knuth’s suggestion of writing a Literate Program directly in a tool like orgmode/noweb since it is a nuisance to keep having to type C-c ' to go into the editing mode of the language concerned.

I also tend to use a mindmapping tool (MindNode on my Mac in my case) since with some specific genetic mental issues I do better with a visual outline than the standard ones even the flexible offering in orgmode itself. I’m fine once I’ve done the brainstorming, and I then will export to OPML and use Pandoc to get an orgmode file.

But what I wanted to do was to insert Javadoc style comments into my Lisp in my original code and I would label each entry with the name of the source code block which also gets named <name>.org in a flat folder.

For example

;;;——
;;; metrics_graph
;;; ——
;;; Textual essay paragraphs
;;; ——
(defun nothing () nil)
;;;——

The above is in metrics_graph.org (http://metrics_graph.org)

All these generated files are styled as a very simple markdown file so that I can read this into MindNode and have a bunch of nodes named with the names of the org snippets as I have called them (confusingly as "snippet" has a different connotation most often).

With these mechanics I can write my Lisp code as I have done for years but I can also have it easily translated into a set of Nodes in MindNode that I can move around graphically with a mouse and create my Literate Program.

Ultimately I have just decided that I will develop my code as normal and then finally just copy and paste it into orgmode especially since now we can select a region and and create a source block around it.

So taking a Lisp file and formatting it for orgmode is not a huge burden - then I will be able to tangle it and I will just then continue to work from the org file if I need to edit and debug the code later on. It just means I will take the code to near completion before trying to work with a Literate Program but I do hope to start using Babel for documenting my work even though I am no longer working in a research setting per se.

Thanks to all for your suggestions - Doom seems a reasonable option - but I will try them all as best I can - I am on my second all nighter though so need some sleep first!

Cheers.

Rama

--
Sent from Canary (https://canarymail.io)

> On Wednesday, Apr 14, 2021 at 4:23 am, Greg Minshall <minshall@umich.edu (mailto:minshall@umich.edu)> wrote:
> Rama,
>
> another possible solution, though it may not be possible for your setup,
> is to "invert" things: centralize all your snippets in snippet.org, with
> each *snippet* set to tangle to its individual lisp file.
>
> cheers, Greg

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

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

* Re: Is it possible to #+include: src blocks and tangle them too?
  2021-04-14  3:48   ` Rama
@ 2021-04-14  6:33     ` Dr. Arne Babenhauserheide
  2021-04-14  6:52     ` Greg Minshall
  2021-04-16 15:27     ` Greg Minshall
  2 siblings, 0 replies; 11+ messages in thread
From: Dr. Arne Babenhauserheide @ 2021-04-14  6:33 UTC (permalink / raw)
  To: Rama; +Cc: Greg Minshall, emacs-orgmode

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


Rama <rama@tzrl.org> writes:
> Ultimately I have just decided that I will develop my code as normal and then finally just copy and paste it into orgmode especially since now we can select a region and and create a source block around it.

Do you know M-x insert-file? That could simplify your workfloww a lot.

Even better could be M-x org-detangle with the :comments link header of
the source-block. When executed in a tangled file, it brings its changes
back into the org-file. I’ve been using it for a site of mine,¹ and it
finally brought specialized-mode development and org-mode together for
me.


¹: https://hg.sr.ht/~arnebab/draketo/browse/anderes/mathe-ass.org?rev=3bc0f27d5471#L284

-- 
Unpolitisch sein
heißt politisch sein
ohne es zu merken

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 1125 bytes --]

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

* Re: Is it possible to #+include: src blocks and tangle them too?
  2021-04-14  3:48   ` Rama
  2021-04-14  6:33     ` Dr. Arne Babenhauserheide
@ 2021-04-14  6:52     ` Greg Minshall
  2021-04-16 15:27     ` Greg Minshall
  2 siblings, 0 replies; 11+ messages in thread
From: Greg Minshall @ 2021-04-14  6:52 UTC (permalink / raw)
  To: Rama; +Cc: emacs-orgmode

Rama,

thanks for your explanation.

Arne Babenhauserheide suggested [M-x org-babel-detangle]; i've not used
it myself, but it seems a possible direction.

cheers, Greg


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

* Re: Is it possible to #+include: src blocks and tangle them too?
  2021-04-14  3:48   ` Rama
  2021-04-14  6:33     ` Dr. Arne Babenhauserheide
  2021-04-14  6:52     ` Greg Minshall
@ 2021-04-16 15:27     ` Greg Minshall
  2021-04-16 21:14       ` Berry, Charles via General discussions about Org-mode.
  2 siblings, 1 reply; 11+ messages in thread
From: Greg Minshall @ 2021-04-16 15:27 UTC (permalink / raw)
  To: Rama; +Cc: emacs-orgmode

Rama,

one other comment/suggestion.

> I haven’t been able to fully work with Donald Knuth’s suggestion of
> writing a Literate Program directly in a tool like orgmode/noweb since
> it is a nuisance to keep having to type C-c ' to go into the editing
> mode of the language concerned.

while i have not much experience with it, you might look at the emacs
packages polymode, poly-org, and poly-whatever-other-languages-you-use.
it seems as if they might give you [C-c ']-like behavior when editing
source blocks in line in an org mode buffer.

(others who use polymode: does this make sense?)

cheers, Greg


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

* Re: Is it possible to #+include: src blocks and tangle them too?
  2021-04-16 15:27     ` Greg Minshall
@ 2021-04-16 21:14       ` Berry, Charles via General discussions about Org-mode.
  0 siblings, 0 replies; 11+ messages in thread
From: Berry, Charles via General discussions about Org-mode. @ 2021-04-16 21:14 UTC (permalink / raw)
  To: Greg Minshall; +Cc: org-mode-email, Rama

Hi Greg,

> On Apr 16, 2021, at 8:27 AM, Greg Minshall <minshall@umich.edu> wrote:
> 
> Rama,
> 
> one other comment/suggestion.
> 
>> I haven’t been able to fully work with Donald Knuth’s suggestion of
>> writing a Literate Program directly in a tool like orgmode/noweb since
>> it is a nuisance to keep having to type C-c ' to go into the editing
>> mode of the language concerned.
> 
> while i have not much experience with it, you might look at the emacs
> packages polymode, poly-org, and poly-whatever-other-languages-you-use.
> it seems as if they might give you [C-c ']-like behavior when editing
> source blocks in line in an org mode buffer.
> 
> (others who use polymode: does this make sense?)


I have tried it a few times, but not had satisfactory results. 

I use mostly R src blocks, so I want to have ESS like functionality. And I really like to be able to execute src blocks with `org-babel-execute-src-block'. 

Unfortunately, it seems like polymode gets into conflicts with org mode from time to time. My memory is a bit dim on exactly the issues, but I think there were freezes. Maybe turning off all the stops and whistles in org mode (like fontification) would solve this, but I never gave it a go. 

Having said that, I will say it is easy enough to install and try out. And perhaps your mileage will vary.

Best,
Chuck


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

end of thread, other threads:[~2021-04-16 22:23 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-12 15:35 Is it possible to #+include: src blocks and tangle them too? Ramachandran Lakshmanan
2021-04-12 21:38 ` Nicolas Goaziou
2021-04-13  6:31   ` Dr. Arne Babenhauserheide
2021-04-13  6:59   ` Timothy
2021-04-14  0:26   ` Kevin M. Stout
2021-04-14  3:23 ` Greg Minshall
2021-04-14  3:48   ` Rama
2021-04-14  6:33     ` Dr. Arne Babenhauserheide
2021-04-14  6:52     ` Greg Minshall
2021-04-16 15:27     ` Greg Minshall
2021-04-16 21:14       ` Berry, Charles via General discussions about Org-mode.

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