summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2016-02-10 16:06:41 +0100
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2016-02-10 23:50:45 +0100
commit867263c207963c463cb60d948cf058ebf0f537c5 (patch)
tree160013f26f467ddf38cf8b0e2d14c322b436f23b
parent9738da473277712804e0d004899388ad71c6b791 (diff)
downloadorg-mode-867263c207963c463cb60d948cf058ebf0f537c5.tar.gz
ob: Remove `org-babel-get-inline-src-block-matches'
* lisp/ob-core.el (org-babel-get-inline-src-block-matches): Remove function. (org-babel-when-in-src-block): (org-babel-insert-result): Do not use removed function. (org-babel-remove-inline-result): Add an optional argument for a tiny speed-up. * testing/examples/babel.org: * testing/lisp/test-ob.el (test-ob/inline-src_blk-default-results-replace-line-1): Remove needless tests.
-rw-r--r--lisp/ob-core.el50
-rw-r--r--testing/examples/babel.org20
-rw-r--r--testing/lisp/test-ob.el26
3 files changed, 21 insertions, 75 deletions
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 0c98987..c4db64d 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -223,16 +223,6 @@ list of the cdr of all the `:var' entries."
(mapcar #'cdr
(cl-remove-if-not (lambda (x) (eq (car x) :var)) 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"
- (save-excursion
- (let ((datum (org-element-context)))
- (when (eq (org-element-type datum) 'inline-src-block)
- (goto-char (org-element-property :begin datum))
- (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 ()
"Set match data if on line of an lob one liner.
@@ -410,8 +400,8 @@ environment, to override this check."
"Execute BODY if point is in a source block and return t.
Otherwise do nothing and return nil."
- `(if (or (org-babel-where-is-src-block-head)
- (org-babel-get-inline-src-block-matches))
+ `(if (memq (org-element-type (org-element-context))
+ '(inline-src-block src-block))
(progn
,@body
t)
@@ -2208,13 +2198,15 @@ INFO may provide the values of these header arguments (in the
result)
(save-excursion
(let* ((inlinep
- (save-excursion
- (when (or (org-babel-get-inline-src-block-matches)
- (org-babel-get-lob-one-liner-matches))
- (goto-char (match-end 0))
- (org-babel-remove-inline-result)
- (insert " ")
- (point))))
+ (let ((context (org-element-context)))
+ (when (memq (org-element-type context)
+ '(inline-babel-call inline-src-block))
+ (save-excursion
+ (goto-char (org-element-property :end context))
+ (skip-chars-backward " \t\n")
+ (org-babel-remove-inline-result context)
+ (insert " ")
+ (point)))))
(existing-result
(unless inlinep
(org-babel-where-is-src-block-result t info hash)))
@@ -2404,23 +2396,23 @@ INFO may provide the values of these header arguments (in the
(if keep-keyword (1+ (match-end 0)) (1- (match-beginning 0)))
(progn (forward-line 1) (org-babel-result-end))))))))
-(defun org-babel-remove-inline-result ()
+(defun org-babel-remove-inline-result (&optional datum)
"Remove the result of the current inline-src-block or babel call.
The result must be wrapped in a `results' macro to be removed.
Leading whitespace is trimmed."
(interactive)
- (let* ((el (org-element-context))
+ (let* ((el (or datum (org-element-context)))
(post-blank (org-element-property :post-blank el)))
(when (memq (org-element-type el) '(inline-src-block inline-babel-call))
(org-with-wide-buffer
- (goto-char (org-element-property :end el))
- (let ((el (org-element-context)))
- (when (and (eq (org-element-type el) 'macro)
- (string= (org-element-property :key el) "results"))
- (delete-region ; And leading whitespace.
- (- (org-element-property :begin el) post-blank)
- (- (org-element-property :end el)
- (org-element-property :post-blank el)))))))))
+ (goto-char (org-element-property :end el))
+ (let ((el (org-element-context)))
+ (when (and (eq (org-element-type el) 'macro)
+ (string= (org-element-property :key el) "results"))
+ (delete-region ; And leading whitespace.
+ (- (org-element-property :begin el) post-blank)
+ (- (org-element-property :end el)
+ (org-element-property :post-blank el)))))))))
(defun org-babel-remove-result-one-or-many (x)
"Remove the result of the current source block.
diff --git a/testing/examples/babel.org b/testing/examples/babel.org
index 4560db5..6f31a26 100644
--- a/testing/examples/babel.org
+++ b/testing/examples/babel.org
@@ -283,26 +283,6 @@ this is simple
: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" }.
-
-* org-babel-get-inline-src-block-matches (with empty args)
- :PROPERTIES:
- :results: silent
- :ID: d55dada7-de0e-4340-8061-787cccbedee5
- :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" }.
-
* exporting a code block with a name
:PROPERTIES:
:ID: b02ddd8a-eeb8-42ab-8664-8a759e6f43d9
diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el
index 07a69bb..7c6b713 100644
--- a/testing/lisp/test-ob.el
+++ b/testing/lisp/test-ob.el
@@ -279,32 +279,6 @@ at the beginning of a line."
:results silent]{(+ 6 1)}"
(org-babel-execute-src-block)))))
-(ert-deftest test-ob/org-babel-get-inline-src-block-matches ()
- (flet ((test-at-id (id)
- (org-test-at-id
- id
- (let ((test-point (point)))
- (should (fboundp 'org-babel-get-inline-src-block-matches))
- (should (re-search-forward "src_" nil t)) ;; 1
- (should (org-babel-get-inline-src-block-matches))
- (should (re-search-forward " b" 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
- (backward-char 7) ;; 3
- (should (org-babel-get-inline-src-block-matches))
- (forward-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))))))
- (test-at-id "0D0983D4-DE33-400A-8A05-A225A567BC74")
- (test-at-id "d55dada7-de0e-4340-8061-787cccbedee5")))
-
(ert-deftest test-ob/inline-src_blk-default-results-replace-line-1 ()
(let ((test-line "src_sh{echo 1}")
(org-babel-inline-result-wrap "=%s="))