浏览代码

Merge branch 'jumping-to-source-blocks'

Eric Schulte 16 年之前
父节点
当前提交
a5f6423a76
共有 2 个文件被更改,包括 15 次插入5 次删除
  1. 13 5
      lisp/org-babel.el
  2. 2 0
      org-babel.org

+ 13 - 5
lisp/org-babel.el

@@ -264,6 +264,15 @@ If the point is not on a source block then return nil."
         (goto-char top) (looking-at org-babel-src-block-regexp)
         (point))))))
 
+(defun org-babel-goto-named-source-block (&optional name)
+  "Go to a named source-code block."
+  (interactive "ssource-block name: ")
+  (let ((point (org-babel-find-named-block name)))
+    (if point
+        ;; taken from `org-open-at-point'
+        (progn (goto-char point) (org-show-context))
+      (message "source-code block '%s' not found in this buffer" name))))
+
 (defun org-babel-find-named-block (name)
   "Find a named source-code block.
 Return the location of the source block identified by
@@ -272,11 +281,10 @@ 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)
-      (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)))
+      (goto-char (point-min))
+      (when (or (re-search-forward regexp nil t)
+                (re-search-backward regexp nil t))
+        (match-beginning 0)))))
 
 (defun org-babel-find-named-result (name)
   "Return the location of the result named NAME in the current

+ 2 - 0
org-babel.org

@@ -122,6 +122,8 @@ and the results to be collected in the same table.
    At the same time I introduced org-babel-named-src-block-regexp, to
    match src-blocks with srcname.
 
+   
+
 ** TODO support for working with =*Org Edit Src Example*= buffers [1/4]
 *** TODO set buffer-local-process variables appropriately [DED]
     I think something like this would be great. You've probably