From b46e7a496c30f683c50759013ad39a9d8c6ff42b Mon Sep 17 00:00:00 2001 From: Martyn Jago 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