emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nick Dokos <ndokos@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: Babel: How to call code in one org file into another org file
Date: Sat, 31 Oct 2015 11:41:48 -0400	[thread overview]
Message-ID: <87oaff82pv.fsf@pierrot.dokosmarshall.org> (raw)
In-Reply-To: CAFAhFSUcGzsMwQLf=PAUJDmVHEtY261-buV1JAUtYvGkxrMCuw@mail.gmail.com

Lawrence Bottorff <borgauf@gmail.com> 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&multi_x2
#+begin_src lisp :session
(defun add&multi_x2 (x y)
 (multi_x2 (myadd x y)))
#+end_src

#+BEGIN_SRC lisp :session
  (add&multi_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

  reply	other threads:[~2015-10-31 15:42 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-30 20:21 Babel: How to call code in one org file into another org file Lawrence Bottorff
2015-10-30 20:53 ` John Kitchin
2015-10-30 20:55 ` Thomas S. Dye
2015-10-30 22:57   ` briangpowell .
2015-10-31  0:14   ` Lawrence Bottorff
     [not found]     ` <m21tcbx2iy.fsf@andrew.cmu.edu>
2015-10-31  2:12       ` Lawrence Bottorff
2015-10-31  2:15         ` Lawrence Bottorff
2015-10-31  3:08     ` Thomas S. Dye
2015-10-31  3:58       ` Lawrence Bottorff
2015-10-31 15:41         ` Nick Dokos [this message]
2015-10-31 16:17           ` Lawrence Bottorff
2015-10-31 16:34             ` Nick Dokos
2015-10-31 16:51               ` Lawrence Bottorff
2015-11-02  7:09                 ` Eric S Fraga
2015-11-02 13:36                   ` Nick Dokos
2015-10-31  9:57 ` Rasmus
  -- strict thread matches above, loose matches on Subject: below --
2015-10-31  2:24 John Kitchin
2015-10-31  2:33 ` Lawrence Bottorff

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87oaff82pv.fsf@pierrot.dokosmarshall.org \
    --to=ndokos@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).