all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* hyperlinks executing multiline code snippets?
@ 2010-12-10 15:20 LanX
  2010-12-10 15:52 ` LanX
  0 siblings, 1 reply; 8+ messages in thread
From: LanX @ 2010-12-10 15:20 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 894 bytes --]

Hi

Don't know if this is trivially answered...

I'm thinking about using org-mode for a collection of code-snippets which
are executed by a click on a link

My first idea was to use orgs hyperlink syntax but there I have two problems
1. something like [[shell:code][NAME]] can't be multiline
2. for  perl  code I'll need to escape certain characters when using
[[shell:...] or [[elisp:...]

my second idea was org-babel, but AFAI see
1. it seems to execute code-snippets only when exporting
2. the code can't be hidden behind a NAME in a link text

Is there a way to combine both ways?

A hyperlink which executes a codesnippet (which is per default folded away)?

something like?

* [[exec:following snippet][name]
#+begin_src perl
for $i (1..9){
   print $i;
}
#+end_src


or


* Title
#+begin_src perl :hyperlink name
for $i (1..9){
   print $i;
}
#+end_src



Thanks for any help

-- rolf

[-- Attachment #1.2: Type: text/html, Size: 1374 bytes --]

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

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

* hyperlinks executing multiline code snippets?
  2010-12-10 15:20 hyperlinks executing multiline code snippets? LanX
@ 2010-12-10 15:52 ` LanX
  2010-12-10 16:14   ` LanX
  0 siblings, 1 reply; 8+ messages in thread
From: LanX @ 2010-12-10 15:52 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 1023 bytes --]

(hope this will not produce a duplicate post)

Hi
>
> Don't know if this is trivially answered...
>
> I'm thinking about using org-mode for a collection of code-snippets which
> are executed by a click on a link
>
> My first idea was to use orgs hyperlink syntax but there I have two
> problems
> 1. something like [[shell:code][NAME]] can't be multiline
> 2. for  perl  code I'll need to escape certain characters when using
> [[shell:...] or [[elisp:...]
>
> my second idea was org-babel, but AFAI see
> 1. it seems to execute code-snippets only when exporting
> 2. the code can't be hidden behind a NAME in a link text
>
> Is there a way to combine both ways?
>
> A hyperlink which executes a codesnippet (which is per default folded
> away)?
>
> something like?
>
> * [[exec:following snippet][name]
> #+begin_src perl
> for $i (1..9){
>
>    print $i;
> }
> #+end_src
>
>
> or
>
>
> * Title
> #+begin_src perl :hyperlink name
> for $i (1..9){
>
>    print $i;
> }
> #+end_src
>
>
>
> Thanks for any help
>
> -- rolf
>

[-- Attachment #1.2: Type: text/html, Size: 1398 bytes --]

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

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

* hyperlinks executing multiline code snippets?
  2010-12-10 15:52 ` LanX
@ 2010-12-10 16:14   ` LanX
  2010-12-10 17:05     ` Eric Schulte
  0 siblings, 1 reply; 8+ messages in thread
From: LanX @ 2010-12-10 16:14 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 1063 bytes --]

