From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Eric Schulte" Subject: Re: org-babel-load-file can't use properties drawers ? Date: Mon, 22 Mar 2010 08:52:47 -0600 Message-ID: <87wrx4if28.fsf@gmail.com> 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 1Ntp5L-0004oj-CL for emacs-orgmode@gnu.org; Mon, 22 Mar 2010 17:22:55 -0400 Received: from [140.186.70.92] (port=34239 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ntp5I-0004nZ-UU for emacs-orgmode@gnu.org; Mon, 22 Mar 2010 17:22:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Ntp5G-0003dN-OP for emacs-orgmode@gnu.org; Mon, 22 Mar 2010 17:22:52 -0400 Received: from fg-out-1718.google.com ([72.14.220.157]:64484) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Ntp5G-0003d8-Ei for emacs-orgmode@gnu.org; Mon, 22 Mar 2010 17:22:50 -0400 Received: by fg-out-1718.google.com with SMTP id l26so111408fgb.12 for ; Mon, 22 Mar 2010 14:22:49 -0700 (PDT) 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 Hi Julien, I just pushed up a small commit which will allow you to pull property values from a headline by embedding a small amount of elisp into your :var header argument. In this way the `org-entry-get' function can be used with our existing tangle-then-load elisp machinery. Best -- Eric ,----[from the commit message] | babel: variable references which look like lisp forms are now evaluat= ed |=20=20=20=20=20 | for example, the following simple example | #+begin_src emacs-lisp :var two=3D(+ 1 1) | (sqrt two) | #+end_src |=20=20=20=20=20 | #+results: | : 1.4142135623730951 |=20=20=20=20=20 | Or this more interesting usage, which pulls variable values from | headline properties | *** example headline w/property | :PROPERTIES: | :special: 89 | :last-name: schulte | :END: |=20=20=20=20=20 | #+begin_src emacs-lisp :var special=3D(string-to-number (org-entr= y-get nil "special" t)) | (+ special 1) | #+end_src |=20=20=20=20=20 | #+results: | : 90 |=20=20=20=20=20 | #+begin_src emacs-lisp :var last-name=3D(org-entry-get nil "last-= name" t)) | (message "hello %s" last-name) | #+end_src |=20=20=20=20=20 | #+results: | : hello schulte `---- 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. > > 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 ? > > 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