Re: [O] Babel: How to call code in one org file into another org file

2015-11-02 Thread Nick Dokos
Eric S Fraga  writes:

> On Saturday, 31 Oct 2015 at 16:51, Lawrence Bottorff wrote:
>> I guess I'm saying that the whole `org-babel-lob-ingest` into
>> `org-babel-library-of-babel` exercise should make code ready and available.
>
> But it does.  There are two levels here: the babel codes and the results
> of the codes.  If your babel codes are emacs which define functions,
> these latter functions are not available until the babel codes are
> executed.  However, the babel codes are now there and ready to be
> executed by name.
>
> I would not want ingest to execute the codes for two reasons: many of
> the codes do not make sense without special arguments and there may be
> many such codes.

Indeed - and just to amplify this a bit, you can arrange (and it's
arguably "better" if you have files whose code blocks you want to reuse)
for all the relevant files to be in org-babel-library-of-babel during
initialization; you do not *need* to have them added through the Local
Variables trick: just add org-babel-lob-ingest calls to .emacs.

You can also add the block evaluations in your .emacs, but that is
probably a bad idea as Eric points out. Instead, use Local Variables
with

eval: (org-sbe "foo")

calls to evaluate just what you need for the current buffer (and make
sure that the relevant inferior process running the language interpreter
is started *before* you open the file: emacs-lisp is exempt, since
it's always there).

The difference of opinion arises in the interpretation of "ready and
available". The LOB in this case (and maybe in all cases, but I haven't
used it often enough to be able to make such a statement) behaves more
like an #include file in C, rather than a library of precompiled code
that you link against (think libc.so or equivalent): you need to
"compile" (i.e. evaluate) the code block before it becomes available
to your code.

-- 
Nick




Re: [O] Babel: How to call code in one org file into another org file

2015-11-01 Thread Eric S Fraga
On Saturday, 31 Oct 2015 at 16:51, Lawrence Bottorff wrote:
> I guess I'm saying that the whole `org-babel-lob-ingest` into
> `org-babel-library-of-babel` exercise should make code ready and available.

But it does.  There are two levels here: the babel codes and the results
of the codes.  If your babel codes are emacs which define functions,
these latter functions are not available until the babel codes are
executed.  However, the babel codes are now there and ready to be
executed by name.

I would not want ingest to execute the codes for two reasons: many of
the codes do not make sense without special arguments and there may be
many such codes.

-- 
: Eric S Fraga (0xFFFCF67D), Emacs 24.5.1, Org release_8.3.2-215-gb4af3f



Re: [O] Babel: How to call code in one org file into another org file

2015-10-31 Thread Rasmus
Hi Lawrence,

Lawrence Bottorff  writes:

> There are many, many Babel examples, but I can't seem to find this
> functionality: A function in a Lisp code block in one org file is to be
> called from a Lisp code block in another org file. Is this possible? I know
> you can stick stuff into your personal "Library of Babel," but I just want
> to write a Lisp block that calls a function from another org file. I'll
> have SLIME running, of course.
>
>
> file1.org:
> ...
>
>  #+begin_src lisp
> (defun foo ()
>(...))
> #+end_src
>
> file2.org:
> ...
>
> #+begin_src lisp
> (defun baa ()
>   (foo))
> #+end_src

At export time you could include a named block, but I’m not really sure
that gets you closer to what you want.

E.g. in file 1,

#+name: fun_foo 
#+begin_src lisp
(defun foo ()
   (...))
#+end_src

In file 2,

#+include: "file1.org::fun_foo"

#+begin_src lisp
(defun baa ()
  (foo))
#+end_src

Rasmus

-- 
Spil noget med Slayer!




Re: [O] Babel: How to call code in one org file into another org file

2015-10-31 Thread Lawrence Bottorff
I guess I'm saying that the whole `org-babel-lob-ingest` into
`org-babel-library-of-babel` exercise should make code ready and available.
Otherwise (especially with the extra `org-babel-lob-ingest` in Local
Variable step I mentioned), what John Kitchin suggested with
`org-babel-load-file` is just as good, i.e., LOB seems hardly worth it. My
whole motivation is to avoid having to scroll through endless code blocks
all on the same level, rather, to have things more modular and distributed,
a bit like DDLs in MS-land.

On Sat, Oct 31, 2015 at 4:34 PM, Nick Dokos  wrote:

