Browse Source

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" <ccberry@ucsd.edu>
<http://lists.gnu.org/archive/html/emacs-orgmode/2017-08/msg00324.html>
Nicolas Goaziou 4 years ago
parent
commit
b862c24b9f
1 changed files with 8 additions and 4 deletions
  1. 8 4
      lisp/ob-core.el

+ 8 - 4
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)))