summaryrefslogtreecommitdiff
path: root/lisp/org/ob-core.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/org/ob-core.el')
-rw-r--r--lisp/org/ob-core.el60
1 files changed, 31 insertions, 29 deletions
diff --git a/lisp/org/ob-core.el b/lisp/org/ob-core.el
index c7c03845451..17aae68434a 100644
--- a/lisp/org/ob-core.el
+++ b/lisp/org/ob-core.el
@@ -1765,15 +1765,17 @@ to `org-babel-named-src-block-regexp'."
(defun org-babel-src-block-names (&optional file)
"Returns the names of source blocks in FILE or the current buffer."
- (when file (find-file file))
- (save-excursion
- (goto-char (point-min))
- (let* ((re (org-babel-named-src-block-regexp-for-name))
- (names (and (looking-at re)
- (list (match-string-no-properties 9)))))
- (while (ignore-errors (org-next-block 1 nil re))
- (push (match-string-no-properties 9) names))
- names)))
+ (with-current-buffer (if file (find-file-noselect file) (current-buffer))
+ (org-with-point-at 1
+ (let ((regexp "^[ \t]*#\\+begin_src ")
+ (case-fold-search t)
+ (names nil))
+ (while (re-search-forward regexp nil t)
+ (let ((element (org-element-at-point)))
+ (when (eq 'src-block (org-element-type element))
+ (let ((name (org-element-property :name element)))
+ (when name (push name names))))))
+ names))))
;;;###autoload
(defun org-babel-goto-named-result (name)
@@ -2416,8 +2418,11 @@ INFO may provide the values of these header arguments (in the
(goto-char location)
(when (looking-at (concat org-babel-result-regexp ".*$"))
(delete-region
- (if keep-keyword (1+ (match-end 0)) (1- (match-beginning 0)))
- (progn (forward-line 1) (org-babel-result-end))))))))
+ (if keep-keyword (line-beginning-position 2)
+ (save-excursion
+ (skip-chars-backward " \r\t\n")
+ (line-beginning-position 2)))
+ (progn (forward-line) (org-babel-result-end))))))))
(defun org-babel-remove-inline-result (&optional datum)
"Remove the result of the current inline-src-block or babel call.
@@ -2454,24 +2459,21 @@ in the buffer."
(defun org-babel-result-end ()
"Return the point at the end of the current set of results."
- (save-excursion
- (cond
- ((org-at-table-p) (progn (goto-char (org-table-end)) (point)))
- ((org-at-item-p) (let* ((struct (org-list-struct))
- (prvs (org-list-prevs-alist struct)))
- (org-list-get-list-end (point-at-bol) struct prvs)))
- ((let ((case-fold-search t)) (looking-at "^\\([ \t]*\\):results:"))
- (progn (re-search-forward (concat "^" (match-string 1) ":END:"))
- (forward-char 1) (point)))
- (t
- (let ((case-fold-search t))
- (if (looking-at (concat "[ \t]*#\\+begin_\\([^ \t\n\r]+\\)"))
- (progn (re-search-forward (concat "[ \t]*#\\+end_" (match-string 1))
- nil t)
- (forward-char 1))
- (while (looking-at "[ \t]*\\(: \\|:$\\|\\[\\[\\)")
- (forward-line 1))))
- (point)))))
+ (cond ((looking-at-p "^[ \t]*$") (point)) ;no result
+ ((looking-at-p (format "^[ \t]*%s[ \t]*$" org-bracket-link-regexp))
+ (line-beginning-position 2))
+ (t
+ (let ((element (org-element-at-point)))
+ (if (memq (org-element-type element)
+ ;; Possible results types.
+ '(drawer example-block export-block fixed-width item
+ plain-list src-block table))
+ (save-excursion
+ (goto-char (min (point-max) ;for narrowed buffers
+ (org-element-property :end element)))
+ (skip-chars-backward " \r\t\n")
+ (line-beginning-position 2))
+ (point))))))
(defun org-babel-result-to-file (result &optional description)
"Convert RESULT into an `org-mode' link with optional DESCRIPTION.