emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Girard <girard.nicolas@gmail.com>
To: emacs-orgmode <emacs-orgmode@gnu.org>
Subject: [Babel] org-babel-execute-buffer gives different results than org-babel-exp-non-block-elements
Date: Thu, 22 Aug 2013 20:23:15 +0200	[thread overview]
Message-ID: <CANMKmefCDqs_amf=OXMLuSJw4qm5EE3xy3upuwOAYhsSBQTcxA@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1124 bytes --]

Hi all,

One thing I've been missing for long within org-mode is transclusion ;
so eventually I came up with some preliminary code which seems
promising regarding what I have in mind.

Now, I wish I would dedicate a full thread on this subject once my
code works in a predictable way ; but for now I'm experiencing
something annoying: while evaluating my test document using
=(org-babel-execute-buffer)=, or typing =C-c C-c= over the inline
Babel non block elements works fine, exporting the same document using
=C-c C-e t U= doesn't give the same results.

Looking into Babel source, I came up with the following conclusion:
- =(org-babel-execute-buffer)= produces the results I expect ;
- the exporter calls =org-export-execute-babel-code=, which eventually triggers
  =(org-babel-exp-non-block-elements (point-min) (point-max))=. And
this latter function doesn't lead to the same results as
=(org-babel-execute-buffer)=

Could anyone give me a hand on this ?

Attached is my test document, containing both my preliminary code for
transclusion, and some tests at the bottom.

Thanks very much in advance,

cheers,
Nicolas

[-- Attachment #2: transclusion.org --]
[-- Type: application/octet-stream, Size: 3180 bytes --]

#+AUTHOR: Nicolas Girard <girard.nicolas@gmail.com>

* Code to evaluate
Evaluate with: (org-babel-load-file buffer-file-name)

** ng/decode-link
#+BEGIN_SRC emacs-lisp
  (defun ng/decode-link (s)
    "[[x][y]] -> (x . y)"
    (let (desc link)
      (when
          (string-match org-bracket-link-regexp s)
        (setq desc (if (match-end 3) (org-match-string-no-properties 3 s)))
        (setq link (org-link-unescape
                    (org-match-string-no-properties 1 s)))
        (cons link desc))))
#+END_SRC
** ng/get-symlink-id
#+BEGIN_SRC emacs-lisp
  (defun ng/get-symlink-id (s)
    "[[id:888-77][ffff]] -> 888-77"
    (when 
      (and (string-match org-bracket-link-regexp s)
           (setq s (match-string 1 s))
           (string-match "^id\\:\\([^][]+\\)" s))
      (match-string 1 s)
      ))
#+END_SRC
** ng/delete-current-line
#+BEGIN_SRC emacs-lisp
  (defun ng/delete-current-line ()
    (let ((b (point-at-bol))
          (e (+ 1 (point-at-eol))))
      (delete-region b e)))
#+END_SRC
** ng/org-tc
#+BEGIN_SRC emacs-lisp
  (defun ng/org-tc (s)
    (let* ((at-heading-p (org-at-heading-p))
           (dec (ng/decode-link s))
           (link (first dec))
           (new-title (rest dec))
           (id (or (ng/get-symlink-id s) link))
           (lv-prop "_CURRENT_LEVEL_")
           (curr-lv (or (org-current-level) 0))
           ;(old-lv (string-to-number 
           ;         (or (org-entry-get-with-inheritance lv-prop) curr-lv)))
           )
      (unless id
        (error (format "No id found: %s" s)))
      (ng/delete-current-line)
      (save-excursion
        (save-window-excursion
          (org-id-open id)
          (org-copy-subtree)))
      (message (format "Levels: %s / %s" curr-lv old-lv))
      (with-temp-buffer
        (org-mode)
        (org-paste-subtree curr-lv nil nil)
        (org-delete-property "ID") ; prevents ID duplication if an entry gets pasted several times
        (org-set-property lv-prop (format "%d" old-lv))
        (org-back-to-heading)
        (if at-heading-p
          (progn
            ; Rename the heading
            (replace-string (ng/org-get-entry-title) new-title nil (point) (point-at-eol))
          ; body only
          (progn
            (ng/delete-current-line)))
        (buffer-string))))
#+END_SRC
* Source blocks
** Source bloc 1
:PROPERTIES:
:ID:       7002ef55-6d58-465c-ad89-b9394bf6f089
:DUMMY_PROP: dummy_value
:END:
Contents of source bloc 1
** Source bloc 2
:PROPERTIES:
:ID:       ad6acd70-b97e-4479-8388-7a5473bcb3bc
:END:
| A | B |
|---+---|
| 1 | 2 |
* Transclusion tests
Works as expected using =(org-babel-execute-buffer)=.

Doesn't work when exporting the buffer via =C-c C-e t U=.

Apparently, the exporter calls =org-export-execute-babel-code=, which eventually triggers
  =(org-babel-exp-non-block-elements (point-min) (point-max))=.
** src_emacs-lisp[:results raw]{(ng/org-tc "[[id:7002ef55-6d58-465c-ad89-b9394bf6f089][New title 1]]")}
Aa
*** src_emacs-lisp[:results raw]{(ng/org-tc "[[id:ad6acd70-b97e-4479-8388-7a5473bcb3bc][New title 2]]")}

** Body only
src_emacs-lisp[:results raw]{(ng/org-tc "[[id:7002ef55-6d58-465c-ad89-b9394bf6f089][Source bloc 1]]")}
B

             reply	other threads:[~2013-08-22 18:23 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-22 18:23 Nicolas Girard [this message]
2013-08-22 18:41 ` [Babel] org-babel-execute-buffer gives different results than org-babel-exp-non-block-elements Nicolas Goaziou
2013-08-22 19:28   ` Nicolas Girard
2013-08-22 20:28     ` Nicolas Girard
2013-08-22 20:33       ` Nicolas Goaziou
2013-08-22 21:01         ` Nicolas Girard
2013-08-22 23:06           ` Nicolas Goaziou
2013-08-22 23:20             ` Nicolas Girard
2013-08-23  8:11               ` Nicolas Goaziou
2013-08-23 14:55                 ` Eric Schulte
2013-08-26 10:33                   ` Nicolas Goaziou

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='CANMKmefCDqs_amf=OXMLuSJw4qm5EE3xy3upuwOAYhsSBQTcxA@mail.gmail.com' \
    --to=girard.nicolas@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).