From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andreas Leha Subject: [babel] [PATCH] enhanced org-babel-goto-named-src-block Date: Wed, 22 Feb 2012 21:51:31 +0100 Message-ID: <87hayid224.fsf@med.uni-goettingen.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([140.186.70.92]:59750) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S0JAQ-0001Yj-VE for emacs-orgmode@gnu.org; Wed, 22 Feb 2012 15:52:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S0JAP-0002cU-7y for emacs-orgmode@gnu.org; Wed, 22 Feb 2012 15:52:02 -0500 Received: from plane.gmane.org ([80.91.229.3]:53821) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S0JAP-0002cK-2x for emacs-orgmode@gnu.org; Wed, 22 Feb 2012 15:52:01 -0500 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1S0JAM-0007wR-J8 for emacs-orgmode@gnu.org; Wed, 22 Feb 2012 21:51:58 +0100 Received: from p57b64b6d.dip.t-dialin.net ([87.182.75.109]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 22 Feb 2012 21:51:58 +0100 Received: from andreas.leha by p57b64b6d.dip.t-dialin.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 22 Feb 2012 21:51:58 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain 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 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=ob.el.diff Content-Description: patch for org-babel-goto-named-src-block 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) --=-=-=--