emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Org babel with multiple linked segments of source code
@ 2011-03-22  2:57 Nicholas Patrick
  2011-03-23  2:57 ` Eric Schulte
  0 siblings, 1 reply; 4+ messages in thread
From: Nicholas Patrick @ 2011-03-22  2:57 UTC (permalink / raw)
  To: emacs-orgmode

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

I'm trying to figure out how to minimize the overhead with using babel to
write some segments of code.  I find myself writing short segments of a set
of functionality, then writing a collector source block which is referred to
later on in the code... e.g.

*********************
#+srcname: test1
#+begin_src clojure :tangle test1.clj :exports none :noweb yes
blah
<<test2>>
blah
#+end_src

#+srcname: test2
#+begin_src clojure
foo
#+end_src

#+srcname: test2
#+begin_src clojure
bar
#+end_src
*********************
I'd like to see
blah
foo
bar
blah

but I see
blah
foo
blah

What I'd like to see is a single srcname for the code that just concatenates
the two different sections when it is referred by <<descriptive-name>>.
That way I don't have to come up with different names and collectors and so
on and so forth.  Maybe I'm just not doing "literate programming" right, but
when I'm hacking stuff together, I'd like to minimize the housekeeping.
e.g.

Is there a way to do this?

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

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

* Re: Org babel with multiple linked segments of source code
  2011-03-22  2:57 Org babel with multiple linked segments of source code Nicholas Patrick
@ 2011-03-23  2:57 ` Eric Schulte
  2011-03-25 14:12   ` Nicholas Patrick
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Schulte @ 2011-03-23  2:57 UTC (permalink / raw)
  To: Nicholas Patrick; +Cc: emacs-orgmode

Hi,

The setup you suggest below is not currently supported.  I fear
implementing such a system could have some odd semantic extensions into
other parts of Org-mode code blocks, for example, would it then make
sense for the results of a code block to be collected over all code
blocks with that name?  For example,

#+source: test2
#+begin_src emacs-lisp
  1
#+end_src

#+source: test2
#+begin_src emacs-lisp
  2
#+end_src

#+begin_src emacs-lisp :var data=test2
  data
#+end_src

#+results:
| 1 | 2 |

Maybe, but this is certainly not possible under the current setup.

Anyways, back to your use case, maybe it would be equally convenient to
simply have a number of sequential code blocks in the Org-mode file all
tangle out, as they will be placed in the tangled file in the order they
appear in the Org-mode file, so your example below could be changed
to...

** tangling example
   :PROPERTIES:
   :tangle:   test1.clj
   :exports:  none
   :END:

#+begin_src clojure
  blah
#+end_src

#+begin_src clojure
  foo
#+end_src

#+begin_src clojure
  bar
#+end_src

#+begin_src clojure
  blah
#+end_src

While not the same as what you suggested this may be sufficient.

Best -- Eric

Nicholas Patrick <npatrick04@gmail.com> writes:

> I'm trying to figure out how to minimize the overhead with using babel to
> write some segments of code.  I find myself writing short segments of a set
> of functionality, then writing a collector source block which is referred to
> later on in the code... e.g.
>
> *********************
> #+srcname: test1
> #+begin_src clojure :tangle test1.clj :exports none :noweb yes
> blah
> <<test2>>
> blah
> #+end_src
>
> #+srcname: test2
> #+begin_src clojure
> foo
> #+end_src
>
> #+srcname: test2
> #+begin_src clojure
> bar
> #+end_src
> *********************
> I'd like to see
> blah
> foo
> bar
> blah
>
> but I see
> blah
> foo
> blah
>
> What I'd like to see is a single srcname for the code that just concatenates
> the two different sections when it is referred by <<descriptive-name>>.
> That way I don't have to come up with different names and collectors and so
> on and so forth.  Maybe I'm just not doing "literate programming" right, but
> when I'm hacking stuff together, I'd like to minimize the housekeeping.
> e.g.
>
> Is there a way to do this?

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

* Re: Org babel with multiple linked segments of source code
  2011-03-23  2:57 ` Eric Schulte
@ 2011-03-25 14:12   ` Nicholas Patrick
  2011-03-29 14:09     ` Eric Schulte
  0 siblings, 1 reply; 4+ messages in thread
From: Nicholas Patrick @ 2011-03-25 14:12 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode

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

I may try playing around with the sequential sections...since that's how I'm
currently writing the majority of this file.  Most of the pieces of code are
simply defining functions that call other functions or macros and wouldn't
be executed alone.  However, I'm defining other blocks as tests for the
functional sections.  So I might do the following:

