From ec38cffff030e4b48fbbeffa52d656c8ed698101 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Sun, 14 Jun 2009 22:06:11 -0700 Subject: [PATCH 1/2] not yet working --- lisp/org-babel.el | 23 ++++++++++++++++++----- org-babel.org | 2 ++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lisp/org-babel.el b/lisp/org-babel.el index 54a890d3d..113b811d8 100644 --- a/lisp/org-babel.el +++ b/lisp/org-babel.el @@ -269,6 +269,20 @@ 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 ((S (format "#+srcname: %s" name))) + (if point + ;; taken from `org-open-at-point' + (progn + (switch-to-buffer-other-window + (org-get-buffer-for-internal-link (current-buffer))) + (org-mark-ring-push) + (condition-case nil (org-link-search (format "#+srcname: %s" name)) + (error (progn (widen) (org-link-search (format "#+srcname: %s" name)))))) + (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 @@ -277,11 +291,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 diff --git a/org-babel.org b/org-babel.org index df13e50fb..ef19d1d30 100644 --- a/org-babel.org +++ b/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 From 793f5205e2239c810d73d04e6898bcab077e875c Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Mon, 15 Jun 2009 12:43:15 -0700 Subject: [PATCH 2/2] org-babel-goto-named-source-block is working --- lisp/org-babel.el | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lisp/org-babel.el b/lisp/org-babel.el index 113b811d8..8021b085c 100644 --- a/lisp/org-babel.el +++ b/lisp/org-babel.el @@ -272,15 +272,10 @@ If the point is not on a source block then return nil." (defun org-babel-goto-named-source-block (&optional name) "Go to a named source-code block." (interactive "ssource-block name: ") - (let ((S (format "#+srcname: %s" name))) + (let ((point (org-babel-find-named-block name))) (if point ;; taken from `org-open-at-point' - (progn - (switch-to-buffer-other-window - (org-get-buffer-for-internal-link (current-buffer))) - (org-mark-ring-push) - (condition-case nil (org-link-search (format "#+srcname: %s" name)) - (error (progn (widen) (org-link-search (format "#+srcname: %s" name)))))) + (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)