emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Martyn Jago <martyn.jago@btinternet.com>
To: emacs-orgmode@gnu.org
Subject: [PATCH] Fixes to inline src block execution
Date: Mon, 05 Sep 2011 23:43:20 +0100	[thread overview]
Message-ID: <m27h5m4nlj.fsf@btinternet.com> (raw)

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


Hi

Some fixes to inline src block execution via org-ctrl-c-ctrl-c
where point is beyond white-space in the inline src block body...

* Start Pomodoro
 #src_emacs-lisp[:results silent]{( org-timer-set-timer 25 )} 
                         ^
,------------------------'
| C-c C-c execution
| was broken beyond 
| here
`------------------

Also fixes to inline src block execution where the inline src block 
happens to be on the first line of a buffer. 

I've included tests and test data.

Regards

Martyn


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Fixes to inline src block execution --]
[-- Type: text/x-patch, Size: 6140 bytes --]

From b559789474920f0471f5844b4675be67a74a8283 Mon Sep 17 00:00:00 2001
From: Martyn Jago <martyn.jago@btinternet.com>
Date: Mon, 5 Sep 2011 22:53:07 +0100
Subject: [PATCH] Bug fixes to inline source block execution triggering.
 * lisp/ob.el: Created org-babel-get-inline-src-block-matches() to fix
 problems with org-ctrl-c-ctrl-c not triggering inline src block
 execution when point is on or after a space within the inline src
 block body. Also fixed execution problems where inline src block is on
 buffer line 1.
 * testing/examples/babel.org: Test data for
 org-babel-get-inline-src-block-matches()

* testing/lisp/test-ob.el: Tests for
  org-babel-get-inline-src-block-matches()
---
 lisp/ob.el                 |   48 ++++++++++++++++++++++++++++++++++---------
 testing/examples/babel.org |    9 ++++++++
 testing/lisp/test-ob.el    |   23 +++++++++++++++++++++
 3 files changed, 70 insertions(+), 10 deletions(-)

diff --git a/lisp/ob.el b/lisp/ob.el
index e424ff1..2964f82 100644
--- a/lisp/ob.el
+++ b/lisp/ob.el
@@ -159,6 +159,39 @@ not match KEY should be returned."
 	 (lambda (p) (when (funcall (if others #'not #'identity) (eq (car p) key)) p))
 	 params)))
 
+(defun org-babel-get-inline-src-block-matches()
+  "Set match data if within body of an inline source block.
+Returns non-nil if match-data set"
+  (let ((src-at-0-p (save-excursion
+		      (beginning-of-line 1)
+		      (string= "src" (thing-at-point 'word))))
+	(first-line-p (= 1 (line-number-at-pos)))
+      (orig (point)))
+    (let ((search-for (cond (src-at-0-p "src_")
+			    (first-line-p " src_")
+			    (t "[ \f\t\n\r\v]src_")))
+	  (lower-limit (if (= 1 (line-number-at-pos))
+			   nil
+			 (- (point-at-bol) 1))))
+      (save-excursion
+	(when (or (and src-at-0-p (bobp))
+		  (and (re-search-forward "}" (point-at-eol) t)
+		       (re-search-backward search-for lower-limit t)
+		       (> orig (point))))
+	  (when (looking-at org-babel-inline-src-block-regexp)
+	    t ))))))
+
+(defun org-babel-get-lob-one-liner-matches()
+  "Set match data if on line of an lob one liner.
+Returns non-nil if match-data set"
+
+  (save-excursion
+    (unless (= (point) (point-at-bol)) ;; move before inline block
+      (re-search-backward "[ \f\t\n\r\v]" nil t))
+    (if (looking-at org-babel-inline-lob-one-liner-regexp)
+	t
+      nil)))
+
 (defun org-babel-get-src-block-info (&optional light)
   "Get information on the current source block.
 
@@ -191,8 +224,7 @@ Returns a list
 			     (org-babel-ref-split-args (match-string 6)))
 		     (nth 2 info))))))
       ;; inline source block
-      (when (save-excursion (re-search-backward "[ \f\t\n\r\v]" nil t)
-			    (looking-at org-babel-inline-src-block-regexp))
+      (when (org-babel-get-inline-src-block-matches)
 	(setq info (org-babel-parse-inline-src-block-match))))
     ;; resolve variable references and add summary parameters
     (when (and info (not light))
@@ -1387,10 +1419,8 @@ following the source block."
     (let* ((on-lob-line (save-excursion
 			  (beginning-of-line 1)
 			  (looking-at org-babel-lob-one-liner-regexp)))
-	   (inlinep (save-excursion
-		      (re-search-backward "[ \f\t\n\r\v]" nil t)
-		      (when (looking-at org-babel-inline-src-block-regexp)
-			(match-end 0))))
+	   (inlinep (when (org-babel-get-inline-src-block-matches)
+			(match-end 0)))
 	   (name (if on-lob-line
 		     (nth 0 (org-babel-lob-get-info))
 		   (nth 4 (or info (org-babel-get-src-block-info 'light)))))
@@ -1578,10 +1608,8 @@ code ---- the results are extracted in the syntax of the source
     (save-excursion
       (let* ((inlinep
 	      (save-excursion
-		(unless (= (point) (point-at-bol)) ;; move before inline block
-		  (re-search-backward "[ \f\t\n\r\v]" nil t))
-		(when (or (looking-at org-babel-inline-src-block-regexp)
-			  (looking-at org-babel-inline-lob-one-liner-regexp))
+		(when (or (org-babel-get-inline-src-block-matches)
+			  (org-babel-get-lob-one-liner-matches))
 		  (goto-char (match-end 0))
 		  (insert (if (listp result) "\n" " "))
 		  (point))))
diff --git a/testing/examples/babel.org b/testing/examples/babel.org
index 3dc603d..f85e1f0 100644
--- a/testing/examples/babel.org
+++ b/testing/examples/babel.org
@@ -279,3 +279,12 @@ this is simple
    :ID:       d4faa7b3-072b-4dcf-813c-dd7141c633f3
    :END:
 has length 14
+* org-babel-get-inline-src-block-matches
+  :PROPERTIES:  
+  :results:  silent
+  :ID:       0D0983D4-DE33-400A-8A05-A225A567BC74
+  :END:
+src_sh{echo "One"} block at start of line
+ One spaced block in  src_sh{ echo "middle" } of line 
+src_sh{echo 2} blocks on the src_emacs-lisp{"same"} line
+ Inline block with src_sh[:results silent]{ echo "parameters" }.
diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el
index dbc7dbd..71ea7e2 100644
--- a/testing/lisp/test-ob.el
+++ b/testing/lisp/test-ob.el
@@ -223,6 +223,29 @@
       (next) (should (equal 2 (org-babel-execute-src-block)))
       (next) (should (equal 3 (org-babel-execute-src-block))))))
 
+(ert-deftest test-org-babel/org-babel-get-inline-src-block-matches ()
+  (org-test-at-id "0D0983D4-DE33-400A-8A05-A225A567BC74"
+    (should (fboundp 'org-babel-get-inline-src-block-matches))
+    (should (re-search-forward "src_" nil t)) ;; 1
+    (should (= 6132 (match-end 0)))
+    (should (org-babel-get-inline-src-block-matches))
+    (should (re-search-forward "}" nil (point-at-bol))) ;; 1
+    (should-not (org-babel-get-inline-src-block-matches))
+    (should (re-search-forward "in" nil t)) ;; 2
+    (should-not (org-babel-get-inline-src-block-matches))
+    (should (re-search-forward "echo" nil t)) ;; 2
+    (should (org-babel-get-inline-src-block-matches))
+    (should (re-search-forward "blocks" nil t)) ;; 3
+    (left-char 8) ;; 3
+    (should (org-babel-get-inline-src-block-matches))
+    (right-char 1) ;;3
+    (should-not (org-babel-get-inline-src-block-matches))
+    (should (re-search-forward ":results" nil t)) ;; 4
+    (should (org-babel-get-inline-src-block-matches))
+    (end-of-line)
+    (should-not (org-babel-get-inline-src-block-matches))
+    ))
+
 (provide 'test-ob)
 
 ;;; test-ob ends here
-- 
1.7.3.4


             reply	other threads:[~2011-09-05 22:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-05 22:43 Martyn Jago [this message]
2011-09-06  3:31 ` [PATCH] Fixes to inline src block execution Eric Schulte
2011-09-06  8:19   ` Martyn Jago
2011-09-06 15:12     ` Eric Schulte

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=m27h5m4nlj.fsf@btinternet.com \
    --to=martyn.jago@btinternet.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).