* [babel] BUG in inline source blocks @ 2012-01-26 7:36 Andreas Leha 2012-01-26 13:29 ` [babel][patch] " Martyn Jago 0 siblings, 1 reply; 8+ messages in thread From: Andreas Leha @ 2012-01-26 7:36 UTC (permalink / raw) To: emacs-orgmode 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 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [babel][patch] BUG in inline source blocks 2012-01-26 7:36 [babel] BUG in inline source blocks Andreas Leha @ 2012-01-26 13:29 ` Martyn Jago 2012-01-26 19:55 ` Martyn Jago 0 siblings, 1 reply; 8+ messages in thread From: Martyn Jago @ 2012-01-26 13:29 UTC (permalink / raw) To: emacs-orgmode [-- Attachment #1: Type: text/plain, Size: 617 bytes --] Hi, Andreas Leha <andreas.leha@med.uni-goettingen.de> 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 [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: Fix inline source block preceded by punctuation --] [-- Type: text/x-patch, Size: 4109 bytes --] From ce7ccfe97ce640f47ed83cdb2fdb6ffa8a6d3c54 Mon Sep 17 00:00:00 2001 From: Martyn Jago <martyn.jago@btinternet.com> 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 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [babel][patch] BUG in inline source blocks 2012-01-26 13:29 ` [babel][patch] " Martyn Jago @ 2012-01-26 19:55 ` Martyn Jago 2012-01-27 22:26 ` Andreas Leha 0 siblings, 1 reply; 8+ messages in thread From: Martyn Jago @ 2012-01-26 19:55 UTC (permalink / raw) To: emacs-orgmode [-- Attachment #1: Type: text/plain, Size: 819 bytes --] Martyn Jago <martyn.jago@btinternet.com> writes: > Hi, > > Andreas Leha <andreas.leha@med.uni-goettingen.de> 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 This is an updated version of the previous patch, with debug noise removed, and a couple of extra tests. Best, Martyn [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: inline src block preceeded by punctuation patch --] [-- Type: text/x-patch, Size: 5032 bytes --] From b46e7a496c30f683c50759013ad39a9d8c6ff42b Mon Sep 17 00:00:00 2001 From: Martyn Jago <martyn.jago@btinternet.com> Date: Thu, 26 Jan 2012 19:48:35 +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 tests. --- lisp/ob.el | 30 ++++++++++---------- testing/lisp/test-ob.el | 69 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 15 deletions(-) diff --git a/lisp/ob.el b/lisp/ob.el index 70c258f..fd6a897 100644 --- a/lisp/ob.el +++ b/lisp/ob.el @@ -170,24 +170,24 @@ 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)))) - (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 )))))) + (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)))) + (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 ))))) (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..f4363f6 100644 --- a/testing/lisp/test-ob.el +++ b/testing/lisp/test-ob.el @@ -430,6 +430,75 @@ 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/inline-src_blk-preceded-by-letter () + "Test inline source block invalid where preceded by letter" + + ;; inline-src-blk preceded by letter + (org-test-with-temp-text + "asrc_emacs-lisp[ :results verbatim ]{ \"x\" }" + (forward-char 1) + (let ((error-result + (should-error + (org-ctrl-c-ctrl-c)))) + (should (equal `(error "C-c C-c can do nothing useful at this location") + error-result))))) + +(ert-deftest test-org-babel/inline-src_blk-preceded-by-number () + "Test inline source block invalid where preceded by number" + + ;; inline-src-blk preceded by number + (org-test-with-temp-text + "0src_emacs-lisp[ :results verbatim ]{ \"x\" }" + (forward-char 1) + (let ((error-result + (should-error + (org-ctrl-c-ctrl-c)))) + (should (equal `(error "C-c C-c can do nothing useful at this location") + error-result))))) + (ert-deftest test-org-babel/combining-scalar-and-raw-result-types () (org-test-with-temp-text-in-file " -- 1.7.3.4 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [babel][patch] BUG in inline source blocks 2012-01-26 19:55 ` Martyn Jago @ 2012-01-27 22:26 ` Andreas Leha 2012-01-27 23:33 ` Eric Schulte 0 siblings, 1 reply; 8+ messages in thread From: Andreas Leha @ 2012-01-27 22:26 UTC (permalink / raw) To: emacs-orgmode Martyn Jago <martyn.jago@btinternet.com> writes: > Martyn Jago <martyn.jago@btinternet.com> writes: > >> Hi, >> >> Andreas Leha <andreas.leha@med.uni-goettingen.de> 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 > > This is an updated version of the previous patch, with debug noise > removed, and a couple of extra tests. > > Best, Martyn Hi Martyn, thanks for this patch! It does half the job for me. Now export (or evaluation) already work. But in the export I get a space inserted. I my example, I'd expect "(here)" to appear in the export, but I get "( here)". Best, Andreas ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [babel][patch] BUG in inline source blocks 2012-01-27 22:26 ` Andreas Leha @ 2012-01-27 23:33 ` Eric Schulte 2012-01-28 9:28 ` Andreas Leha 0 siblings, 1 reply; 8+ messages in thread From: Eric Schulte @ 2012-01-27 23:33 UTC (permalink / raw) To: Andreas Leha; +Cc: emacs-orgmode Andreas Leha <andreas.leha@med.uni-goettingen.de> writes: > Martyn Jago <martyn.jago@btinternet.com> writes: > >> Martyn Jago <martyn.jago@btinternet.com> writes: >> >>> Hi, >>> >>> Andreas Leha <andreas.leha@med.uni-goettingen.de> 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 >> >> This is an updated version of the previous patch, with debug noise >> removed, and a couple of extra tests. >> >> Best, Martyn > Thanks for this patch Martyn, I just pushed up your [:punct:] change. > > Hi Martyn, > > thanks for this patch! It does half the job for me. Now export (or > evaluation) already work. But in the export I get a space inserted. > > I my example, I'd expect "(here)" to appear in the export, but I get "( here)". > This should now be fixed. Best, > > Best, > Andreas > > -- Eric Schulte http://cs.unm.edu/~eschulte/ ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [babel][patch] BUG in inline source blocks 2012-01-27 23:33 ` Eric Schulte @ 2012-01-28 9:28 ` Andreas Leha 2012-01-29 0:34 ` Martyn Jago 0 siblings, 1 reply; 8+ messages in thread From: Andreas Leha @ 2012-01-28 9:28 UTC (permalink / raw) To: emacs-orgmode Eric Schulte <eric.schulte@gmx.com> writes: > Andreas Leha <andreas.leha@med.uni-goettingen.de> writes: > >> Martyn Jago <martyn.jago@btinternet.com> writes: >> >>> Martyn Jago <martyn.jago@btinternet.com> writes: >>> >>>> Hi, >>>> >>>> Andreas Leha <andreas.leha@med.uni-goettingen.de> 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 >>> >>> This is an updated version of the previous patch, with debug noise >>> removed, and a couple of extra tests. >>> >>> Best, Martyn >> > > Thanks for this patch Martyn, I just pushed up your [:punct:] change. > >> >> Hi Martyn, >> >> thanks for this patch! It does half the job for me. Now export (or >> evaluation) already work. But in the export I get a space inserted. >> >> I my example, I'd expect "(here)" to appear in the export, but I get >> "( here)". >> > > This should now be fixed. > Thanks, Martyn and Eric! Indeed "both" issues are fixed now. Regards, Andreas ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [babel][patch] BUG in inline source blocks 2012-01-28 9:28 ` Andreas Leha @ 2012-01-29 0:34 ` Martyn Jago 2012-01-30 16:06 ` Eric Schulte 0 siblings, 1 reply; 8+ messages in thread From: Martyn Jago @ 2012-01-29 0:34 UTC (permalink / raw) To: emacs-orgmode Hi Eric Andreas Leha <andreas.leha@med.uni-goettingen.de> writes: [...] >> Thanks for this patch Martyn, I just pushed up your [:punct:] change. >> >>> >>> Hi Martyn, >>> >>> thanks for this patch! It does half the job for me. Now export (or >>> evaluation) already work. But in the export I get a space inserted. >>> >>> I my example, I'd expect "(here)" to appear in the export, but I get >>> "( here)". >>> >> >> This should now be fixed. >> > > Thanks, Martyn and Eric! Indeed "both" issues are fixed now. > > Regards, > Andreas Thanks. But out of interest why were the tests discarded? They are after all the proof that the code works, and the `living specification' of expected behavior. Just wondering Best, Martyn ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [babel][patch] BUG in inline source blocks 2012-01-29 0:34 ` Martyn Jago @ 2012-01-30 16:06 ` Eric Schulte 0 siblings, 0 replies; 8+ messages in thread From: Eric Schulte @ 2012-01-30 16:06 UTC (permalink / raw) To: Martyn Jago; +Cc: emacs-orgmode > > Thanks. But out of interest why were the tests discarded? They are after > all the proof that the code works, and the `living specification' of > expected behavior. > > Just wondering > My apologies, I didn't see the tests when looking at your patch and didn't realize they were there. Thanks for mentioning this, I have now applied them. BTW: the only reason I didn't apply your patch outright was because by the time I got to your message in the thread I had already pushed up my own (less comprehensive) patch which conflicted with your own. Also, as a more general note to everyone who works with and submits patches. It is worthwhile to review the text of a patch before submitting because often trivial things like changed indentation can add many lines to a patch file hiding the actual code changes. Cheers, -- Eric Schulte http://cs.unm.edu/~eschulte/ ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2012-01-30 16:06 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2012-01-26 7:36 [babel] BUG in inline source blocks Andreas Leha 2012-01-26 13:29 ` [babel][patch] " Martyn Jago 2012-01-26 19:55 ` Martyn Jago 2012-01-27 22:26 ` Andreas Leha 2012-01-27 23:33 ` Eric Schulte 2012-01-28 9:28 ` Andreas Leha 2012-01-29 0:34 ` Martyn Jago 2012-01-30 16:06 ` 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).