all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* ob: Make src block location available to execution backend
@ 2013-06-05 13:49 Vitalie Spinu
  2013-06-06 11:07 ` [PATCH] Make src block location available to execution backends Vitalie Spinu
  0 siblings, 1 reply; 4+ messages in thread
From: Vitalie Spinu @ 2013-06-05 13:49 UTC (permalink / raw)
  To: emacs-orgmode

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


Hi, 

ESS has a visual debugger that depends on the availability of source
references. It would be very nice if the debugger could step directly
through org buffers.

ESS was detecting org-src-edit buffers and redirecting references to
original org file for already quite a while. That because of the
availability of org-edit-src-beg-marker in src-edit
buffers. Unfortunately similar functionality is not available in babel.

I attach a patch that would allow ess-eval-buffer from ob-R.el to access
the location of the currently executed block through a temporary stored
marker in org-babel-current-exec-src-block-head.

    Vitalie


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-diff, Size: 1947 bytes --]

	Modified   lisp/ob-core.el
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 8d26c4e..653975a 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -251,7 +251,7 @@ references; a process which could likely result in the execution
 of other code blocks.
 
 Returns a list
- (language body header-arguments-alist switches name indent)."
+ (language body header-arguments-alist switches name indent block-head)."
   (let ((case-fold-search t) head info name indent)
     ;; full code block
     (if (setq head (org-babel-where-is-src-block-head))
@@ -274,7 +274,7 @@ Returns a list
     ;; resolve variable references and add summary parameters
     (when (and info (not light))
       (setf (nth 2 info) (org-babel-process-params (nth 2 info))))
-    (when info (append info (list name indent)))))
+    (when info (append info (list name indent head)))))
 
 (defvar org-current-export-file) ; dynamically bound
 (defmacro org-babel-check-confirm-evaluate (info &rest body)
@@ -535,6 +535,8 @@ can not be resolved.")
 
 ;;; functions
 (defvar call-process-region)
+(defvar org-babel-current-exec-src-block-head nil
+  "Marker to the currently processed src block.")
 
 ;;;###autoload
 (defun org-babel-execute-src-block (&optional arg info params)
@@ -562,6 +564,7 @@ block."
       (let* ((params (if params
 			 (org-babel-process-params merged-params)
 		       (nth 2 info)))
+	     (org-babel-current-exec-src-block-head (nth 6 info))
 	     (cachep (and (not arg) (cdr (assoc :cache params))
 			   (string= "yes" (cdr (assoc :cache params)))))
 	     (new-hash (when cachep (org-babel-sha1-hash info)))
@@ -1592,7 +1595,7 @@ If the point is not on a source block then return nil."
         (< top initial) (< initial bottom)
         (progn (goto-char top) (beginning-of-line 1)
 	       (looking-at org-babel-src-block-regexp))
-        (point))))))
+        (point-marker))))))
 
 ;;;###autoload
 (defun org-babel-goto-src-block-head ()

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

* [PATCH] Make src block location available to execution backends
  2013-06-05 13:49 ob: Make src block location available to execution backend Vitalie Spinu
@ 2013-06-06 11:07 ` Vitalie Spinu
  2013-06-06 15:18   ` Eric Schulte
  2013-06-24 20:56   ` Bastien
  0 siblings, 2 replies; 4+ messages in thread
From: Vitalie Spinu @ 2013-06-06 11:07 UTC (permalink / raw)
  To: emacs-orgmode

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


Hi again, 

I wrapped it in a patch. All tests are fine. Will be very happy if
someone could have a glance. I have my FSF papers signed.

Thanks, 

    Vitalie


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-make-src-block-location-available-to-execution-backe.patch --]
[-- Type: text/x-diff, Size: 3404 bytes --]

From 90dc398856c121c0a1cac36d6726e49d9fa31570 Mon Sep 17 00:00:00 2001
From: Vitalie Spinu <spinuvit@gmail.com>
Date: Thu, 6 Jun 2013 12:04:02 +0200
Subject: [PATCH] make src block location available to execution backends

