emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Michael Brand <michael.ch.brand@gmail.com>
To: Org Mode <emacs-orgmode@gnu.org>
Subject: Re: link abbreviation with multiple params, e. g. for geo locations
Date: Wed, 22 May 2013 19:03:09 +0200	[thread overview]
Message-ID: <CALn3zogSUmgFNr1DrUsjwJ19x_0ODP6rYLNB37m1-Jxai-B6Wg@mail.gmail.com> (raw)

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

Hi all

On Tue, May 7, 2013 at 12:29 AM, Christian Moe <mail@christianmoe.com> wrote:
> I'm afraid knowing that doesn't help much. The problem is, you don't know
> what point the inline call is at, so you cannot point org-entry-get to
> the right entry. If you try
>
> : (org-entry-get (point) "geo")
>
> it will look for a geo property in the outline entry the source block is
> in, not in the entry the call comes from.
>
> I don't know any easy way to pass a parameter to a source block from an
> outline entry property via an inline call in that entry. Others may know
> better.

After some trials it seemed to me that it is enough to just add a "loc
(point-marker)" to a "let" of org-babel-ref-resolve. Now when the Lisp
variable loc ("Location Of Call") is used as the first argument of
org-entry-get it reads the property from that entry where the code
block has been called. With this, Babel perfectly covers every
requirement of my use case described earlier in this thread.

Please review and comment my attached patch containing doc and ERT.

Michael