>
> Hi
>
> Don't know if this is trivially answered...
>
> I'm thinking about using org-mode for a collection of code-snippets which
> are executed by a click on a link
>
> My first idea was to use orgs hyperlink syntax but there I have two
> problems
> 1. something like [[shell:code][NAME]] can't be multiline
> 2. for  perl  code I'll need to escape certain characters when using
> [[shell:...] or [[elisp:...]
>
> my second idea was org-babel, but AFAI see
> 1. it seems to execute code-snippets only when exporting
> 2. the code can't be hidden behind a NAME in a link text
>
> Is there a way to combine both ways?
>
> A hyperlink which executes a codesnippet (which is per default folded
> away)?
>
> something like?
>
> * [[exec:following snippet][name]
> #+begin_src perl
> for $i (1..9){
>
>    print $i;
> }
> #+end_src
>
>
> or
>
>
> * Title
> #+begin_src perl :hyperlink name
> for $i (1..9){
>
>    print $i;
> }
> #+end_src
>
>
>
> Thanks for any help
>
> -- rolf
>

PS hope this will not produce a duplicate post, "gmail" != "googlemail"
confusion

[-- Attachment #1.2: Type: text/html, Size: 1522 bytes --]

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

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

* Re: hyperlinks executing multiline code snippets?
  2010-12-10 16:14   ` LanX
@ 2010-12-10 17:05     ` Eric Schulte
  2010-12-10 18:03       ` LanX
  0 siblings, 1 reply; 8+ messages in thread
From: Eric Schulte @ 2010-12-10 17:05 UTC (permalink / raw)
  To: LanX; +Cc: emacs-orgmode

Hi LanX,

The following two options come to mind, although I'm not sure if any are
exactly what you're after.

* named code block and a #+call: line
#+source: counter
#+begin_src perl :results output :var to=5
for $i (1..$to){
   print $i;
}
#+end_src

#+results: counter
: 12345

#+call: counter(to=3)

#+results: counter(to=3)
: 123

C-c C-c on the call line to execute the counter block, the block does
not need to be located near the call line, and using the Library of
Babel could even be located in another file.

* using an elisp link
[[elisp:(sbe counter (to "8"))][count to 8]]

Clicking on the link above will also call the code block.

Best -- Eric

LanX <lanx.perl@googlemail.com> writes:

>>
>> Hi
>>
>> Don't know if this is trivially answered...
>>
>> I'm thinking about using org-mode for a collection of code-snippets which
>> are executed by a click on a link
>>
>> My first idea was to use orgs hyperlink syntax but there I have two
>> problems
>> 1. something like [[shell:code][NAME]] can't be multiline
>> 2. for  perl  code I'll need to escape certain characters when using
>> [[shell:...] or [[elisp:...]
>>
>> my second idea was org-babel, but AFAI see
>> 1. it seems to execute code-snippets only when exporting
>> 2. the code can't be hidden behind a NAME in a link text
>>
>> Is there a way to combine both ways?
>>
>> A hyperlink which executes a codesnippet (which is per default folded
>> away)?
>>
>> something like?
>>
>> * [[exec:following snippet][name]
>> #+begin_src perl
>> for $i (1..9){
>>
>>    print $i;
>> }
>> #+end_src
>>
>>
>> or
>>
>>
>> * Title
>> #+begin_src perl :hyperlink name
>> for $i (1..9){
>>
>>    print $i;
>> }
>> #+end_src
>>
>>
>>
>> Thanks for any help
>>
>> -- rolf
>>
>
> PS hope this will not produce a duplicate post, "gmail" != "googlemail"
> confusion
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

* Re: hyperlinks executing multiline code snippets?
  2010-12-10 17:05     ` Eric Schulte
@ 2010-12-10 18:03       ` LanX
  2010-12-10 18:08         ` LanX
  0 siblings, 1 reply; 8+ messages in thread
From: LanX @ 2010-12-10 18:03 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 3408 bytes --]

Hi Eric

Thanks looks promising but I'm having problems to use it.

I noticed that babel is not a part of 6.30trans and did an upgrade to the
latest current version 7.4.

Unfortunately it's causing problems (all I did was updating a sym-link to
the new package)

Am I supposed to set additional PATHs?

bye
--Rolf

emacs-23.1.50 --no-site-file --debug-init emacs/tst.org

--------
Debugger entered--Lisp error: (file-error "Cannot open load file"
"org-entities")
  require(org-entities)
  eval-buffer(#<buffer  *load*<4>> nil
"/home/lanx/.emacs.d/elisp/org/org-mode/lisp/org.el" nil t)  ; Reading at
buffer position 3964

load-with-code-conversion("/home/lanx/.emacs.d/elisp/org/org-mode/lisp/org.el"
"/home/lanx/.emacs.d/elisp/org/org-mode/lisp/org.el" nil nil)
  load("/home/lanx/.emacs.d/elisp/org/org-mode/lisp/org.el")
...
-------


emacs22 --no-site-file --debug-init emacs/tst.org

--------
Debugger entered--Lisp error: (file-error "Cannot open load file"
"org-macs")
  require(org-macs)
  eval-buffer(#<buffer  *load*<4>> nil
"/home/lanx/.emacs.d/elisp/org/org-mode/lisp/org.el" nil t)  ; Reading at
buffer position 3940
...
--------





2010/12/10 Eric Schulte <schulte.eric@gmail.com>

> Hi LanX,
>
> The following two options come to mind, although I'm not sure if any are
> exactly what you're after.
>
> * named code block and a #+call: line
> #+source: counter
> #+begin_src perl :results output :var to=5
> for $i (1..$to){
>   print $i;
> }
> #+end_src
>
> #+results: counter
> : 12345
>
> #+call: counter(to=3)
>
> #+results: counter(to=3)
> : 123
>
> C-c C-c on the call line to execute the counter block, the block does
> not need to be located near the call line, and using the Library of
> Babel could even be located in another file.
>
> * using an elisp link
> [[elisp:(sbe counter (to "8"))][count to 8]]
>
> Clicking on the link above will also call the code block.
>
> Best -- Eric
>
> LanX <lanx.perl@googlemail.com> writes:
>
> >>
> >> Hi
> >>
> >> Don't know if this is trivially answered...
> >>
> >> I'm thinking about using org-mode for a collection of code-snippets
> which
> >> are executed by a click on a link
> >>
> >> My first idea was to use orgs hyperlink syntax but there I have two
> >> problems
> >> 1. something like [[shell:code][NAME]] can't be multiline
> >> 2. for  perl  code I'll need to escape certain characters when using
> >> [[shell:...] or [[elisp:...]
> >>
> >> my second idea was org-babel, but AFAI see
> >> 1. it seems to execute code-snippets only when exporting
> >> 2. the code can't be hidden behind a NAME in a link text
> >>
> >> Is there a way to combine both ways?
> >>
> >> A hyperlink which executes a codesnippet (which is per default folded
> >> away)?
> >>
> >> something like?
> >>
> >> * [[exec:following snippet][name]
> >> #+begin_src perl
> >> for $i (1..9){
> >>
> >>    print $i;
> >> }
> >> #+end_src
> >>
> >>
> >> or
> >>
> >>
> >> * Title
> >> #+begin_src perl :hyperlink name
> >> for $i (1..9){
> >>
> >>    print $i;
> >> }
> >> #+end_src
> >>
> >>
> >>
> >> Thanks for any help
> >>
> >> -- rolf
> >>
> >
> > PS hope this will not produce a duplicate post, "gmail" != "googlemail"
> > confusion
> > _______________________________________________
> > Emacs-orgmode mailing list
> > Please use `Reply All' to send replies to the list.
> > Emacs-orgmode@gnu.org
> > http://lists.gnu.org/mailman/listinfo/emacs-orgmode
>

[-- Attachment #1.2: Type: text/html, Size: 4870 bytes --]

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

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

* Re: hyperlinks executing multiline code snippets?
  2010-12-10 18:03       ` LanX
@ 2010-12-10 18:08         ` LanX
  2010-12-10 22:14           ` LanX
  0 siblings, 1 reply; 8+ messages in thread
From: LanX @ 2010-12-10 18:08 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 322 bytes --]

ARGH ..


... just realised that I still need to run the makefile for installation.

Sorry! :)

2010/12/10 LanX <lanx.perl@googlemail.com>

> Hi Eric
>
> Thanks looks promising but I'm having problems to use it.
>
> I noticed that babel is not a part of 6.30trans and did an upgrade to the
> latest current version 7.4.
>

[-- Attachment #1.2: Type: text/html, Size: 610 bytes --]

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

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

* Re: hyperlinks executing multiline code snippets?
  2010-12-10 18:08         ` LanX
@ 2010-12-10 22:14           ` LanX
  2010-12-11  2:23             ` LanX
  0 siblings, 1 reply; 8+ messages in thread
From: LanX @ 2010-12-10 22:14 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 1204 bytes --]

Hi Eric

thanks, after some fiddling I was able to make it work...

But do I get it right?

The snippet has to be explicitely named, I can't tell the hyperlink just to
take the next block?

Before I start trying it, is it theoretically possible to write an on
ob-multiline.el which parses the following lines?

I.e. is the current "point" known at execution time?

Out of curiosity, the manual says

> The org-babel-load-languages controls which languages are enabled for
evaluation (by default only emacs-lisp is enabled).

Is it done out of security reasons? Cause it wouldn't be a problem to start
a  process via elisp and (shell-command ...)

Next question:

shell-command normally prints the stdout into the minibuffer, but
org-hyperlink executions overwrite it with the return code.

Is this behaviour configurable?

Thanks for the help
  Rolf

PS: ob-perl.el says
-----
(defun org-babel-perl-initiate-session (&optional session params)
  "Return nil because sessions are not supported by perl"
nil)
------
What is meant with supporting sessions? IIRC do packages like sepia.el fork
a perl process allowing bidirectional communication with emacs.

Or what kind of extra support is neccessary here?

[-- Attachment #1.2: Type: text/html, Size: 1396 bytes --]

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

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

* Re: hyperlinks executing multiline code snippets?
  2010-12-10 22:14           ` LanX
@ 2010-12-11  2:23             ` LanX
  0 siblings, 0 replies; 8+ messages in thread
From: LanX @ 2010-12-11  2:23 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 319 bytes --]

>
>
> Before I start trying it, is it theoretically possible to write an on
> ob-multiline.el which parses the following lines?
>
> I.e. is the current "point" known at execution time?
>
>
it works.


I managed to create a new lisp defun which parses the following text,
extracts the code and executes it!

perfect! =)

[-- Attachment #1.2: Type: text/html, Size: 536 bytes --]

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

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

end of thread, other threads:[~2010-12-11  2:24 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-10 15:20 hyperlinks executing multiline code snippets? LanX
2010-12-10 15:52 ` LanX
2010-12-10 16:14   ` LanX
2010-12-10 17:05     ` Eric Schulte
2010-12-10 18:03       ` LanX
2010-12-10 18:08         ` LanX
2010-12-10 22:14           ` LanX
2010-12-11  2:23             ` LanX

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.