From b862c24b9fb2591dc6240bfbd3a9829c72d9b970 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sun, 13 Aug 2017 19:01:41 +0200 Subject: [PATCH] ob-core: Fix `org-babel-goto-named-src-block' at point-min * lisp/ob-core.el (org-babel-find-named-block): (org-babel-src-block-names): Fix behaviour when match is at point-min. Reported-by: "Berry, Charles" --- lisp/ob-core.el | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lisp/ob-core.el b/lisp/ob-core.el index a4ecfca2f..2e28ac4d1 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -1752,16 +1752,20 @@ NAME, or nil if no such block exists. Set match data according to `org-babel-named-src-block-regexp'." (save-excursion (goto-char (point-min)) - (ignore-errors - (org-next-block 1 nil (org-babel-named-src-block-regexp-for-name name))))) + (let ((regexp (org-babel-named-src-block-regexp-for-name name))) + (or (and (looking-at regexp) + (progn (goto-char (match-beginning 1)) + (line-beginning-position))) + (ignore-errors (org-next-block 1 nil)))))) (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) + (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)))