[-- Attachment #2: 0001-Entry-properties-as-code-block-arguments-in-Babel.patch.txt --]
[-- Type: text/plain, Size: 4160 bytes --]

From 178d8c7100176561a395d545c193ea36225ab81c Mon Sep 17 00:00:00 2001
From: Michael Brand <michael.ch.brand@gmail.com>
Date: Wed, 22 May 2013 18:59:24 +0200
Subject: [PATCH] Entry properties as code block arguments in Babel

* doc/org.texi (var): Document loc ("Location Of Call").
* lisp/ob-ref.el (org-babel-ref-resolve): Add `loc' which is set to
point as a marker object.
* testing/examples/babel.org: Add test entry for ERT.
* testing/lisp/test-ob-exp.el: Add expected code block results for
ERT.
---
 doc/org.texi                |    9 +++++++++
 lisp/ob-ref.el              |    4 +++-
 testing/examples/babel.org  |   30 ++++++++++++++++++++++++++++++
 testing/lisp/test-ob-exp.el |    8 ++++++++
 4 files changed, 50 insertions(+), 1 deletions(-)

diff --git a/doc/org.texi b/doc/org.texi
index 290c671..29362cd 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -14381,6 +14381,15 @@ evaluation of the code block body.
 #+END_SRC
 @end example
 
+Within Emacs Lisp evaluation the Lisp variable @code{loc} provides the
+``Location Of Call'' as a marker object which can be passed for example to
+the Lisp function @code{org-entry-get} to read a property from that entry
+where the code block has been called:
+
+@example
+#+HEADERS: :var todo_state=(org-entry-get loc "TODO" t)
+@end example
+
 Note that values read from tables and lists will not be evaluated as
 Emacs Lisp, as shown in the following example.
 
diff --git a/lisp/ob-ref.el b/lisp/ob-ref.el
index a2814ea..9645b9e 100644
--- a/lisp/ob-ref.el
+++ b/lisp/ob-ref.el
@@ -124,7 +124,9 @@ the variable."
     (save-excursion
       (let ((case-fold-search t)
 	    type args new-refere new-header-args new-referent result
-	    lob-info split-file split-ref index index-row index-col id)
+	    lob-info split-file split-ref index index-row index-col id
+	    ;; For Emacs Lisp evaluation of :var, see Org manual.
+	    (loc (point-marker)))
 	;; if ref is indexed grab the indices -- beware nested indices
 	(when (and (string-match "\\[\\([^\\[]+\\)\\]$" ref)
 		   (let ((str (substring ref 0 (match-beginning 0))))
diff --git a/testing/examples/babel.org b/testing/examples/babel.org
index 7c30ab2..8b18c3f 100644
--- a/testing/examples/babel.org
+++ b/testing/examples/babel.org
@@ -359,3 +359,33 @@ Here is a call line with more than just the results exported.
   <<strip-export-1>>
   echo "1$i"
 #+END_SRC
+
+* Emacs Lisp evaluation of :var with "loc" (Location Of Call)
+  :PROPERTIES:
+  :ID:       cc5fbc20-bca5-437a-a7b8-2b4d7a03f820
+  :END:
+
+#+NAME: func
+#+HEADERS: :var a=(string-to-number (or (org-entry-get loc "a" t) "0"))
+#+HEADERS: :var b=(string-to-number (or (org-entry-get loc "b" t) "0"))
+#+HEADERS: :var c=(string-to-number (or (org-entry-get loc "c" t) "0"))
+#+HEADERS: :var d=(string-to-number (or (org-entry-get loc "d" t) "0"))
+#+HEADERS: :var e=(string-to-number (or (org-entry-get loc "e" t) "0"))
+#+BEGIN_SRC emacs-lisp
+  (message "a:%d, b:%d, c:%d, d:%d, e:%d" a b c d e)
+#+END_SRC
+
+** section
+   :PROPERTIES:
+   :a:        1
+   :c:        3
+   :END:
+- section: call_func()
+
+*** subsection
+    :PROPERTIES:
+    :b:        2
+    :c:        4
+    :END:
+- subsec1: call_func()
+- subsec2: call_func(c=5, e=6)
diff --git a/testing/lisp/test-ob-exp.el b/testing/lisp/test-ob-exp.el
index abfe230..ea671f0 100644
--- a/testing/lisp/test-ob-exp.el
+++ b/testing/lisp/test-ob-exp.el
@@ -216,6 +216,14 @@ Here is one at the end of a line. =2=
       (should-not (string-match (regexp-quote "<<strip-export-1>>") result))
       (should-not (string-match (regexp-quote "i=\"10\"") result)))))
 
+(ert-deftest ob-exp/location-of-call ()
+  (org-test-at-id "cc5fbc20-bca5-437a-a7b8-2b4d7a03f820"
+    (org-narrow-to-subtree)
+    (let ((result (org-test-with-expanded-babel-code (buffer-string))))
+      (should (string-match "section: =a:1, b:0, c:3, d:0, e:0=" result))
+      (should (string-match "subsec1: =a:1, b:2, c:4, d:0, e:0=" result))
+      (should (string-match "subsec2: =a:1, b:2, c:5, d:0, e:6=" result)))))
+
 (ert-deftest ob-exp/export-from-a-temp-buffer ()
   :expected-result :failed
   (org-test-with-temp-text
-- 
1.7.4.2


             reply	other threads:[~2013-05-22 17:03 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-22 17:03 Michael Brand [this message]
2013-05-29 16:14 ` link abbreviation with multiple params, e. g. for geo locations Michael Brand
2013-06-05 17:19   ` Michael Brand
2013-06-06 17:01 ` Eric Schulte
2013-06-07 14:53   ` Michael Brand
2013-06-07 15:18     ` Eric Schulte
2013-06-07 19:16       ` Michael Brand
2013-06-07 19:54         ` Vitalie Spinu
2013-06-08 18:05           ` Eric Schulte
2013-06-08 18:52             ` Vitalie Spinu
2013-06-08 19:21               ` Eric Schulte
2013-06-14 17:54                 ` Michael Brand
2013-06-14 18:18                   ` Eric Schulte
2013-06-14 20:13                     ` Michael Brand
2013-06-19  9:39                       ` Michael Brand
2013-06-07 20:10         ` Achim Gratz
2013-06-08 18:03         ` Eric Schulte
2013-06-09  7:56           ` Michael Brand
2013-06-09  8:07             ` Michael Brand
2013-06-09 19:18             ` Eric Schulte
2013-06-09 20:32               ` Michael Brand
2013-06-11 13:12                 ` Eric Schulte
  -- strict thread matches above, loose matches on Subject: below --
2013-05-05 15:06 Michael Brand
2013-05-06  7:06 ` Christian Moe
2013-05-06 18:42   ` Michael Brand
2013-05-06 22:29     ` Christian Moe

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=CALn3zogSUmgFNr1DrUsjwJ19x_0ODP6rYLNB37m1-Jxai-B6Wg@mail.gmail.com \
    --to=michael.ch.brand@gmail.com \
    --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).