emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [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-06-01  5:17 Mark Cox
  2011-06-01 12:47 ` Eric Schulte
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Cox @ 2011-06-01  5:17 UTC (permalink / raw)
  To: emacs-orgmode

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

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

* Re: [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-06-01  5:17 [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 Mark Cox
@ 2011-06-01 12:47 ` Eric Schulte
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Schulte @ 2011-06-01 12:47 UTC (permalink / raw)
  To: Mark Cox; +Cc: emacs-orgmode

Hi Mark,

I agree that this would constitute more reasonable default behavior.
I've implemented your suggestion with a simpler version of the patch you
supplied which makes use of the `default-directory' variable.  This
version also uses the :dir header argument, which can be used to
override (or unset) the local directory.

#+begin_src lisp
  *default-pathname-defaults*
#+end_src

#+results:
: #P/home/eschulte/path/to/org/file/

#+begin_src lisp :dir /tmp/
  *default-pathname-defaults*
#+end_src

#+results:
: #P/tmp/

#+begin_src lisp :dir
  *default-pathname-defaults*
#+end_src

#+results:
: NIL

Thanks for these patches.  If you think you may continue to make
contributions it may be worth starting the FSF copyright assignment now
as it takes some time to complete and without it we can not apply
patches >10 lines long.  See http://orgmode.org/worg/org-contribute.html
for more information on copyright assignment and contributing to
Org-mode.

Many Thanks -- Eric

Mark Cox <markcox80@gmail.com> writes:

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

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/

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

end of thread, other threads:[~2011-06-01 12:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-01  5:17 [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 Mark Cox
2011-06-01 12:47 ` Eric Schulte

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).