diff options
author | Andreas Leha <andreas.leha@med.uni-goettingen.de> | 2012-02-25 09:35:18 -0700 |
---|---|---|
committer | Eric Schulte <eric.schulte@gmx.com> | 2012-02-25 09:36:15 -0700 |
commit | 87216ffa56a2714fc245fe9cd64ff9fa93f84be6 (patch) | |
tree | 77bc2f0b03da26a8ff557c7cf1d9e58820ac0d4d | |
parent | 81cc6dff19a141271af89a20ba80359cde93a542 (diff) | |
download | org-mode-87216ffa56a2714fc245fe9cd64ff9fa93f84be6.tar.gz |
enhancements to org-babel-goto-named-src-block
> attached is a patch that enhances org-babel-goto-named-src-block (bound
> to C-c C-v g by default). Included are two enhancements:
>
> 1. the point is pushed to the org-mark-ring, such that returning with
> C-c & becomes possible
> 2. the target src block is guessed from
> a) noweb-reference
> b) #+call:
> c) #+results:
> d) symbol-at-point
> if one of these is found (in that order)
* lisp/ob.el (org-babel-goto-named-src-block): Pushing the point to
the org-mark-ring and guessing at the code block name to jump to.
-rw-r--r-- | lisp/ob.el | 30 |
1 files changed, 26 insertions, 4 deletions
@@ -1457,13 +1457,35 @@ If the point is not on a source block then return nil." (defun org-babel-goto-named-src-block (name) "Go to a named source-code block." (interactive - (let ((completion-ignore-case t)) - (list (org-icompleting-read "source-block name: " - (org-babel-src-block-names) nil t)))) + (let ((completion-ignore-case t) + (under-point (thing-at-point 'line))) + (list (org-icompleting-read + "source-block name: " (org-babel-src-block-names) nil t + (cond + ;; noweb + ((string-match (org-babel-noweb-wrap) under-point) + (let ((block-name (match-string 1 under-point))) + (string-match "[^(]*" block-name) + (match-string 0 block-name))) + ;; #+call: + ((string-match org-babel-lob-one-liner-regexp under-point) + (let ((source-info (car (org-babel-lob-get-info)))) + (if (string-match "^\\([^\\[]+?\\)\\(\\[.*\\]\\)?(" source-info) + (let ((source-name (match-string 1 source-info))) + source-name)))) + ;; #+results: + ((string-match (concat "#\\+" org-babel-results-keyword + "\\:\s+\\([^\\(]*\\)") under-point) + (match-string 1 under-point)) + ;; symbol-at-point + ((and (thing-at-point 'symbol)) + (org-babel-find-named-block (thing-at-point 'symbol)) + (thing-at-point 'symbol)) + ("")))))) (let ((point (org-babel-find-named-block name))) (if point ;; taken from `org-open-at-point' - (progn (goto-char point) (org-show-context)) + (progn (org-mark-ring-push) (goto-char point) (org-show-context)) (message "source-code block '%s' not found in this buffer" name)))) (defun org-babel-find-named-block (name) |