all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* babel srcname? Calling Library of Babel code?
@ 2015-10-06  3:43 Lawrence Bottorff
  2015-10-06  5:15 ` Thomas S. Dye
  0 siblings, 1 reply; 5+ messages in thread
From: Lawrence Bottorff @ 2015-10-06  3:43 UTC (permalink / raw)
  To: emacs-orgmode Mailinglist

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

Not really getting how to call code "meta-style" from other points -- in my
file, in other files, in my "library of babel" file? I've tracked down bits
and pieces here and there, but I'm missing the big picture.

For example, this:

#+srcname: python2_env
#+begin_src emacs-lisp
  (setq org-babel-python-command "python")
  (set-face-background 'modeline "#4477aa")
#+end_src

#+srcname: python3_env
#+begin_src emacs-lisp
  (setq org-babel-python-command "python3")
  (set-face-background 'modeline "#771944")
#+end_src

Why is #+srcname being used and not just #+name? I assume these blocks will
be called later? I'm also assuming that #+call plays a role, but this page
<http://orgmode.org/manual/Evaluating-code-blocks.html> has no examples and
confused me.

This example
<https://lists.gnu.org/archive/html/emacs-orgmode/2010-09/msg00466.html> again
uses #+srcname:

. . .
* Opening
> #+srcname: opening
> #+begin_src org
> Dear Org mode users,
> #+end_src
. . .
* Closing
> #+srcname: closing
> #+begin_src org
>   Yours Truly
> #+end_src
. . .
and then

. . .
\setupdocument{
>     to = {%
>           <<to>>},
. . .
>     opening = {<<opening>>},
>     closing = {<<closing>>}
> }

I'm guessing the opening and closing are being called. But again, why
srcname and not just name? And what if my blocks had been defined somewhere
outside of this file?

LB

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

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

* Re: babel srcname? Calling Library of Babel code?
  2015-10-06  3:43 babel srcname? Calling Library of Babel code? Lawrence Bottorff
@ 2015-10-06  5:15 ` Thomas S. Dye
  2015-10-06 18:16   ` Lawrence Bottorff
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas S. Dye @ 2015-10-06  5:15 UTC (permalink / raw)
  To: Lawrence Bottorff; +Cc: emacs-orgmode Mailinglist

Aloha Lawrence,

Lawrence Bottorff <borgauf@gmail.com> writes:

> Not really getting how to call code "meta-style" from other points -- in my
> file, in other files, in my "library of babel" file? I've tracked down bits
> and pieces here and there, but I'm missing the big picture.
>
> For example, this:
>
> #+srcname: python2_env
> #+begin_src emacs-lisp
>   (setq org-babel-python-command "python")
>   (set-face-background 'modeline "#4477aa")
> #+end_src
>
> #+srcname: python3_env
> #+begin_src emacs-lisp
>   (setq org-babel-python-command "python3")
>   (set-face-background 'modeline "#771944")
> #+end_src
>
> Why is #+srcname being used and not just #+name? I assume these blocks will
> be called later? I'm also assuming that #+call plays a role, but this page
> <http://orgmode.org/manual/Evaluating-code-blocks.html> has no examples and
> confused me.

During development of Babel, source code blocks were originally named
using #+srcname:.  Later, as other elements gained the ability to be
named, it was decided to use a more generic identifier, #+name:.

The #+call: syntax is confusing to me, too.  I usually put :var
arguments in the <arguments> part, non-:var arguments that change what
the code block does in <inside header arguments>, and non-:var arguments
that affect how the buffer is changed in the <end header arguments>.

>
> This example
> <https://lists.gnu.org/archive/html/emacs-orgmode/2010-09/msg00466.html> again
> uses #+srcname:
>
> . . .
> * Opening
>> #+srcname: opening
>> #+begin_src org
>> Dear Org mode users,
>> #+end_src
> . . .
> * Closing
>> #+srcname: closing
>> #+begin_src org
>>   Yours Truly
>> #+end_src
> . . .
> and then
>
> . . .
> \setupdocument{
>>     to = {%
>>           <<to>>},
> . . .
>>     opening = {<<opening>>},
>>     closing = {<<closing>>}
>> }
>
> I'm guessing the opening and closing are being called. But again, why
> srcname and not just name? And what if my blocks had been defined somewhere
> outside of this file?

The <<foo>> form is noweb reference syntax.  Your example expands the
source code block.  You can get the results of the source code block
with <<opening()>>, which I think is what this example might intend.

If the blocks are defined outside of the file, then where they are
defined is a library of Babel.  You'll need to explicitly load them with
the org-babel-lob-ingest function.  You can have as many libraries of
Babel as you want.

hth,
Tom

-- 
Thomas S. Dye
http://www.tsdye.com

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

* Re: babel srcname? Calling Library of Babel code?
  2015-10-06  5:15 ` Thomas S. Dye
