emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Andreas Leha <andreas.leha@med.uni-goettingen.de>
To: emacs-orgmode@gnu.org
Subject: [babel] [PATCH] enhanced org-babel-goto-named-src-block
Date: Wed, 22 Feb 2012 21:51:31 +0100	[thread overview]
Message-ID: <87hayid224.fsf@med.uni-goettingen.de> (raw)

[-- Attachment #1: Type: text/plain, Size: 419 bytes --]

Hi all,

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)

- Andreas


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch for org-babel-goto-named-src-block --]
[-- Type: text/x-diff, Size: 1763 bytes --]

diff --git a/lisp/ob.el b/lisp/ob.el
index f021943..9962817 100644
--- a/lisp/ob.el
+++ b/lisp/ob.el
@@ -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))
+   (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))))
+				 (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)

             reply	other threads:[~2012-02-22 20:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-22 20:51 Andreas Leha [this message]
2012-02-25 16:36 ` [babel] [PATCH] enhanced org-babel-goto-named-src-block Eric Schulte
2012-02-29  0:39 ` Thomas S. Dye
2012-02-29  8:57   ` Andreas Leha
2012-02-29 16:09     ` Thomas S. Dye
2012-02-29 19:48       ` Jonathan Leech-Pepin
2012-02-29 21:44         ` Sebastien Vauban
2012-02-29 22:24           ` Andreas Leha
2012-02-29 23:52             ` Thomas S. Dye
2012-03-01  8:19               ` Andreas Leha

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87hayid224.fsf@med.uni-goettingen.de \
    --to=andreas.leha@med.uni-goettingen.de \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).