Browse Source

New variable org-babel-named-src-block-regexp, to match a block with its srcname, and simple version of function org-babel-find-named-block.

Dan Davison 16 years ago
parent
commit
e0909d8458
1 changed files with 15 additions and 0 deletions
  1. 15 0
      lisp/org-babel.el

+ 15 - 0
lisp/org-babel.el

@@ -218,6 +218,21 @@ If the point is not on a source block then return nil."
         (goto-char top) (looking-at org-babel-src-block-regexp)
         (goto-char top) (looking-at org-babel-src-block-regexp)
         (point))))))
         (point))))))
 
 
+(defun org-babel-find-named-block (name)
+  "Find a named source-code block.
+
+Return the location of the source block identified by
+#+srcname 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 name)) msg)
+      (unless (or (re-search-forward regexp nil t)
+		  (re-search-backward regexp nil t))
+	(progn (setq msg (format "source-code block '%s' not found in this buffer" name))
+	       (message msg) (error msg)))))
+  (point))
+
 (defun org-babel-find-named-result (name)
 (defun org-babel-find-named-result (name)
   "Return the location of the result named NAME in the current
   "Return the location of the result named NAME in the current
 buffer or nil if no such result exists."
 buffer or nil if no such result exists."