From mboxrd@z Thu Jan 1 00:00:00 1970 From: Robert Goldman Subject: Org babel does not work properly with included files Date: Sun, 01 May 2011 19:44:05 -0500 Message-ID: <4DBDFE55.7080303@sift.info> Reply-To: rpgoldman@sift.info Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------050102040000080601050205" Return-path: Received: from eggs.gnu.org ([140.186.70.92]:45987) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QGhFB-0003pt-DE for emacs-orgmode@gnu.org; Sun, 01 May 2011 20:44:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QGhF9-0001tT-PT for emacs-orgmode@gnu.org; Sun, 01 May 2011 20:44:09 -0400 Received: from mpls.sift.info ([75.146.46.193]:36545) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QGhF9-0001tM-Iz for emacs-orgmode@gnu.org; Sun, 01 May 2011 20:44:07 -0400 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: Org Mode This is a multi-part message in MIME format. --------------050102040000080601050205 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Here's the problem: when org-babel goes to look for parameters when executing a source block, it looks for them in the parent source file, and not in the parent source file with the included materials. Here is the function that goes awry: (defmacro org-babel-exp-in-export-file (lang &rest body) (declare (indent 1)) `(let* ((lang-headers (intern (concat "org-babel-default-header-args:" ,lang))) (heading (nth 4 (ignore-errors (org-heading-components)))) (link (when org-current-export-file (org-make-link-string (if heading (concat org-current-export-file "::" heading) org-current-export-file)))) (export-buffer (current-buffer)) results) (when link ;; resolve parameters in the original file so that ;; headline and file-wide parameters are included, attempt ;; to go to the same heading in the original file (set-buffer (get-file-buffer org-current-export-file)) (save-restriction (condition-case nil ** (org-open-link-from-string link) (error (when heading (goto-char (point-min)) (re-search-forward (regexp-quote heading) nil t)))) (setq results ,@body)) (set-buffer export-buffer) results))) The line that blows up, AFAICT is the one marked with an asterisk. It goes to look in the file *without* incorporated materials, instead of the file *with* incorporated materials. I believe that what needs to happen is that the link must be searched for in the export-buffer, rather than in org-current-export-file. Unfortunately, I don't understand the code well enough to figure out how to make this modification. I believe that the first trick is to NOT concatenate org-current-export-file onto the link string. The second would be to change org-open-link-from-string to something that looks for the link match in the current buffer. To see the bug, it should be sufficient to install the attached to .org files into a temporary directory and then try to export foo.org to latex. You may need to tweak your configuration so that evaluation is enabled for sh scripts (require 'ob-sh) The error messages one gets are deeply cryptic. To debug this I modified org-link-search as follows. I added a DEBUG call when the link is unfound. This is, of course, not generally good practice, but you will want this debug call in place when you test the export per my instructions above. You will get a debug window with a backtrace that should make things relatively clear. Here is the modified org-link-search --- you can just evaluate the definition before testing the export. To see what I've changed, just search for debug... Cheers, r (defun org-link-search (s &optional type avoid-pos) "Search for a link search option. If S is surrounded by forward slashes, it is interpreted as a regular expression. In org-mode files, this will create an `org-occur' sparse tree. In ordinary files, `occur' will be used to list matches. If the current buffer is in `dired-mode', grep will be used to search in all files. If AVOID-POS is given, ignore matches near that position." (let ((case-fold-search t) (s0 (mapconcat 'identity (org-split-string s "[ \t\r\n]+") " ")) (markers (concat "\\(?:" (mapconcat (lambda (x) (regexp-quote (car x))) (append '(("") (" ") ("\t") ("\n")) org-emphasis-alist) "\\|") "\\)")) (pos (point)) (pre nil) (post nil) words re0 re1 re2 re3 re4_ re4 re5 re2a re2a_ reall) (cond ;; First check if there are any special search functions ((run-hook-with-args-until-success 'org-execute-file-search-functions s)) ;; Now try the builtin stuff ((and (equal (string-to-char s0) ?#) (> (length s0) 1) (save-excursion (goto-char (point-min)) (and (re-search-forward (concat "^[ \t]*:CUSTOM_ID:[ \t]+" (regexp-quote (substring s0 1)) "[ \t]*$") nil t) (setq type 'dedicated pos (match-beginning 0)))) ;; There is an exact target for this (goto-char pos) (org-back-to-heading t))) ((save-excursion (goto-char (point-min)) (and (re-search-forward (concat "<<" (regexp-quote s0) ">>") nil t) (setq type 'dedicated pos (match-beginning 0)))) ;; There is an exact target for this (goto-char pos)) ((and (string-match "^(\\(.*\\))$" s0) (save-excursion (goto-char (point-min)) (and (re-search-forward (concat "[^[]" (regexp-quote (format org-coderef-label-format (match-string 1 s0)))) nil t) (setq type 'dedicated pos (1+ (match-beginning 0)))))) ;; There is a coderef target for this (goto-char pos)) ((string-match "^/\\(.*\\)/$" s) ;; A regular expression (cond ((org-mode-p) (org-occur (match-string 1 s))) ;;((eq major-mode 'dired-mode) ;; (grep (concat "grep -n -e '" (match-string 1 s) "' *"))) (t (org-do-occur (match-string 1 s))))) ((and (org-mode-p) org-link-search-must-match-exact-headline) (and (equal (string-to-char s) ?*) (setq s (substring s 1))) (goto-char (point-min)) (cond ((let (case-fold-search) (re-search-forward (format org-complex-heading-regexp-format (regexp-quote s)) nil t)) ;; OK, found a match (setq type 'dedicated) (goto-char (match-beginning 0))) ((and (not org-link-search-inhibit-query) (eq org-link-search-must-match-exact-headline 'query-to-create) (debug nil (format "No match for target %s" s)) (y-or-n-p "No match - create this as a new heading? ")) (goto-char (point-max)) (or (bolp) (newline)) (insert "* " s "\n") (beginning-of-line 0)) (t (goto-char pos) (error "No match")))) (t ;; A normal search string (when (equal (string-to-char s) ?*) ;; Anchor on headlines, post may include tags. (setq pre "^\\*+[ \t]+\\(?:\\sw+\\)?[ \t]*" post (org-re "[ \t]*\\(?:[ \t]+:[[:alnum:]_@#%:+]:[ \t]*\\)?$") s (substring s 1))) (remove-text-properties 0 (length s) '(face nil mouse-face nil keymap nil fontified nil) s) ;; Make a series of regular expressions to find a match (setq words (org-split-string s "[ \n\r\t]+") re0 (concat "\\(<<" (regexp-quote s0) ">>\\)") re2 (concat markers "\\(" (mapconcat 'downcase words "[ \t]+") "\\)" markers) re2a_ (concat "\\(" (mapconcat 'downcase words "[ \t\r\n]+") "\\)[ \t\r\n]") re2a (concat "[ \t\r\n]" re2a_) re4_ (concat "\\(" (mapconcat 'downcase words "[^a-zA-Z_\r\n]+") "\\)[^a-zA-Z_]") re4 (concat "[^a-zA-Z_]" re4_) re1 (concat pre re2 post) re3 (concat pre (if pre re4_ re4) post) re5 (concat pre ".*" re4) re2 (concat pre re2) re2a (concat pre (if pre re2a_ re2a)) re4 (concat pre (if pre re4_ re4)) reall (concat "\\(" re0 "\\)\\|\\(" re1 "\\)\\|\\(" re2 "\\)\\|\\(" re3 "\\)\\|\\(" re4 "\\)\\|\\(" re5 "\\)" )) (cond ((eq type 'org-occur) (org-occur reall)) ((eq type 'occur) (org-do-occur (downcase reall) 'cleanup)) (t (goto-char (point-min)) (setq type 'fuzzy) (if (or (and (org-search-not-self 1 re0 nil t) (setq type 'dedicated)) (org-search-not-self 1 re1 nil t) (org-search-not-self 1 re2 nil t) (org-search-not-self 1 re2a nil t) (org-search-not-self 1 re3 nil t) (org-search-not-self 1 re4 nil t) (org-search-not-self 1 re5 nil t) ) (goto-char (match-beginning 1)) (goto-char pos) (error "No match")))))) (and (org-mode-p) (org-show-context 'link-search)) type)) --------------050102040000080601050205 Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0"; name="foo.org" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="foo.org" * Purpose This document is intended to demonstrate that src buffer evaluation in subsidiary, included files, does not work. * Demo #+include "~/src/org-test/bar.org" --------------050102040000080601050205 Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0"; name="bar.org" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="bar.org" * Here's the demo #+begin_src sh :exports results :results output echo "foo!" #+end_src --------------050102040000080601050205--