From mboxrd@z Thu Jan 1 00:00:00 1970 From: Martyn Jago Subject: [PATCH] Fixes to inline src block execution Date: Mon, 05 Sep 2011 23:43:20 +0100 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([140.186.70.92]:52082) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R0htD-0001eP-Oi for emacs-orgmode@gnu.org; Mon, 05 Sep 2011 18:43:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R0htC-00070U-7w for emacs-orgmode@gnu.org; Mon, 05 Sep 2011 18:43:39 -0400 Received: from lo.gmane.org ([80.91.229.12]:36282) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R0htB-00070P-S9 for emacs-orgmode@gnu.org; Mon, 05 Sep 2011 18:43:38 -0400 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1R0htA-0004lL-2q for emacs-orgmode@gnu.org; Tue, 06 Sep 2011 00:43:36 +0200 Received: from 88-96-171-142.dsl.zen.co.uk ([88.96.171.142]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 06 Sep 2011 00:43:36 +0200 Received: from martyn.jago by 88-96-171-142.dsl.zen.co.uk with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 06 Sep 2011 00:43:36 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain 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 --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=patch.diff Content-Description: Fixes to inline src block execution >From b559789474920f0471f5844b4675be67a74a8283 Mon Sep 17 00:00:00 2001 From: Martyn Jago 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 --=-=-=--