* lisp/ob-core.el (org-babel-where-is-src-block-head): return
  point-marker instead of point.

  (org-babel-current-exec-src-block-head): new global variable which is
  bound during `org-babel-execute-src-block-maybe'

  (org-babel-get-src-block-info): return a list of 7 elements, last
  being the header location

Evaluation backends might need to use the exact location of the block in
original org file. For example when inserting the correct source
references for visual debugging. With this patch the information on
current block is available in `org-babel-current-exec-src-block-head'.
---
 lisp/ob-core.el | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 8d26c4e..93c5d5e 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -251,14 +251,14 @@ references; a process which could likely result in the execution
 of other code blocks.
 
 Returns a list
- (language body header-arguments-alist switches name indent)."
+ (language body header-arguments-alist switches name indent block-head)."
   (let ((case-fold-search t) head info name indent)
     ;; full code block
     (if (setq head (org-babel-where-is-src-block-head))
 	(save-excursion
 	  (goto-char head)
 	  (setq info (org-babel-parse-src-block-match))
-	  (setq indent (car (last info)))
+	  (setq indent (nth 5 info))
 	  (setq info (butlast info))
 	  (while (and (forward-line -1)
 		      (looking-at org-babel-multi-line-header-regexp))
@@ -274,7 +274,7 @@ Returns a list
     ;; resolve variable references and add summary parameters
     (when (and info (not light))
       (setf (nth 2 info) (org-babel-process-params (nth 2 info))))
-    (when info (append info (list name indent)))))
+    (when info (append info (list name indent head)))))
 
 (defvar org-current-export-file) ; dynamically bound
 (defmacro org-babel-check-confirm-evaluate (info &rest body)
@@ -535,6 +535,8 @@ can not be resolved.")
 
 ;;; functions
 (defvar call-process-region)
+(defvar org-babel-current-exec-src-block-head nil
+  "Marker to the currently processed src block.")
 
 ;;;###autoload
 (defun org-babel-execute-src-block (&optional arg info params)
@@ -562,6 +564,7 @@ block."
       (let* ((params (if params
 			 (org-babel-process-params merged-params)
 		       (nth 2 info)))
+	     (org-babel-current-exec-src-block-head (nth 6 info))
 	     (cachep (and (not arg) (cdr (assoc :cache params))
 			   (string= "yes" (cdr (assoc :cache params)))))
 	     (new-hash (when cachep (org-babel-sha1-hash info)))
@@ -592,7 +595,7 @@ block."
 		  (or (org-bound-and-true-p
 		       org-babel-call-process-region-original)
 		      (symbol-function 'call-process-region)))
-		 (indent (car (last info)))
+		 (indent (nth 5 info))
 		 result cmd)
 	    (unwind-protect
 		(let ((call-process-region
@@ -1592,7 +1595,7 @@ If the point is not on a source block then return nil."
         (< top initial) (< initial bottom)
         (progn (goto-char top) (beginning-of-line 1)
 	       (looking-at org-babel-src-block-regexp))
-        (point))))))
+        (point-marker))))))
 
 ;;;###autoload
 (defun org-babel-goto-src-block-head ()
-- 
1.8.1.2


[-- Attachment #3: Type: text/plain, Size: 2955 bytes --]







 >> Vitalie Spinu <spinuvit@gmail.com>
 >> on Wed, 05 Jun 2013 15:49:08 +0200 wrote:

 VS> Hi, 

 VS> ESS has a visual debugger that depends on the availability of source
 VS> references. It would be very nice if the debugger could step directly
 VS> through org buffers.

 VS> ESS was detecting org-src-edit buffers and redirecting references to
 VS> original org file for already quite a while. That because of the
 VS> availability of org-edit-src-beg-marker in src-edit
 VS> buffers. Unfortunately similar functionality is not available in babel.

 VS> I attach a patch that would allow ess-eval-buffer from ob-R.el to access
 VS> the location of the currently executed block through a temporary stored
 VS> marker in org-babel-current-exec-src-block-head.

 VS>     Vitalie


 VS> 	Modified   lisp/ob-core.el
 VS> diff --git a/lisp/ob-core.el b/lisp/ob-core.el
 VS> index 8d26c4e..653975a 100644
 VS> --- a/lisp/ob-core.el
 VS> +++ b/lisp/ob-core.el
 VS> @@ -251,7 +251,7 @@ references; a process which could likely result in the execution
 VS>  of other code blocks.
 
 VS>  Returns a list
 VS> - (language body header-arguments-alist switches name indent)."
 VS> + (language body header-arguments-alist switches name indent block-head)."
 VS>    (let ((case-fold-search t) head info name indent)
 VS>      ;; full code block
 VS>      (if (setq head (org-babel-where-is-src-block-head))
 VS> @@ -274,7 +274,7 @@ Returns a list
 VS>      ;; resolve variable references and add summary parameters
 VS>      (when (and info (not light))
 VS>        (setf (nth 2 info) (org-babel-process-params (nth 2 info))))
 VS> -    (when info (append info (list name indent)))))
 VS> +    (when info (append info (list name indent head)))))
 
 VS>  (defvar org-current-export-file) ; dynamically bound
 VS>  (defmacro org-babel-check-confirm-evaluate (info &rest body)
 VS> @@ -535,6 +535,8 @@ can not be resolved.")
 
 VS>  ;;; functions
 VS>  (defvar call-process-region)
 VS> +(defvar org-babel-current-exec-src-block-head nil
 VS> +  "Marker to the currently processed src block.")
 
 VS>  ;;;###autoload
 VS>  (defun org-babel-execute-src-block (&optional arg info params)
 VS> @@ -562,6 +564,7 @@ block."
 VS>        (let* ((params (if params
 VS>  			 (org-babel-process-params merged-params)
 VS>  		       (nth 2 info)))
 VS> +	     (org-babel-current-exec-src-block-head (nth 6 info))
 VS>  	     (cachep (and (not arg) (cdr (assoc :cache params))
 VS>  			   (string= "yes" (cdr (assoc :cache params)))))
 VS>  	     (new-hash (when cachep (org-babel-sha1-hash info)))
 VS> @@ -1592,7 +1595,7 @@ If the point is not on a source block then return nil."
 VS>          (< top initial) (< initial bottom)
 VS>          (progn (goto-char top) (beginning-of-line 1)
 VS>  	       (looking-at org-babel-src-block-regexp))
 VS> -        (point))))))
 VS> +        (point-marker))))))
 
 VS>  ;;;###autoload
 VS>  (defun org-babel-goto-src-block-head ()


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

* Re: [PATCH] Make src block location available to execution backends
  2013-06-06 11:07 ` [PATCH] Make src block location available to execution backends Vitalie Spinu
@ 2013-06-06 15:18   ` Eric Schulte
  2013-06-24 20:56   ` Bastien
  1 sibling, 0 replies; 4+ messages in thread
From: Eric Schulte @ 2013-06-06 15:18 UTC (permalink / raw)
  To: Vitalie Spinu; +Cc: emacs-orgmode

Vitalie Spinu <spinuvit@gmail.com> writes:

> Hi again, 
>
> I wrapped it in a patch. All tests are fine. Will be very happy if
> someone could have a glance. I have my FSF papers signed.
>

I've just applied this patch.  I think this is an excellent idea, and I
appreciate the clean implementation and packaging into a git-patch.

Cheers!

>
> Thanks,
>
>     Vitalie
>
>
> From 90dc398856c121c0a1cac36d6726e49d9fa31570 Mon Sep 17 00:00:00 2001
> From: Vitalie Spinu <spinuvit@gmail.com>
> Date: Thu, 6 Jun 2013 12:04:02 +0200
> Subject: [PATCH] make src block location available to execution backends
>
> * lisp/ob-core.el (org-babel-where-is-src-block-head): return
>   point-marker instead of point.
>
>   (org-babel-current-exec-src-block-head): new global variable which is
>   bound during `org-babel-execute-src-block-maybe'
>
>   (org-babel-get-src-block-info): return a list of 7 elements, last
>   being the header location
>
> Evaluation backends might need to use the exact location of the block in
> original org file. For example when inserting the correct source
> references for visual debugging. With this patch the information on
> current block is available in `org-babel-current-exec-src-block-head'.
> ---
>  lisp/ob-core.el | 13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)
>
> diff --git a/lisp/ob-core.el b/lisp/ob-core.el
> index 8d26c4e..93c5d5e 100644
> --- a/lisp/ob-core.el
> +++ b/lisp/ob-core.el
> @@ -251,14 +251,14 @@ references; a process which could likely result in the execution
>  of other code blocks.
>  
>  Returns a list
> - (language body header-arguments-alist switches name indent)."
> + (language body header-arguments-alist switches name indent block-head)."
>    (let ((case-fold-search t) head info name indent)
>      ;; full code block
>      (if (setq head (org-babel-where-is-src-block-head))
>  	(save-excursion
>  	  (goto-char head)
>  	  (setq info (org-babel-parse-src-block-match))
> -	  (setq indent (car (last info)))
> +	  (setq indent (nth 5 info))
>  	  (setq info (butlast info))
>  	  (while (and (forward-line -1)
>  		      (looking-at org-babel-multi-line-header-regexp))
> @@ -274,7 +274,7 @@ Returns a list
>      ;; resolve variable references and add summary parameters
>      (when (and info (not light))
>        (setf (nth 2 info) (org-babel-process-params (nth 2 info))))
> -    (when info (append info (list name indent)))))
> +    (when info (append info (list name indent head)))))
>  
>  (defvar org-current-export-file) ; dynamically bound
>  (defmacro org-babel-check-confirm-evaluate (info &rest body)
> @@ -535,6 +535,8 @@ can not be resolved.")
>  
>  ;;; functions
>  (defvar call-process-region)
> +(defvar org-babel-current-exec-src-block-head nil
> +  "Marker to the currently processed src block.")
>  
>  ;;;###autoload
>  (defun org-babel-execute-src-block (&optional arg info params)
> @@ -562,6 +564,7 @@ block."
>        (let* ((params (if params
>  			 (org-babel-process-params merged-params)
>  		       (nth 2 info)))
> +	     (org-babel-current-exec-src-block-head (nth 6 info))
>  	     (cachep (and (not arg) (cdr (assoc :cache params))
>  			   (string= "yes" (cdr (assoc :cache params)))))
>  	     (new-hash (when cachep (org-babel-sha1-hash info)))
> @@ -592,7 +595,7 @@ block."
>  		  (or (org-bound-and-true-p
>  		       org-babel-call-process-region-original)
>  		      (symbol-function 'call-process-region)))
> -		 (indent (car (last info)))
> +		 (indent (nth 5 info))
>  		 result cmd)
>  	    (unwind-protect
>  		(let ((call-process-region
> @@ -1592,7 +1595,7 @@ If the point is not on a source block then return nil."
>          (< top initial) (< initial bottom)
>          (progn (goto-char top) (beginning-of-line 1)
>  	       (looking-at org-babel-src-block-regexp))
> -        (point))))))
> +        (point-marker))))))
>  
>  ;;;###autoload
>  (defun org-babel-goto-src-block-head ()

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

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

* Re: [PATCH] Make src block location available to execution backends
  2013-06-06 11:07 ` [PATCH] Make src block location available to execution backends Vitalie Spinu
  2013-06-06 15:18   ` Eric Schulte
@ 2013-06-24 20:56   ` Bastien
  1 sibling, 0 replies; 4+ messages in thread
From: Bastien @ 2013-06-24 20:56 UTC (permalink / raw)
  To: Vitalie Spinu; +Cc: emacs-orgmode

Hi Vitalie,

Vitalie Spinu <spinuvit@gmail.com> writes:

> I wrapped it in a patch. All tests are fine. Will be very happy if
> someone could have a glance. I have my FSF papers signed.

I added you to 

  http://orgmode.org/worg/org-contribute.html#contributors_with_fsf_papers

(We need to keep this list as accurate as possible.)

-- 
 Bastien

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

end of thread, other threads:[~2013-06-24 20:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-05 13:49 ob: Make src block location available to execution backend Vitalie Spinu
2013-06-06 11:07 ` [PATCH] Make src block location available to execution backends Vitalie Spinu
2013-06-06 15:18   ` Eric Schulte
2013-06-24 20:56   ` Bastien

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.