emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Re: link abbreviation with multiple params, e. g. for geo locations
@ 2013-05-22 17:03 Michael Brand
  2013-05-29 16:14 ` Michael Brand
  2013-06-06 17:01 ` Eric Schulte
  0 siblings, 2 replies; 26+ messages in thread
From: Michael Brand @ 2013-05-22 17:03 UTC (permalink / raw)
  To: Org Mode

[-- 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


^ permalink raw reply related	[flat|nested] 26+ messages in thread
* link abbreviation with multiple params, e. g. for geo locations
@ 2013-05-05 15:06 Michael Brand
  2013-05-06  7:06 ` Christian Moe
  0 siblings, 1 reply; 26+ messages in thread
From: Michael Brand @ 2013-05-05 15:06 UTC (permalink / raw)
  To: Org Mode

Hi all

I suggest that the Org link abbreviation supports multiple and
repeated parameters so that it can handle more than the one and only
parameter %s as of now. What I have in mind is to abbreviate the URL

[[http://maps.google.com/maps?ll=4.56,7.89&spn=0.3,0.3&q=4.56,7.89]]

this way

: #+LINK: geo http://maps.google.com/maps?ll=%1&spn=%2,%2&q=%1
: [[geo:4.56,7.89&0.3]]

where & in the Org link is the separator of the parameters %1 and %2.
Note the repeated use of %1 and %2 in this case which is a good part
of the convenience. I tried with a workaround URL that by itself would
work

[[http://maps.google.com/maps?ll=4.56,7.89&spn=0.3,0.3&q=4.56,7.89&spn=0.3,0.3]]

with the repeated spn. But below the second %s remains without
replacement which means the marker in the map gets lost when trying
this with release_8.0.2-72-gccfe83:

#+LINK: geo http://maps.google.com/maps?ll=%s&q=%s
[[geo:4.56,7.89&spn=0.3,0.3]]

Does it make sense to put at least repeatable %s, but then also
multiple and repeatable parameters for link abbreviations to the wish
list? Or did I miss something else that supports also
org-open-at-point, maybe Org macros?

I am not sure if %1 %2 etc. for the parameters is a good choice since
it might interfere with escaped chars in #+LINK. Maybe &1 &2 etc.
interfere less because the & to separate URL parameters are followed
mostly by letters, as well as the & in HTML entities, AFAIK.

Michael

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2013-06-19  9:40 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-22 17:03 link abbreviation with multiple params, e. g. for geo locations Michael Brand
2013-05-29 16:14 ` 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

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).