From b4b2809eb17f301ae59d0865840d45b3f3ff9f3e Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Tue, 28 Nov 2017 23:57:18 +0100 Subject: [PATCH] ob-core: Fix `org-babel-src-block-names' * lisp/ob-core.el (org-babel-src-block-names): Do not change visibility or windows when called. --- lisp/ob-core.el | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 9f367f2ad..17aae6843 100644 --- a/lisp/ob-core.el +++ b/lisp/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) -- 2.11.4.GIT