From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nick Dokos Subject: Re: Babel: How to call code in one org file into another org file Date: Sat, 31 Oct 2015 11:41:48 -0400 Message-ID: <87oaff82pv.fsf@pierrot.dokosmarshall.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:36212) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZsYIE-0006Dr-An for emacs-orgmode@gnu.org; Sat, 31 Oct 2015 11:42:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZsYIA-00020q-Vv for emacs-orgmode@gnu.org; Sat, 31 Oct 2015 11:42:10 -0400 Received: from plane.gmane.org ([80.91.229.3]:44265) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZsYIA-00020m-PF for emacs-orgmode@gnu.org; Sat, 31 Oct 2015 11:42:06 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1ZsYI8-0001sm-N0 for emacs-orgmode@gnu.org; Sat, 31 Oct 2015 16:42:04 +0100 Received: from pool-108-20-41-232.bstnma.fios.verizon.net ([108.20.41.232]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 31 Oct 2015 16:42:04 +0100 Received: from ndokos by pool-108-20-41-232.bstnma.fios.verizon.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 31 Oct 2015 16:42:04 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org 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&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