#+source: functional-definitions
#+begin_src emacs-lisp
(defn f1
#+end_src

#+source: functional-definitions
#+begin_src emacs-lisp
(defn f2
#+end_src

#+begin_src emacs-lisp
<<functional-definitions>>
(def xyz (f1 (f2 foo))) ; produces bar
#+end_src

#+results:
| bar |

I'm still pretty new to using babel, so I haven't figured out much other
than the basic tangling capability.  Maybe my example could be accomplished
with something like a ':concatenate yes' option on the
functional-definitions blocks.

On Tue, Mar 22, 2011 at 9:57 PM, Eric Schulte <schulte.eric@gmail.com>wrote:

> Hi,
>
> The setup you suggest below is not currently supported.  I fear
> implementing such a system could have some odd semantic extensions into
> other parts of Org-mode code blocks, for example, would it then make
> sense for the results of a code block to be collected over all code
> blocks with that name?  For example,
>
> #+source: test2
> #+begin_src emacs-lisp
>  1
> #+end_src
>
> #+source: test2
> #+begin_src emacs-lisp
>  2
> #+end_src
>
> #+begin_src emacs-lisp :var data=test2
>  data
> #+end_src
>
> #+results:
> | 1 | 2 |
>
> Maybe, but this is certainly not possible under the current setup.
>
> Anyways, back to your use case, maybe it would be equally convenient to
> simply have a number of sequential code blocks in the Org-mode file all
> tangle out, as they will be placed in the tangled file in the order they
> appear in the Org-mode file, so your example below could be changed
> to...
>
> ** tangling example
>   :PROPERTIES:
>    :tangle:   test1.clj
>   :exports:  none
>    :END:
>
> #+begin_src clojure
>  blah
> #+end_src
>
> #+begin_src clojure
>  foo
> #+end_src
>
> #+begin_src clojure
>  bar
> #+end_src
>
> #+begin_src clojure
>  blah
> #+end_src
>
> While not the same as what you suggested this may be sufficient.
>
> Best -- Eric
>
> Nicholas Patrick <npatrick04@gmail.com> writes:
>
> > I'm trying to figure out how to minimize the overhead with using babel to
> > write some segments of code.  I find myself writing short segments of a
> set
> > of functionality, then writing a collector source block which is referred
> to
> > later on in the code... e.g.
> >
> > *********************
> > #+srcname: test1
> > #+begin_src clojure :tangle test1.clj :exports none :noweb yes
> > blah
> > <<test2>>
> > blah
> > #+end_src
> >
> > #+srcname: test2
> > #+begin_src clojure
> > foo
> > #+end_src
> >
> > #+srcname: test2
> > #+begin_src clojure
> > bar
> > #+end_src
> > *********************
> > I'd like to see
> > blah
> > foo
> > bar
> > blah
> >
> > but I see
> > blah
> > foo
> > blah
> >
> > What I'd like to see is a single srcname for the code that just
> concatenates
> > the two different sections when it is referred by <<descriptive-name>>.
> > That way I don't have to come up with different names and collectors and
> so
> > on and so forth.  Maybe I'm just not doing "literate programming" right,
> but
> > when I'm hacking stuff together, I'd like to minimize the housekeeping.
> > e.g.
> >
> > Is there a way to do this?
>
>

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

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

* Re: Org babel with multiple linked segments of source code
  2011-03-25 14:12   ` Nicholas Patrick
@ 2011-03-29 14:09     ` Eric Schulte
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Schulte @ 2011-03-29 14:09 UTC (permalink / raw)
  To: Nicholas Patrick; +Cc: emacs-orgmode

Nicholas Patrick <npatrick04@gmail.com> writes:

> I may try playing around with the sequential sections...since that's how I'm
> currently writing the majority of this file.  Most of the pieces of code are
> simply defining functions that call other functions or macros and wouldn't
> be executed alone.  However, I'm defining other blocks as tests for the
> functional sections.  So I might do the following:
>

Maybe you could try either putting all of your functional definitions
into a single large code block, or you could write all of your functions
in their own named code blocks

#+source: foo1
#+begin_src emacs-lisp
  (deufn foo1 () :foo1)
#+end_src

#+source: foo2
#+begin_src emacs-lisp
  (deufn foo1 () :foo2)
#+end_src

and then use a single "functional-definitions" code block to collect all
of these functional definitions

#+source: functional-definitions
#+begin_src emacs-lisp
  <<foo1>>
  <<foo2>>
#+end_src

this single code block could then be easily included in other code
blocks.

#+begin_src emacs-lisp
  <<functional-definitions>>
  (def xyz (f1 (f2 foo))) ; produces bar
#+end_src

#+results:
: bar

I know this isn't exactly what you were after, but it does work under
the current system.  I'd be interested to hear if other LP systems have
something analogous to a "concatenate" function...

Best -- Eric

>
> #+source: functional-definitions
> #+begin_src emacs-lisp
> (defn f1
> #+end_src
>
> #+source: functional-definitions
> #+begin_src emacs-lisp
> (defn f2
> #+end_src
>
> #+begin_src emacs-lisp
> <<functional-definitions>>
> (def xyz (f1 (f2 foo))) ; produces bar
> #+end_src
>
> #+results:
> | bar |
>
> I'm still pretty new to using babel, so I haven't figured out much other
> than the basic tangling capability.  Maybe my example could be accomplished
> with something like a ':concatenate yes' option on the
> functional-definitions blocks.
>
> On Tue, Mar 22, 2011 at 9:57 PM, Eric Schulte <schulte.eric@gmail.com>wrote:
>
>> Hi,
>>
>> The setup you suggest below is not currently supported.  I fear
>> implementing such a system could have some odd semantic extensions into
>> other parts of Org-mode code blocks, for example, would it then make
>> sense for the results of a code block to be collected over all code
>> blocks with that name?  For example,
>>
>> #+source: test2
>> #+begin_src emacs-lisp
>>  1
>> #+end_src
>>
>> #+source: test2
>> #+begin_src emacs-lisp
>>  2
>> #+end_src
>>
>> #+begin_src emacs-lisp :var data=test2
>>  data
>> #+end_src
>>
>> #+results:
>> | 1 | 2 |
>>
>> Maybe, but this is certainly not possible under the current setup.
>>
>> Anyways, back to your use case, maybe it would be equally convenient to
>> simply have a number of sequential code blocks in the Org-mode file all
>> tangle out, as they will be placed in the tangled file in the order they
>> appear in the Org-mode file, so your example below could be changed
>> to...
>>
>> ** tangling example
>>   :PROPERTIES:
>>    :tangle:   test1.clj
>>   :exports:  none
>>    :END:
>>
>> #+begin_src clojure
>>  blah
>> #+end_src
>>
>> #+begin_src clojure
>>  foo
>> #+end_src
>>
>> #+begin_src clojure
>>  bar
>> #+end_src
>>
>> #+begin_src clojure
>>  blah
>> #+end_src
>>
>> While not the same as what you suggested this may be sufficient.
>>
>> Best -- Eric
>>
>> Nicholas Patrick <npatrick04@gmail.com> writes:
>>
>> > I'm trying to figure out how to minimize the overhead with using babel to
>> > write some segments of code.  I find myself writing short segments of a
>> set
>> > of functionality, then writing a collector source block which is referred
>> to
>> > later on in the code... e.g.
>> >
>> > *********************
>> > #+srcname: test1
>> > #+begin_src clojure :tangle test1.clj :exports none :noweb yes
>> > blah
>> > <<test2>>
>> > blah
>> > #+end_src
>> >
>> > #+srcname: test2
>> > #+begin_src clojure
>> > foo
>> > #+end_src
>> >
>> > #+srcname: test2
>> > #+begin_src clojure
>> > bar
>> > #+end_src
>> > *********************
>> > I'd like to see
>> > blah
>> > foo
>> > bar
>> > blah
>> >
>> > but I see
>> > blah
>> > foo
>> > blah
>> >
>> > What I'd like to see is a single srcname for the code that just
>> concatenates
>> > the two different sections when it is referred by <<descriptive-name>>.
>> > That way I don't have to come up with different names and collectors and
>> so
>> > on and so forth.  Maybe I'm just not doing "literate programming" right,
>> but
>> > when I'm hacking stuff together, I'd like to minimize the housekeeping.
>> > e.g.
>> >
>> > Is there a way to do this?
>>
>>

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

end of thread, other threads:[~2011-03-29 14:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-22  2:57 Org babel with multiple linked segments of source code Nicholas Patrick
2011-03-23  2:57 ` Eric Schulte
2011-03-25 14:12   ` Nicholas Patrick
2011-03-29 14:09     ` 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).