all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Charles C. Berry" <ccberry@ucsd.edu>
To: Org-Mode mailing list <emacs-orgmode@gnu.org>
Subject: [PATCH] org-babel-goto-named-src-block bugfix and test
Date: Sat, 11 Jun 2016 16:04:44 -0700	[thread overview]
Message-ID: <alpine.OSX.2.20.1606111552350.1245@charles-berrys-macbook.local> (raw)

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



Hi all,

The revision a few months back of `org-babel-goto-named-src-block' broke 
some of the interactive uses. I have fixed these in the attached patch.

Also, I provide an ERT test for those interactive uses --- filling in the 
initial-input with the name of the symbol, results block name, #+call: 
name, or not if point is elsewhere.

The test uses lines like:

 	(execute-kbd-macro  "\M-xorg-babel-goto-named-src-block\n\n")

to emulate interactive usage.

This feels like a hack, and the messages generated spill into my *shell* 
buffer when I run `make test'.  If there is a cleaner way to do this, 
I'd like to know it.

WDYT?

Chuck

[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 4135 bytes --]

From 6b6d0beb908474b75e903c86649a04b6ef71048c Mon Sep 17 00:00:00 2001
From: Charles Berry <ccberry@ucsd.edu>
Date: Sat, 11 Jun 2016 15:45:20 -0700
Subject: [PATCH] org-babel-goto-named-src-block bugfix

* lisp/ob-core.el (org-babel-goto-named-src-block): The user prompt
  (i.e. `initial-input' arg of `completing-read') will be the name of
  the results block, noweb reference, call reference, or symbol if
  point is in such.

* testing/lisp/test-ob.el (test-ob/goto-named-src-block): Simulate
  interactive use of `org-babel-goto-named-src-block'.
---
 lisp/ob-core.el         | 18 ++++++++++++------
 testing/lisp/test-ob.el | 42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 6 deletions(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 2e9a4d1..63983d5 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -1690,16 +1690,22 @@ If the point is not on a source block then return nil."
 	 (all-block-names (org-babel-src-block-names)))
      (list (completing-read
 	    "source-block name: " all-block-names nil t
-	    (let* ((context (org-element-context))
-		   (type (org-element-type context)))
+	    (let* ((context (org-element-context)) 
+		   (type (org-element-type context))
+		   (noweb-ref
+		    (and (memq type '(inline-src-block src-block))
+			 (org-in-regexp (org-babel-noweb-wrap))))) 
 	      (cond
-	       ((and (memq type '(inline-src-block src-block)) ;<<noweb>>
-		     (org-in-regexp (org-babel-noweb-wrap))))
+	       (noweb-ref
+		(buffer-substring
+		 (+ (car noweb-ref) (length org-babel-noweb-wrap-start))
+		 (- (cdr noweb-ref) (length org-babel-noweb-wrap-end))))
 	       ((memq type '(babel-call inline-babel-call)) ;#+CALL:
 		(org-element-property :call context))
-	       ((org-element-property :results context)) ;#+RESULTS:
+	       ((car (org-element-property :results context))) ;#+RESULTS:
 	       ((let ((symbol (thing-at-point 'symbol))) ;Symbol.
-		  (and (member-ignore-case symbol all-block-names)
+		  (and symbol
+		       (member-ignore-case symbol all-block-names)
 		       symbol)))
 	       (t "")))))))
   (let ((point (org-babel-find-named-block name)))
diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el
index aa26602..fe5bbea 100644
--- a/testing/lisp/test-ob.el
+++ b/testing/lisp/test-ob.el
@@ -1581,6 +1581,48 @@ echo \"$data\"
    (org-test-with-temp-text "#+results: foo"
      (org-babel-find-named-result "foo"))))
 
+(ert-deftest test-ob/goto-named-src-block ()
+    "Test interactive use of `org-babel-goto-named-src-block'."
+    (org-test-with-temp-text-in-file
+	 	"
+#+NAME: abc
+#+BEGIN_SRC emacs-lisp :results value 
+(1+ 1)
+#+END_SRC
+#+CALL: abc( lorem() ) :results raw :wrap EXAMPLE
+#+BEGIN_SRC emacs-lisp
+<<abc>>
+#+END_SRC
+abc
+#+RESULTS: abc
+: 2
+"
+       ;; non-existent name
+       (should-not
+         (execute-kbd-macro  "\M-xorg-babel-goto-named-src-block\ndef\n"))
+       ;; correct name
+       (execute-kbd-macro  "\M-xorg-babel-goto-named-src-block\nabc\n")
+       (should  (= 14 (point)))  
+       ;; call line   - autocompletion
+       (forward-line 3)
+       (execute-kbd-macro  "\M-xorg-babel-goto-named-src-block\n\n")
+       (should  (= 14 (point)))
+       ;; noweb reference  - autocompletion
+       (forward-line 5)
+       (execute-kbd-macro  "\M-xorg-babel-goto-named-src-block\n\n")
+       (should  (= 14 (point)))
+       ;; at symbol  - autocompletion
+       (forward-line 7)
+       (execute-kbd-macro  "\M-xorg-babel-goto-named-src-block\n\n")
+       (should  (= 14 (point)))
+       ;; in results  - autocompletion
+       (forward-line 8)
+       (execute-kbd-macro  "\M-xorg-babel-goto-named-src-block\n\n")
+       (should  (= 14 (point)))
+       (forward-line 9)
+       (execute-kbd-macro  "\M-xorg-babel-goto-named-src-block\n\n")
+       (should  (= 14 (point)))))
+
 (ert-deftest test-ob/where-is-src-block-result ()
   "Test `org-babel-where-is-src-block-result' specifications."
   ;; Find anonymous results.
-- 
2.6.4 (Apple Git-63)


             reply	other threads:[~2016-06-11 23:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-11 23:04 Charles C. Berry [this message]
2016-06-12 10:21 ` [PATCH] org-babel-goto-named-src-block bugfix and test Marco Wahl
2016-06-12 16:05   ` Charles C. Berry
2016-06-14 10:36     ` Marco Wahl
2016-06-14 11:46       ` Nicolas Goaziou

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

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

  git send-email \
    --in-reply-to=alpine.OSX.2.20.1606111552350.1245@charles-berrys-macbook.local \
    --to=ccberry@ucsd.edu \
    --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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.