浏览代码

ob-core: Use `org-next-block'

* lisp/ob-core.el (org-babel-find-named-block):
(org-babel-src-block-names): Use `org-next-block'.
Nicolas Goaziou 10 年之前
父节点
当前提交
4aeb622336
共有 1 个文件被更改,包括 11 次插入12 次删除
  1. 11 12
      lisp/ob-core.el

+ 11 - 12
lisp/ob-core.el

@@ -1759,23 +1759,22 @@ If the point is not on a source block then return nil."
 (defun org-babel-find-named-block (name)
   "Find a named source-code block.
 Return the location of the source block identified by source
-NAME, or nil if no such block exists.  Set match data according to
-org-babel-named-src-block-regexp."
+NAME, or nil if no such block exists.  Set match data according
+to `org-babel-named-src-block-regexp'."
   (save-excursion
-    (let ((case-fold-search t)
-	  (regexp (org-babel-named-src-block-regexp-for-name name)) msg)
-      (goto-char (point-min))
-      (when (or (re-search-forward regexp nil t)
-		(re-search-backward regexp nil t))
-        (match-beginning 0)))))
+    (goto-char (point-min))
+    (ignore-errors
+      (org-next-block 1 nil (org-babel-named-src-block-regexp-for-name name)))))
 
 (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
-    (when file (find-file file)) (goto-char (point-min))
-    (let ((case-fold-search t) names)
-      (while (re-search-forward org-babel-src-name-w-name-regexp nil t)
-	(setq names (cons (match-string 3) names)))
+    (goto-char (point-min))
+    (let (names)
+      (while (ignore-errors
+	       (org-next-block 1 nil org-babel-src-name-w-name-regexp))
+	(push (match-string 3) names))
       names)))
 
 ;;;###autoload