> Lawrence Bottorff  writes:
>
> > Yes, I experimented with this too -- and got it to work. But strangely,
> if you leave out the
> >
> > # eval: (org-babel-lob-ingest "./a.org")
> > # eval: (org-babel-lob-ingest "./b.org")
> >
> > lines and do a regular `org-babel-lob-ingest` (or  C-c C-v i) on those
> > two files -- it doesn't work. Rather bizarre behavior, IMHO.
> >
>
> I think you have some misconceptions about what org-babel-lob-ingest
> does. All it does is go through the file and add the named source
> blocks in that file to org-babel-library-of-babel: it does *not*
> evaluate the code blocks. So if the code block is e.g. a lisp code
> block with a defun in it, the function is *not* defined, until the
> code block is evaluated by org-babel: that's what org-sbe does.
>
> > Anyway, the dream behavior for LOB would be to simply add your files to
> your `org-babel-lob-files` in your Emacs init, start up an org file -- and
> be able to simply use all the LOB
> > files in your "live" `org-babel-library-of-babel` list library.
> >
>
> You can do that but again all that does is populate a list that
> only org-babel knows about. You'd still need to evaluate the code
> blocks in order to tell the inferior lisp process about what the
> code block define.
>
> --
> Nick
>
>
>


Re: [O] Babel: How to call code in one org file into another org file

2015-10-31 Thread Nick Dokos
Lawrence Bottorff  writes:

> Yes, I experimented with this too -- and got it to work. But strangely, if 
> you leave out the 
>
> # eval: (org-babel-lob-ingest "./a.org")
> # eval: (org-babel-lob-ingest "./b.org")
>
> lines and do a regular `org-babel-lob-ingest` (or  C-c C-v i) on those
> two files -- it doesn't work. Rather bizarre behavior, IMHO.
>

I think you have some misconceptions about what org-babel-lob-ingest
does. All it does is go through the file and add the named source
blocks in that file to org-babel-library-of-babel: it does *not*
evaluate the code blocks. So if the code block is e.g. a lisp code
block with a defun in it, the function is *not* defined, until the
code block is evaluated by org-babel: that's what org-sbe does.

> Anyway, the dream behavior for LOB would be to simply add your files to your 
> `org-babel-lob-files` in your Emacs init, start up an org file -- and be able 
> to simply use all the LOB
> files in your "live" `org-babel-library-of-babel` list library.
>

You can do that but again all that does is populate a list that
only org-babel knows about. You'd still need to evaluate the code
blocks in order to tell the inferior lisp process about what the
code block define.

-- 
Nick




Re: [O] Babel: How to call code in one org file into another org file

2015-10-31 Thread Nick Dokos
Lawrence Bottorff  writes:

> I would use local variables for this--something like (untested):
>
> # eval: (org-babel-lob-ingest path/to/your/file)
> # eval: (sbe "my-add")
> # eval: (sbe "multi_x2")
>
> Computer savvy Org moders don't like eval because anything can happen,
> but if you're willing to trust yourself, then it shouldn't cause any
> problems.
>
> With this near the bottom of your file, whenever you open the file your
> other org files will be loaded into the Library of Babel where you can
> load up function definitions as needed.
>
> Of course, you'll need to have slime running when you open the file.
>
> hth,
> Tom
>
> Thanks Tom. Still, I'm wondering if the whole LOB is worth it in
> Lisp/SLIME-land. I can load code with org-babel-lob-ingest into
> `org-babel-library-of-babel`, but SLIME doesn't seem to know about it
> -- which sort of defeats the whole purpose, if you follow what I
> mean. . . . 
>

You got me all curious to see where things break: I had to install slime
and clisp to find out. Everything is working I think: nothing is broken.

As long as you are willing to add Tom's initialization (slightly
modified - the function I have is org-sbe rather than sbe - I guess Tom
has defined sbe in his own setup for backward-compatibility purposes),
the following process works for me.

Here's what I added to my .emacs:

--8<---cut here---start->8---
(setq inferior-lisp-program "/usr/bin/clisp")

;;; start it  - it's important to start slime *before*
;;; you load the c.org file below.
(slime)

