From d9cfec3040e5d487d91336b9a643ad15d2fa5bec Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Thu, 30 May 2013 18:03:21 -0400 Subject: [PATCH] jump back to the correct point in the code block * lisp/ob-tangle.el (org-babel-tangle-jump-to-org): Use the existing org-edit-src functionality to jump back to the correct point in the code block in the original Org-mode buffer. --- lisp/ob-tangle.el | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el index 25dcb91cc..c5cde5308 100644 --- a/lisp/ob-tangle.el +++ b/lisp/ob-tangle.el @@ -493,13 +493,15 @@ which enable the original code blocks to be found." "Jump from a tangled code file to the related Org-mode file." (interactive) (let ((mid (point)) - start end done + start body-start end done target-buffer target-char link path block-name body) (save-window-excursion (save-excursion (while (and (re-search-backward org-bracket-link-analytic-regexp nil t) (not ; ever wider searches until matching block comments (and (setq start (point-at-eol)) + (setq body-start (save-excursion + (forward-line 2) (point-at-bol))) (setq link (match-string 0)) (setq path (match-string 3)) (setq block-name (match-string 5)) @@ -520,6 +522,17 @@ which enable the original code blocks to be found." (org-babel-next-src-block (string-to-number (match-string 1 block-name))) (org-babel-goto-named-src-block block-name)) + ;; position at the beginning of the code block body + (goto-char (org-babel-where-is-src-block-head)) + (forward-line 1) + ;; Use org-edit-special to isolate the code. + (org-edit-special) + ;; Then move forward the correct number of characters in the + ;; code buffer. + (forward-char (- mid body-start)) + ;; And return to the Org-mode buffer with the point in the right + ;; place. + (org-edit-src-exit) (setq target-char (point))) (pop-to-buffer target-buffer) (prog1 body (goto-char target-char))))