[O] [PATCH] Common Lisp source blocks are now wrapped in a LET form which binds the symbol *default-pathname-defaults* to the directory in which the org file resides.

2011-05-31 Thread Mark Cox
Hi,

This may be contentious and break backward compatibility for some people.

Currently, relative pathnames in Common Lisp source blocks are
meaningless as the *default-pathname-defaults* symbol is set to
whatever the value is when SLIME was invoked. This behaviour is
contrary to the shell source block processor (I haven't checked the
others).

This is in /tmp/example1/test.org
#+begin_src sh
pwd
#+end_src

#+results:
: #P/tmp/example1/

This is in /tmp/example2/test.org
#+begin_src sh
pwd
#+end_src

#+results:
: #P/tmp/example2/

The attached patch brings this expected behaviour (well from my point
of view) to lisp source blocks. Given the behaviour of Emacs commands
like DIRED and COMPILE, I think the patch makes things more
consistent.

I couldn't figure out how the sh block processor determines the path
to the org file so I hacked together something that works using some
of the Org hooks.

Thanks
Mark

lisp/ob-lisp.el: Added new variable ORG-BABEL-LISP-CURRENT-BUFFER
which is used to store a reference to the currently being processed org file.
This variable is setq'd in the hooks for
ORG-BABEL-PRE-TANGLE-HOOK, ORG-CTRL-C-CTRL-C-HOOK and
ORG-EXPORT-FIRST-HOOK.

lisp/ob-lisp.el (org-babel-expand-body:lisp): The code sent to SLIME
is now wrapped in a LET block which binds
COMMON-LISP:*DEFAULT-PATHNAME-DEFAULTS* to the directory where the
currently being processed org file resides.

diff --git a/lisp/ob-lisp.el b/lisp/ob-lisp.el
index a875d55..db06182 100644
--- a/lisp/ob-lisp.el
+++ b/lisp/ob-lisp.el
@@ -40,6 +40,14 @@

 (defvar org-babel-default-header-args:lisp '())
 (defvar org-babel-header-arg-names:lisp '(package))
+(defvar org-babel-lisp-current-buffer nil)
+
+(let ((fn (lambda ()
+   (setq org-babel-lisp-current-buffer (current-buffer))
+   nil)))
+  (dolist (hook '(org-babel-pre-tangle-hook org-ctrl-c-ctrl-c-hook
org-export-first-hook))
+(add-hook hook fn)))
+

 (defun org-babel-expand-body:lisp (body params)
   Expand BODY according to PARAMS, return the expanded body.
@@ -73,8 +81,10 @@
(read (org-bable-lisp-vector-to-list (cadr result)))
  (error (cadr result)
   (slime-eval `(swank:eval-and-grab-output
-   ,(format (progn %s) (buffer-substring-no-properties
-  (point-min) (point-max
+   ,(format (let
((common-lisp:*default-pathname-defaults* #P%S)) %s)
+(file-name-directory (buffer-file-name
org-babel-lisp-current-buffer))
+(buffer-substring-no-properties
+ (point-min) (point-max
  (cdr (assoc :package params)
(org-babel-pick-name (cdr (assoc :colname-names params))
(cdr (assoc :colnames params)))



[O] Unwanted (progn ) when Tangling Lisp Code

2011-05-30 Thread Mark Cox
Hi,

When tangling lisp source code blocks, the tangled code is wrapped in
a `(progn ,@body). For example,
the block
#+begin_src lisp :tangle example.lisp
(defun mischief ()
  (/ 1 0))
#+end_src
produces
: (progn (defun mischief ()
:   (/ 1 0))
: )

With the attached patch, the tangling process now produces
:
: (defun mischief ()
:   (/ 1 0))

Thanks
Mark

Here is the patch.

diff --git a/lisp/ob-lisp.el b/lisp/ob-lisp.el
index a810d86..3382418 100644
--- a/lisp/ob-lisp.el
+++ b/lisp/ob-lisp.el
@@ -54,7 +54,7 @@
   (format (%S (quote %S)) (car var) (cdr var)))
 vars \n  )
)\n body ))
- (format (progn %s) body)
+ body
 (if (or (member code result-params)
(member pp result-params))
(format (pprint %s) body)
@@ -65,7 +65,7 @@
   (require 'slime)
   (org-babel-reassemble-table
(with-temp-buffer
- (insert (org-babel-expand-body:lisp body params))
+ (insert (format (progn\n  %s) (org-babel-expand-body:lisp body params)))
  ((lambda (result)
(if (member output (cdr (assoc :result-params params)))
(car result)



[O] No Expansion of noweb references when exporting

2011-05-18 Thread Mark Cox
Hi,

Is it possible for the output of the expansion of a code block to
appear in the exported document?

Consider the example:

#+TITLE: No expansion of noweb references when exporting

* Example
:PROPERTIES:
:tangle: illustration.hpp
:END:
#+srcname: boiler-plate-code-generator()
#+begin_src emacs-lisp :results output :exports none :tangle no
(dolist (type '(int8_t uint8_t float double))
  (princ (format template  %s boiler_plate_code%s();\n type type)))
#+end_src
#+begin_src c++ :noweb yes
boiler-plate-code-generator()
#+end_src

When I export this to HTML using C-c C-e b, the text
boiler-plate-code-generator() is present. What I would like to see
is the output that is generated when tangling.

Thanks
Mark



[O] #+end_src interfering with :results raw

2011-05-14 Thread Mark Cox
Hi,

I have an org file like this one,

#+TITLE: An issue with #+end_src

#+srcname: no_issue()
#+begin_src sh :results output
echo '#+begin_src'
#+end_src

#+call: no_issue() :results raw

#+srcname: the_issue()
#+begin_src sh :results output
echo '#+end_src'
#+end_src

#+call: the_issue() :results raw

When C-c C-c on the line containing #+call: no_issue() :results raw, the 
following lines are inserted:
#+results: no_issue()
#+begin_src

When C-c C-c on the line containing #+call: the_issue() :results raw, the 
following unexpected lines are inserted:
#+results: the_issue()
nil

I am currently running a2f29de86.

Thanks
Mark Cox