@ 2015-10-06 18:16   ` Lawrence Bottorff
  2015-10-06 18:59     ` Nick Dokos
  2015-10-06 19:00     ` Thomas S. Dye
  0 siblings, 2 replies; 5+ messages in thread
From: Lawrence Bottorff @ 2015-10-06 18:16 UTC (permalink / raw)
  To: emacs-orgmode Mailinglist

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

Thanks for the info, T. Now, if I commit a file of source code blocks to be
"library of babel," how do I then call them? Is there some sort of prefix?

On Tue, Oct 6, 2015 at 5:15 AM, Thomas S. Dye <tsd@tsdye.com> wrote:

> Aloha Lawrence,
>
> Lawrence Bottorff <borgauf@gmail.com> writes:
>
> > Not really getting how to call code "meta-style" from other points -- in
> my
> > file, in other files, in my "library of babel" file? I've tracked down
> bits
> > and pieces here and there, but I'm missing the big picture.
> >
> > For example, this:
> >
> > #+srcname: python2_env
> > #+begin_src emacs-lisp
> >   (setq org-babel-python-command "python")
> >   (set-face-background 'modeline "#4477aa")
> > #+end_src
> >
> > #+srcname: python3_env
> > #+begin_src emacs-lisp
> >   (setq org-babel-python-command "python3")
> >   (set-face-background 'modeline "#771944")
> > #+end_src
> >
> > Why is #+srcname being used and not just #+name? I assume these blocks
> will
> > be called later? I'm also assuming that #+call plays a role, but this
> page
> > <http://orgmode.org/manual/Evaluating-code-blocks.html> has no examples
> and
> > confused me.
>
> During development of Babel, source code blocks were originally named
> using #+srcname:.  Later, as other elements gained the ability to be
> named, it was decided to use a more generic identifier, #+name:.
>
> The #+call: syntax is confusing to me, too.  I usually put :var
> arguments in the <arguments> part, non-:var arguments that change what
> the code block does in <inside header arguments>, and non-:var arguments
> that affect how the buffer is changed in the <end header arguments>.
>
> >
> > This example
> > <https://lists.gnu.org/archive/html/emacs-orgmode/2010-09/msg00466.html>
> again
> > uses #+srcname:
> >
> > . . .
> > * Opening
> >> #+srcname: opening
> >> #+begin_src org
> >> Dear Org mode users,
> >> #+end_src
> > . . .
> > * Closing
> >> #+srcname: closing
> >> #+begin_src org
> >>   Yours Truly
> >> #+end_src
> > . . .
> > and then
> >
> > . . .
> > \setupdocument{
> >>     to = {%
> >>           <<to>>},
> > . . .
> >>     opening = {<<opening>>},
> >>     closing = {<<closing>>}
> >> }
> >
> > I'm guessing the opening and closing are being called. But again, why
> > srcname and not just name? And what if my blocks had been defined
> somewhere
> > outside of this file?
>
> The <<foo>> form is noweb reference syntax.  Your example expands the
> source code block.  You can get the results of the source code block
> with <<opening()>>, which I think is what this example might intend.
>
> If the blocks are defined outside of the file, then where they are
> defined is a library of Babel.  You'll need to explicitly load them with
> the org-babel-lob-ingest function.  You can have as many libraries of
> Babel as you want.
>
> hth,
> Tom
>
> --
> Thomas S. Dye
> http://www.tsdye.com
>

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

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

* Re: babel srcname? Calling Library of Babel code?
  2015-10-06 18:16   ` Lawrence Bottorff
@ 2015-10-06 18:59     ` Nick Dokos
  2015-10-06 19:00     ` Thomas S. Dye
  1 sibling, 0 replies; 5+ messages in thread
From: Nick Dokos @ 2015-10-06 18:59 UTC (permalink / raw)
  To: emacs-orgmode

Lawrence Bottorff <borgauf@gmail.com> writes:

> Thanks for the info, T. Now, if I commit a file of source code blocks to be "library of babel," how do I
> then call them? Is there some sort of prefix?
>

C-h v org-babel-lob-ingest RET

(info "(org) Library of babel")

Also, reading the library-of-babel.org file in the doc directory
of your org-mode installation is helpful.

Nick

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

* Re: babel srcname? Calling Library of Babel code?
  2015-10-06 18:16   ` Lawrence Bottorff
  2015-10-06 18:59     ` Nick Dokos
@ 2015-10-06 19:00     ` Thomas S. Dye
  1 sibling, 0 replies; 5+ messages in thread
From: Thomas S. Dye @ 2015-10-06 19:00 UTC (permalink / raw)
  To: Lawrence Bottorff; +Cc: emacs-orgmode Mailinglist

Aloha Lawrence,

Lawrence Bottorff <borgauf@gmail.com> writes:

> Thanks for the info, T. Now, if I commit a file of source code blocks to be
> "library of babel," how do I then call them? Is there some sort of prefix?

You can name the file as you wish, and you can have as many libraries of
Babel as need be.

I have this code in .emacs to load one of my libraries of Babel:

  (org-babel-lob-ingest "~/org/td-lob.org")

After the library has been "ingested" then you can call the named source
code blocks it contains, just like you would if they were defined in
your working buffer.

hth,
Tom

-- 
Thomas S. Dye
http://www.tsdye.com

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

end of thread, other threads:[~2015-10-06 19:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-06  3:43 babel srcname? Calling Library of Babel code? Lawrence Bottorff
2015-10-06  5:15 ` Thomas S. Dye
2015-10-06 18:16   ` Lawrence Bottorff
2015-10-06 18:59     ` Nick Dokos
2015-10-06 19:00     ` Thomas S. Dye

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.