From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dan Davison Subject: Re: [babel] org-babel-load-file can't use properties drawers ? Date: Sun, 28 Feb 2010 16:59:34 -0500 Message-ID: <87y6id3ttl.fsf@stats.ox.ac.uk> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NlrAy-0005F5-Ut for emacs-orgmode@gnu.org; Sun, 28 Feb 2010 16:59:49 -0500 Received: from [140.186.70.92] (port=34764 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NlrAx-0005Eh-Sg for emacs-orgmode@gnu.org; Sun, 28 Feb 2010 16:59:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NlrAw-0005vA-Cl for emacs-orgmode@gnu.org; Sun, 28 Feb 2010 16:59:47 -0500 Received: from markov.stats.ox.ac.uk ([163.1.210.1]:62098) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NlrAw-0005ug-1h for emacs-orgmode@gnu.org; Sun, 28 Feb 2010 16:59:46 -0500 In-Reply-To: (Julien Fantin's message of "Sun, 28 Feb 2010 21:57:29 +0100") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Julien Fantin Cc: emacs-orgmode@gnu.org Julien Fantin writes: > I've been using this init file to load my org-mode-contained emacs config= uration =C2=A0: > > ;;; init.el --- Where all the magic begins > ;; > ;; This file loads both > ;; - Org-mode : http://orgmode.org/ and > ;; - Org-babel: http://orgmode.org/worg/org-contrib/babel/org-babel.php#l= ibrary-of-babel > ;; > ;; It then loads the rest of our Emacs initialization from Emacs lisp > ;; embedded in literate Org-mode files. > ;; Load up Org Mode and Org Babel for elisp embedded in Org Mode files > (setq dotfiles-dir (file-name-directory (or (buffer-file-name) load-file-= name))) > > (let* ((org-dir (expand-file-name > =C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "lisp" (exp= and-file-name > =C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 "org-mode" (expand-file-name > =C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"elisp" dotfiles-dir)))) > =C2=A0=C2=A0 =C2=A0 =C2=A0 (org-contrib-dir (expand-file-name > =C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 "lisp" (expand-file-name > =C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "contrib" (expand-file-name > =C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0".." org-dir)))) > =C2=A0=C2=A0 =C2=A0 =C2=A0 (load-path (append (list org-dir org-contrib-d= ir) > =C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0(or load-path nil)))) > =C2=A0=C2=A0;; load up Org-mode and Org-babel > =C2=A0=C2=A0(require 'org-install) > =C2=A0=C2=A0(require 'org-babel-init) > =C2=A0=C2=A0(require 'org-babel-emacs-lisp)) > ;; load up all literate org-mode files in this directory > (mapc 'org-babel-load-file (directory-files dotfiles-dir t "\\.org$")) > ;;; init.el ends here > > It's been working nicely until I tried to clean things up by setting some= commonly used variables =C2=A0in properties drawers, > and access them from emacs-lisp src blocks. > > The following illustrates my intent, and will behave as expected with org= -babel-execute-buffer, but fails when it is loaded > by org-babel-load-file : > > * Configuration > :PROPERTIES: > :ELISP-DIR:~/emacs.d/elisp/ > :END: > > ** Load Path > #+begin_src emacs-lisp=C2=A0 > (add-to-list 'load-path (org-entry-get nil "ELISP-DIR" t)) > #+end_src > > From my understanding, orb-babel-load-file tangles then loads the file, l= osing the variables in the process. Yes. Initially when I read your email I thought "hang on, why didn't Eric implement org-babel-load-file using org-babel-execute-buffer?" But I think (of course) there are good reasons -- for example I believe that C-h f will be able to link back to the file in which a function was defined, if it is loaded with load-file. > > I've been using this function to get the expected behaviour, but the defa= ult somewhat breaks expectations, don't you think > ? > =C2=A0(defun > =C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0ba/org-babel-load-file (file) (with-temp= -buffer (insert-file-contents > =C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0file) (org-mode) (org-babel-execute-buff= er))) > > Or, is there a cleaner way to achieve this ? Eric may have a better answer, but I think that your solution is appropriate. In fact, perhaps you'd like to donate us your function to become org-babel-execute-file? So that would lead towards a scheme of emacs initialisation broken into two parts: 1. org files containing emacs-lisp blocks that you want to be load-file'd 2. org files that you want to be org-babel-execute-file'd=20 Perhaps org philosophy suggests that it ought to be possible for those to be subtrees rather than distinct files? In which case we'd need to be able to refer to a particular subtree within a particular file. Here's a half thought through idea which might be getting convoluted and out of my depth, but I wonder whether there's an alternative involving lisp evaluation tricks. Would it be possible to have a version of org-babel-load-file that doesn't simply extract the elisp from the blocks, but instead generates the elisp that *would* be evaluated if you had done C-c C-c, and then instead of evaluating it, tangles it to a .el file so that it can be load-file'd. In particular, :var references would be resolved and their variables set in a let binding as they are normally. And perhaps you could get that (org-entry-get nil "ELISP-DIR" t) to be evaluated while in the org buffer using the comma operator somehow? Dan > > Regards, > julien > > _______________________________________________ > Emacs-orgmode mailing list > Please use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode