From mboxrd@z Thu Jan 1 00:00:00 1970 From: Martyn Jago Subject: Re: [babel][patch] BUG in inline source blocks Date: Thu, 26 Jan 2012 13:29:10 +0000 Message-ID: References: <87fwf27w67.fsf@med.uni-goettingen.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([140.186.70.92]:60783) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RqPOR-0005us-Hc for emacs-orgmode@gnu.org; Thu, 26 Jan 2012 08:29:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RqPOM-0008MF-VW for emacs-orgmode@gnu.org; Thu, 26 Jan 2012 08:29:35 -0500 Received: from lo.gmane.org ([80.91.229.12]:33259) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RqPOM-0008M7-KG for emacs-orgmode@gnu.org; Thu, 26 Jan 2012 08:29:30 -0500 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1RqPOK-0001Yh-Ct for emacs-orgmode@gnu.org; Thu, 26 Jan 2012 14:29:28 +0100 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 ; Thu, 26 Jan 2012 14:29:28 +0100 Received: from martyn.jago by 88-96-171-142.dsl.zen.co.uk with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 26 Jan 2012 14:29:28 +0100 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, Andreas Leha writes: > Hi all, > > I experience unexpected behaviour when an inline source block is not > preceded by whitespace. > > Example: > ======================= > * Test inline > This is a functional inline src_R{print("source block")}. > > This (src_R{print("here")}) is not. > ======================= > > Regards, > Andreas I can confirm this behaviour and provide a patch to allow for inline source blocks to be preceded by punctuation, or, for instance, enclosed in parenthesis, as in Andreas' example. Patch is attached for consideration. Best, Martyn --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Fix-for-where-inline-source-block-is-not-preceded-by.patch Content-Description: Fix inline source block preceded by punctuation >From ce7ccfe97ce640f47ed83cdb2fdb6ffa8a6d3c54 Mon Sep 17 00:00:00 2001 From: Martyn Jago Date: Thu, 26 Jan 2012 13:22:25 +0000 Subject: [PATCH] Fix for where inline source block is not preceded by whitespace but by punctuation (reported by Andreas Leha). * lisp/ob.el: Fix for where inline source block is not preceded by whitespace but by punctuation. * testing/lisp/test-ob.el: Regression test, testing inline source block preceded by point, equality, and enclosed in parenthesis and brackets. --- lisp/ob.el | 21 ++++++++++++--------- testing/lisp/test-ob.el | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 9 deletions(-) diff --git a/lisp/ob.el b/lisp/ob.el index 70c258f..fbf032b 100644 --- a/lisp/ob.el +++ b/lisp/ob.el @@ -170,24 +170,27 @@ not match KEY should be returned." (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 + (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 ((and src-at-0-p first-line-p "src_")) - (first-line-p "[ \t]src_") - (t "[ \f\t\n\r\v]src_"))) - (lower-limit (if first-line-p - nil - (- (point-at-bol) 1)))) + (orig (point)) + (search-for (cond ((and src-at-0-p first-line-p "src_")) + (first-line-p "[ \t[:punct:]]src_") + (t "[ \f\t\n\r\v[:punct:]]src_"))) + (lower-limit (if first-line-p + nil + (- (point-at-bol) 1)))) + (message "src-at-0-p = %S" src-at-0-p) + (message "first-line-p = %S" src-at-0-p) + (message "search-for = %S" search-for) (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 )))))) + t ))))) (defvar org-babel-inline-lob-one-liner-regexp) (defun org-babel-get-lob-one-liner-matches() diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el index 7dccd22..fb38ead 100644 --- a/testing/lisp/test-ob.el +++ b/testing/lisp/test-ob.el @@ -430,6 +430,50 @@ this is simple" (buffer-substring-no-properties (point-min) (point-max))))))) +(ert-deftest test-org-babel/inline-src_blk-preceded-punct () + "Test inline source block where preceded by punctuation" + + ;; inline-src-blk preceded by point + (let ((test-line ".src_emacs-lisp[ :results verbatim ]{ \"x\" }")) + (org-test-with-temp-text + test-line + (forward-char 1) + (org-ctrl-c-ctrl-c) + (should (string= (concat test-line " =\"x\"=") + (buffer-substring-no-properties + (point-min) (point-max)))))) + + ;; inline-src-blk preceded by equality + (let ((test-line "=src_emacs-lisp[ :results verbatim ]{ \"x\" }")) + (org-test-with-temp-text + test-line + (forward-char 1) + (org-ctrl-c-ctrl-c) + (should (string= (concat test-line " =\"x\"=") + (buffer-substring-no-properties + (point-min) (point-max)))))) + + ;; inline-src-blk enclosed within parenthesis + (let ((test-line "(src_emacs-lisp[ :results verbatim ]{ \"x\" }")) + (org-test-with-temp-text + (concat test-line ")") + (forward-char 1) + (org-ctrl-c-ctrl-c) + (should (string= (concat test-line " =\"x\"=)" ) + (buffer-substring-no-properties + (point-min) (point-max)))))) + + ;; inline-src-blk enclosed within parenthesis + (let ((test-line "{src_emacs-lisp[ :results verbatim ]{ \"x\" }")) + (org-test-with-temp-text + (concat test-line "}") + (forward-char 1) + (org-ctrl-c-ctrl-c) + (should (string= (concat test-line " =\"x\"=}") + (buffer-substring-no-properties + (point-min) (point-max)))))) + + ) (ert-deftest test-org-babel/combining-scalar-and-raw-result-types () (org-test-with-temp-text-in-file " -- 1.7.3.4 --=-=-=--