Fix inline src and inline babel calls parsing

* lisp/org-element.el (org-element-inline-babel-call-parser):
(org-element-inline-src-block-parser): Tolerate any prefix before the objects.

* testing/lisp/test-ob-exp.el (ob-exp/exports-inline-code):
* testing/lisp/test-org-element.el (test-org-element/inline-src-block-parser):
Update tests.

Reported-by: Greg Minshall <minshall@acm.org>
<http://lists.gnu.org/r/emacs-orgmode/2018-01/msg00489.html>
This commit is contained in:
Nicolas Goaziou 2018-01-30 10:11:02 +01:00
parent 5b4a711949
commit 7efa0f2879
3 changed files with 61 additions and 52 deletions

View File

@ -2849,7 +2849,7 @@ Assume point is at the beginning of the babel call."
(save-excursion (save-excursion
(catch :no-object (catch :no-object
(when (let ((case-fold-search nil)) (when (let ((case-fold-search nil))
(looking-at "\\<call_\\([^ \t\n[(]+\\)[([]")) (looking-at "call_\\([^ \t\n[(]+\\)[([]"))
(goto-char (match-end 1)) (goto-char (match-end 1))
(let* ((begin (match-beginning 0)) (let* ((begin (match-beginning 0))
(call (match-string-no-properties 1)) (call (match-string-no-properties 1))
@ -2903,7 +2903,7 @@ Assume point is at the beginning of the inline src block."
(save-excursion (save-excursion
(catch :no-object (catch :no-object
(when (let ((case-fold-search nil)) (when (let ((case-fold-search nil))
(looking-at "\\<src_\\([^ \t\n[{]+\\)[{[]")) (looking-at "src_\\([^ \t\n[{]+\\)[{[]"))
(goto-char (match-end 1)) (goto-char (match-end 1))
(let ((begin (match-beginning 0)) (let ((begin (match-beginning 0))
(language (match-string-no-properties 1)) (language (match-string-no-properties 1))

View File

@ -201,57 +201,65 @@ Here is one at the end of a line. {{{results(=2=)}}}
(org-test-with-expanded-babel-code (buffer-string))))))) (org-test-with-expanded-babel-code (buffer-string)))))))
(ert-deftest ob-exp/exports-inline-code () (ert-deftest ob-exp/exports-inline-code ()
(let ((org-babel-inline-result-wrap "=%s=") (should
(org-export-use-babel t)) (equal "src_emacs-lisp[]{(+ 1 1)}"
(should (org-test-with-temp-text "src_emacs-lisp[:exports code]{(+ 1 1)}"
(string-match "\\`src_emacs-lisp\\(?:\\[]\\)?{(\\+ 1 1)}$" (let ((org-babel-inline-result-wrap "=%s=")
(org-export-use-babel t))
(org-babel-exp-process-buffer))
(buffer-string))))
(should
(equal "src_emacs-lisp[]{(+ 1 1)}"
(org-test-with-temp-text "src_emacs-lisp[ :exports code ]{(+ 1 1)}"
(let ((org-babel-inline-result-wrap "=%s=")
(org-export-use-babel t))
(org-babel-exp-process-buffer))
(buffer-string))))
(should
(equal "src_emacs-lisp[]{(+ 1 1)} {{{results(=2=)}}}"
(org-test-with-temp-text "src_emacs-lisp[:exports both]{(+ 1 1)}"
(let ((org-babel-inline-result-wrap "=%s=")
(org-export-use-babel t))
(org-babel-exp-process-buffer))
(buffer-string))))
(should
(equal "{{{results(=2=)}}}"
(org-test-with-temp-text
"src_emacs-lisp[:exports results :results scalar]{(+ 1 1)}"
(let ((org-babel-inline-result-wrap "=%s=")
(org-export-use-babel t))
(org-babel-exp-process-buffer))
(buffer-string))))
(should
(equal "foosrc_emacs-lisp[]{(+ 1 1)}"
(org-test-with-temp-text
"foosrc_emacs-lisp[:exports code]{(+ 1 1)}"
(let ((org-babel-inline-result-wrap "=%s=")
(org-export-use-babel t))
(org-babel-exp-process-buffer))
(buffer-string))))
(should
(let ((text "src_emacs lisp{(+ 1 1)}"))
(string-match (regexp-quote text)
(org-test-with-temp-text (org-test-with-temp-text
"src_emacs-lisp[:exports code]{(+ 1 1)}" text
(org-babel-exp-process-buffer) (let ((org-babel-inline-result-wrap "=%s=")
(buffer-string)))) (org-export-use-babel t))
(should (org-babel-exp-process-buffer))
(string-match "\\`src_emacs-lisp\\(?:\\[]\\)?{(\\+ 1 1)}$" (buffer-string)))))
(org-test-with-temp-text (should
"src_emacs-lisp[ :exports code ]{(+ 1 1)}" (string-match
(org-babel-exp-process-buffer) (replace-regexp-in-string
(buffer-string)))) "\\\\\\[]{" "\\(?:\\[]\\)?{" ;accept both src_sh[]{...} or src_sh{...}
(should (regexp-quote "Here is one in the middle src_sh[]{echo 1} of a line.
(string-match "\\`src_emacs-lisp\\(?:\\[]\\)?{(\\+ 1 1)} {{{results(=2=)}}}$"
(org-test-with-temp-text
"src_emacs-lisp[:exports both]{(+ 1 1)}"
(org-babel-exp-process-buffer)
(buffer-string))))
(should
(string-match "\\`{{{results(=2=)}}}$"
(org-test-with-temp-text
"src_emacs-lisp[:exports results :results scalar]{(+ 1 1)}"
(org-babel-exp-process-buffer)
(buffer-string))))
(should
(let ((text "foosrc_emacs-lisp[:exports code]{(+ 1 1)}"))
(string-match (regexp-quote text)
(org-test-with-temp-text
text
(org-babel-exp-process-buffer)
(buffer-string)))))
(should
(let ((text "src_emacs lisp{(+ 1 1)}"))
(string-match (regexp-quote text)
(org-test-with-temp-text
text
(org-babel-exp-process-buffer)
(buffer-string)))))
(should
(string-match
(replace-regexp-in-string
"\\\\\\[]{" "\\(?:\\[]\\)?{" ;accept both src_sh[]{...} or src_sh{...}
(regexp-quote "Here is one in the middle src_sh[]{echo 1} of a line.
Here is one at the end of a line. src_sh[]{echo 2} Here is one at the end of a line. src_sh[]{echo 2}
src_sh[]{echo 3} Here is one at the beginning of a line. src_sh[]{echo 3} Here is one at the beginning of a line.
Here is one that is also evaluated: src_sh[]{echo 4} {{{results(=4=)}}}") Here is one that is also evaluated: src_sh[]{echo 4} {{{results(=4=)}}}")
nil t) nil t)
(org-test-at-id "cd54fc88-1b6b-45b6-8511-4d8fa7fc8076" (org-test-at-id "cd54fc88-1b6b-45b6-8511-4d8fa7fc8076"
(org-narrow-to-subtree) (org-narrow-to-subtree)
(let ((org-babel-inline-result-wrap "=%s=")
(org-export-use-babel t))
(org-test-with-expanded-babel-code (buffer-string))))))) (org-test-with-expanded-babel-code (buffer-string)))))))
(ert-deftest ob-exp/exports-inline-code-double-eval () (ert-deftest ob-exp/exports-inline-code-double-eval ()

View File

@ -1210,6 +1210,10 @@ Some other text
(should (should
(org-test-with-temp-text "src_emacs-lisp{(+ 1 1)}" (org-test-with-temp-text "src_emacs-lisp{(+ 1 1)}"
(org-element-map (org-element-parse-buffer) 'inline-src-block 'identity))) (org-element-map (org-element-parse-buffer) 'inline-src-block 'identity)))
;; With prefix.
(should
(org-test-with-temp-text "foosrc_emacs-lisp[]{(+ 1 1)}"
(org-element-map (org-element-parse-buffer) 'inline-src-block 'identity)))
;; With switches. ;; With switches.
(should (should
(org-test-with-temp-text "src_emacs-lisp[:foo bar]{(+ 1 1)}" (org-test-with-temp-text "src_emacs-lisp[:foo bar]{(+ 1 1)}"
@ -1222,9 +1226,6 @@ Some other text
(org-test-with-temp-text "src_emacs-lisp[]{(+ 1 1)}" (org-test-with-temp-text "src_emacs-lisp[]{(+ 1 1)}"
(org-element-map (org-element-parse-buffer) 'inline-src-block 'identity))) (org-element-map (org-element-parse-buffer) 'inline-src-block 'identity)))
;; Invalid syntax. ;; Invalid syntax.
(should-not
(org-test-with-temp-text "foosrc_emacs-lisp[]{(+ 1 1)}"
(org-element-map (org-element-parse-buffer) 'inline-src-block 'identity)))
(should-not (should-not
(org-test-with-temp-text "src_emacs-lisp[]foo{(+ 1 1)}" (org-test-with-temp-text "src_emacs-lisp[]foo{(+ 1 1)}"
(org-element-map (org-element-parse-buffer) 'inline-src-block 'identity))) (org-element-map (org-element-parse-buffer) 'inline-src-block 'identity)))