(require 'ob-lisp)
--8<---cut here---end--->8---

a.org and b.org are just as you defined them:

--8<---cut here---start->8---
#+name: myadd
#+begin_src lisp :session foo
(defun myadd (x y)
 (+ x y))
#+end_src
--8<---cut here---end--->8---

--8<---cut here---start->8---
#+name: multi_x2
#+begin_src lisp :session
(defun multi_x2 (x)
  (* 2 x))
#+end_src
--8<---cut here---end--->8---

and c.org with Tom's modifications looks like this:

--8<---cut here---start->8---
#+name: add_x2
#+begin_src lisp :session
(defun add_x2 (x y)
 (multi_x2 (myadd x y)))
#+end_src

#+BEGIN_SRC lisp :session
  (add_x2 2 3)
#+END_SRC

# Local Variables:
# eval: (org-babel-lob-ingest "./a.org")
# eval: (org-babel-lob-ingest "./b.org")
# eval: (org-sbe "myadd")
# eval: (org-sbe "multi_x2")
# End:
--8<---cut here---end--->8---

Evaluation of the two code block in c.org proceeds correctly and without
problems.

-- 
Nick




Re: [O] Babel: How to call code in one org file into another org file

2015-10-31 Thread Lawrence Bottorff
Yes, I experimented with this too -- and got it to work. But strangely, if
you leave out the

# eval: (org-babel-lob-ingest "./a.org")
# eval: (org-babel-lob-ingest "./b.org")

lines and do a regular `org-babel-lob-ingest` (or  C-c C-v i) on those two
files -- *it doesn't work. *Rather bizarre behavior, IMHO.

Anyway, the dream behavior for LOB would be to simply add your files to
your `org-babel-lob-files` in your Emacs init, start up an org file -- and
be able to simply use all the LOB files in your "live"
`org-babel-library-of-babel` list library.


[O] Babel: How to call code in one org file into another org file

2015-10-30 Thread Lawrence Bottorff
There are many, many Babel examples, but I can't seem to find this
functionality: A function in a Lisp code block in one org file is to be
called from a Lisp code block in another org file. Is this possible? I know
you can stick stuff into your personal "Library of Babel," but I just want
to write a Lisp block that calls a function from another org file. I'll
have SLIME running, of course.


file1.org:
...
 #+begin_src lisp
(defun foo ()
   (...))
#+end_src

is then called from. . .

file2.org:
...
#+begin_src lisp
(defun baa ()
  (foo))
#+end_src


LB


Re: [O] Babel: How to call code in one org file into another org file

2015-10-30 Thread Thomas S . Dye
Aloha Lawrence,

Lawrence Bottorff  writes:

> There are many, many Babel examples, but I can't seem to find this
> functionality: A function in a Lisp code block in one org file is to be
> called from a Lisp code block in another org file. Is this possible? I know
> you can stick stuff into your personal "Library of Babel," but I just want
> to write a Lisp block that calls a function from another org file. I'll
> have SLIME running, of course.
>
>
> file1.org:
> ...
>  #+begin_src lisp
> (defun foo ()
>(...))
> #+end_src
>
> is then called from. . .
>
> file2.org:
> ...
> #+begin_src lisp
> (defun baa ()
>   (foo))
> #+end_src

Any Org mode file can function as Library of Babel.  In your case,
(org-babel-lob-ingest path/to/file1.org) should do what you want.  Note
that org-babel-lob-ingest is bound to C-c C-v i.

hth,
Tom

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



Re: [O] Babel: How to call code in one org file into another org file

2015-10-30 Thread briangpowell .
Could create a named pipe and have one org-mode file write to it and
another org-mode file read from it.

On Fri, Oct 30, 2015 at 4:55 PM, Thomas S. Dye  wrote:

> Aloha Lawrence,
>
> Lawrence Bottorff  writes:
>
> > There are many, many Babel examples, but I can't seem to find this
> > functionality: A function in a Lisp code block in one org file is to be
> > called from a Lisp code block in another org file. Is this possible? I
> know
> > you can stick stuff into your personal "Library of Babel," but I just
> want
> > to write a Lisp block that calls a function from another org file. I'll
> > have SLIME running, of course.
> >
> >
> > file1.org:
> > ...
> >  #+begin_src lisp
> > (defun foo ()
> >(...))
> > #+end_src
> >
> > is then called from. . .
> >
> > file2.org:
> > ...
> > #+begin_src lisp
> > (defun baa ()
> >   (foo))
> > #+end_src
>
> Any Org mode file can function as Library of Babel.  In your case,
> (org-babel-lob-ingest path/to/file1.org) should do what you want.  Note
> that org-babel-lob-ingest is bound to C-c C-v i.
>
> hth,
> Tom
>
> --
> Thomas S. Dye
> http://www.tsdye.com
>
>


Re: [O] Babel: How to call code in one org file into another org file

2015-10-30 Thread John Kitchin
I don't think this is possible. You probably need some tangling and
loading to make it happen the way I understand it.

Lawrence Bottorff writes:

> There are many, many Babel examples, but I can't seem to find this
> functionality: A function in a Lisp code block in one org file is to be
> called from a Lisp code block in another org file. Is this possible? I know
> you can stick stuff into your personal "Library of Babel," but I just want
> to write a Lisp block that calls a function from another org file. I'll
> have SLIME running, of course.
>
>
> file1.org:
> ...
>  #+begin_src lisp
> (defun foo ()
>(...))
> #+end_src
>
> is then called from. . .
>
> file2.org:
> ...
> #+begin_src lisp
> (defun baa ()
>   (foo))
> #+end_src
>
>
> LB

--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu



Re: [O] Babel: How to call code in one org file into another org file

2015-10-30 Thread John Kitchin
Odd. I found this I wrote before 
http://kitchingroup.cheme.cmu.edu/blog/2014/06/24/Using-org-files-like-el-files/

What org version do you have?

On October 30, 2015, at 10:15 PM, Lawrence Bottorff  wrote:

@John Kitchin: I can't seem to find a `org-babel-load-file`.

 




Re: [O] Babel: How to call code in one org file into another org file

2015-10-30 Thread Lawrence Bottorff
Org-mode version 8.3.2 (8.3.2-10-g00dacd-elpa @
../.emacs.d/elpa/org-20151005/)

Did you all see my post directly before? The whole LOB idea seems not to
work with Lisp/SLIME. . .


Re: [O] Babel: How to call code in one org file into another org file

2015-10-30 Thread Lawrence Bottorff
In my init file I have

(custom-set-variables
  . . .
   '(org-babel-lob-files
   (quote
("/home/hercynian/org/babeltest/a.org" "/home/hercynian/org/babeltest/
b.org")))

that, of course, lasted an Emacs reboot after I had set them with
customization. But then right after Emacs reboot, looking into the contents
of `org-babel-library-of-babel`, I do not see the "association list" of the
entire code blocks of a.org and b.org as I did in the last Emacs/org-mode
session when I ran `org-babel-lob-ingest` on a.org and b.org. So
`org-babel-library-of-babel` is populated only
through `org-babel-lob-ingest`. Next question was, Does code alive in the
current `org-babel-library-of-babel` make it live and ready to use?
Apparently not. Experimenting has shown that starting Emacs not only does
not auto-populate `org-babel-library-of-babel`, but even when I do
a `org-babel-lob-ingest` on a.org and b.org, SLIME takes no notice and
fails to see the functions in a.org and b.org.

Here's my `org-babel-library-of-babel`:

Value: ((multi_x2 "lisp" "(defun multi_x2 (x)\n  (* 2 x))"
   ((:comments . "")
(:shebang . "")
(:cache . "no")
(:padline . "")
(:noweb . "no")
(:tangle . "no")
(:exports . "code")
(:results . "replace")
(:session)
(:hlines . "no"))
   "" "multi_x2" 0 18)
 (myadd "lisp" "(defun myadd (x y)\n  (+ x y))"
((:comments . "")
 (:shebang . "")
 (:cache . "no")
 (:padline . "")
 (:noweb . "no")
 (:tangle . "no")
 (:exports . "code")
 (:results . "replace")
 (:session)
 (:hlines . "no"))
"" "myadd" 0 15))

which seems like my code block in c.org should know about them, right? No.
Again, Babel LOB seems to have forgotten to tell SLIME the good news. But
then maybe I need to say something specific in my add_x2 code block
about these helper functions I've got in a.org and b.org?


Re: [O] Babel: How to call code in one org file into another org file

2015-10-30 Thread Lawrence Bottorff
@John Kitchin: I can't seem to find a `org-babel-load-file`.


Re: [O] Babel: How to call code in one org file into another org file

2015-10-30 Thread Lawrence Bottorff
>
>
> I would use local variables for this--something like (untested):
>
> # eval: (org-babel-lob-ingest path/to/your/file)
> # eval: (sbe "my-add")
> # eval: (sbe "multi_x2")
>
> Computer savvy Org moders don't like eval because anything can happen,
> but if you're willing to trust yourself, then it shouldn't cause any
> problems.
>
> With this near the bottom of your file, whenever you open the file your
> other org files will be loaded into the Library of Babel where you can
> load up function definitions as needed.
>
> Of course, you'll need to have slime running when you open the file.
>
> hth,
> Tom
>

Thanks Tom. Still, I'm wondering if the whole LOB is worth it in
Lisp/SLIME-land. I can load code with org-babel-lob-ingest into
`org-babel-library-of-babel`, but SLIME doesn't seem to know about it --
which sort of defeats the whole purpose, if you follow what I mean. . . .


Re: [O] Babel: How to call code in one org file into another org file

2015-10-30 Thread Lawrence Bottorff
Doing M-x org-babel-lob-files called up a customization buffer that allowed
me to put in many separate file paths. I did this for ../a.org and ../b.org.

a.org:

#+name: myadd
#+begin_src lisp :session
(defun myadd (x y)
  (+ x y))
#+end_src

b.org:

#+name: multi_x2
#+begin_src lisp :session
(defun multi_x2 (x)
  (* 2 x))
#+end_src

then in c.org:

#+name: add_x2
#+begin_src lisp :session
(defun add_x2 (x y)
  (multi_x2 (myadd x y)))
#+end_src

but upon C-c C-c in c.org SLIME didn't know about myadd or multi_x2 ...
until I did C-c C-c in both a.org and b.org for the respective functions.
Then c.org's add_x2 knew about the helper functions. That is
wonderful and allows a very distributed and modular approach to org-mode LP
for Lisp. However, it would be nice if I didn't have to acquaint my SLIME
session by hand all of my ingested babel-lob files. Any way to have this
happen automatically upon C-c C-c-ing my main org file? I found this

discussion,
but I don't believe it really addresses my wish.

LB



On Fri, Oct 30, 2015 at 8:55 PM, Thomas S. Dye  wrote:

> Aloha Lawrence,
>
> Lawrence Bottorff  writes:
>
> > There are many, many Babel examples, but I can't seem to find this
> > functionality: A function in a Lisp code block in one org file is to be
> > called from a Lisp code block in another org file. Is this possible? I
> know
> > you can stick stuff into your personal "Library of Babel," but I just
> want
> > to write a Lisp block that calls a function from another org file. I'll
> > have SLIME running, of course.
> >
> >
> > file1.org:
> > ...
> >  #+begin_src lisp
> > (defun foo ()
> >(...))
> > #+end_src
> >
> > is then called from. . .
> >
> > file2.org:
> > ...
> > #+begin_src lisp
> > (defun baa ()
> >   (foo))
> > #+end_src
>
> Any Org mode file can function as Library of Babel.  In your case,
> (org-babel-lob-ingest path/to/file1.org) should do what you want.  Note
> that org-babel-lob-ingest is bound to C-c C-v i.
>
> hth,
> Tom
>
> --
> Thomas S. Dye
> http://www.tsdye.com
>


Re: [O] Babel: How to call code in one org file into another org file

2015-10-30 Thread Thomas S . Dye
Aloha Lawrence,

Lawrence Bottorff  writes:

> Doing M-x org-babel-lob-files called up a customization buffer that allowed
> me to put in many separate file paths. I did this for ../a.org and ../b.org.
>
> a.org:
>
> #+name: myadd
> #+begin_src lisp :session
> (defun myadd (x y)
>   (+ x y))
> #+end_src
>
> b.org:
>
> #+name: multi_x2
> #+begin_src lisp :session
> (defun multi_x2 (x)
>   (* 2 x))
> #+end_src
>
> then in c.org:
>
> #+name: add_x2
> #+begin_src lisp :session
> (defun add_x2 (x y)
>   (multi_x2 (myadd x y)))
> #+end_src
>
> but upon C-c C-c in c.org SLIME didn't know about myadd or multi_x2 ...
> until I did C-c C-c in both a.org and b.org for the respective functions.
> Then c.org's add_x2 knew about the helper functions. That is
> wonderful and allows a very distributed and modular approach to org-mode LP
> for Lisp. However, it would be nice if I didn't have to acquaint my SLIME
> session by hand all of my ingested babel-lob files. Any way to have this
> happen automatically upon C-c C-c-ing my main org file? I found this
> 
> discussion,
> but I don't believe it really addresses my wish.

I would use local variables for this--something like (untested):

# eval: (org-babel-lob-ingest path/to/your/file)
# eval: (sbe "my-add")
# eval: (sbe "multi_x2")

Computer savvy Org moders don't like eval because anything can happen,
but if you're willing to trust yourself, then it shouldn't cause any
problems.

With this near the bottom of your file, whenever you open the file your
other org files will be loaded into the Library of Babel where you can
load up function definitions as needed.

Of course, you'll need to have slime running when you open the file.

hth,
Tom

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