all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [Babel] org-babel-execute-buffer gives different results than org-babel-exp-non-block-elements
@ 2013-08-22 18:23 Nicolas Girard
  2013-08-22 18:41 ` Nicolas Goaziou
  0 siblings, 1 reply; 11+ messages in thread
From: Nicolas Girard @ 2013-08-22 18:23 UTC (permalink / raw)
  To: emacs-orgmode

[-- 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

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2013-08-26 10:33 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-22 18:23 [Babel] org-babel-execute-buffer gives different results than org-babel-exp-non-block-elements Nicolas Girard
2013-08-22 18:41 ` 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

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.