emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Embedded code
@ 2011-01-17 16:06 Ido Magal
  2011-01-17 22:01 ` Ido Magal
  0 siblings, 1 reply; 23+ messages in thread
From: Ido Magal @ 2011-01-17 16:06 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

Hello,

Is it possible to put code in a document such that it gets evaluated
when the document is opened?  For example, I'd like to have a
link-back section in each note. I'm aware of babel but I neither
understand how to make it auto-evaluate on open nor do i know if
making it compact ( and avoid separate code and result blocks ) is
possible.

Thanks in advance.

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

* Embedded code
  2011-01-17 16:06 Embedded code Ido Magal
@ 2011-01-17 22:01 ` Ido Magal
  2011-01-17 23:48   ` Eric Schulte
  0 siblings, 1 reply; 23+ messages in thread
From: Ido Magal @ 2011-01-17 22:01 UTC (permalink / raw)
  To: emacs-orgmode


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

Hello,

Is it possible to put a block of code in a document such that it gets
evaluated when the document is opened?  For example, I'd like to have
a link-back section in each note.

I'm aware of babel but I neither understand how to make it auto-evaluate on
open nor do i know if
making it compact ( and avoid having code and result blocks ) is possible.
 I see examples where it's used for export but haven't seen one for general
org usage.

Thanks in advance.

[-- Attachment #1.2: Type: text/html, Size: 672 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] 23+ messages in thread

* Re: Embedded code
  2011-01-17 22:01 ` Ido Magal
@ 2011-01-17 23:48   ` Eric Schulte
  2011-01-18  8:51     ` Rainer M Krug
  0 siblings, 1 reply; 23+ messages in thread
From: Eric Schulte @ 2011-01-17 23:48 UTC (permalink / raw)
  To: Ido Magal; +Cc: emacs-orgmode

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

Hi,

This is possible using Babel, the attached org-mode file will execute
its code block every time it is opened.  You can replace the contents of
the code block with any arbitrary elisp you would like to have executed
in the file.

To see this work, save the attached org-mode file to your system, open
the file, answer "y" to allow execution, and then check your messages
buffer for the "I have been run" message to see that the code block has
in fact been evaluated.

Best -- Eric


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: code-on-startup.org --]
[-- Type: text/org, Size: 191 bytes --]

# -*- eval: (org-babel-execute-buffer) -*-
#+Title: Evaluates code on startup

* contents
* COMMENT statup code
#+begin_src emacs-lisp :results silent
  (message "I have been run")
#+end_src

[-- Attachment #3: Type: text/plain, Size: 736 bytes --]


Ido Magal <ido@idomagal.com> writes:

> Hello,
>
> Is it possible to put a block of code in a document such that it gets
> evaluated when the document is opened?  For example, I'd like to have
> a link-back section in each note.
>
> I'm aware of babel but I neither understand how to make it auto-evaluate on
> open nor do i know if
> making it compact ( and avoid having code and result blocks ) is possible.
>  I see examples where it's used for export but haven't seen one for general
> org usage.
>
> Thanks in advance.
> _______________________________________________
> 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 #4: 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] 23+ messages in thread

* Re: Embedded code
  2011-01-17 23:48   ` Eric Schulte
@ 2011-01-18  8:51     ` Rainer M Krug
  2011-01-18 16:16       ` Eric Schulte
  0 siblings, 1 reply; 23+ messages in thread
From: Rainer M Krug @ 2011-01-18  8:51 UTC (permalink / raw)
  To: Eric Schulte; +Cc: Ido Magal, emacs-orgmode

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 01/18/2011 12:48 AM, Eric Schulte wrote:
> Hi,
> 
> This is possible using Babel, the attached org-mode file will execute
> its code block every time it is opened.  You can replace the contents of
> the code block with any arbitrary elisp you would like to have executed
> in the file.
> 
> To see this work, save the attached org-mode file to your system, open
> the file, answer "y" to allow execution, and then check your messages
> buffer for the "I have been run" message to see that the code block has
> in fact been evaluated.

This is indeed very useful (e.g. if I open an R script, to open an R
session and source the file).

But it seems that all code blocks are evaluated on loading. Is there a
way of only executing a specific code block?

Cheers,

Rainer
> 
> Best -- Eric
> 
> 
> 
> 
> 
> Ido Magal <ido@idomagal.com> writes:
> 
>> Hello,
>>
>> Is it possible to put a block of code in a document such that it gets
>> evaluated when the document is opened?  For example, I'd like to have
>> a link-back section in each note.
>>
>> I'm aware of babel but I neither understand how to make it auto-evaluate on
>> open nor do i know if
>> making it compact ( and avoid having code and result blocks ) is possible.
>>  I see examples where it's used for export but haven't seen one for general
>> org usage.
>>
>> Thanks in advance.
>> _______________________________________________
>> 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
>>
>>
>> _______________________________________________
>> 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


- -- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Natural Sciences Building
Office Suite 2039
Stellenbosch University
Main Campus, Merriman Avenue
Stellenbosch
South Africa

Tel:        +33 - (0)9 53 10 27 44
Cell:       +27 - (0)8 39 47 90 42
Fax (SA):   +27 - (0)8 65 16 27 82
Fax (D) :   +49 - (0)3 21 21 25 22 44
Fax (FR):   +33 - (0)9 58 10 27 44
email:      Rainer@krugs.de

Skype:      RMkrug
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk01VKwACgkQoYgNqgF2egqGpQCfV+cIwibbFNGENpeem101fxy2
DQkAnRx825iX2QP/B9wl/M5xYa61yqQV
=1BSa
-----END PGP SIGNATURE-----

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

* Re: Embedded code
  2011-01-18  8:51     ` Rainer M Krug
@ 2011-01-18 16:16       ` Eric Schulte
  2011-01-18 16:44         ` Rainer M Krug
                           ` (2 more replies)
  0 siblings, 3 replies; 23+ messages in thread
From: Eric Schulte @ 2011-01-18 16:16 UTC (permalink / raw)
  To: Rainer M Krug; +Cc: Ido Magal, emacs-orgmode

Rainer M Krug <r.m.krug@gmail.com> writes:

> On 01/18/2011 12:48 AM, Eric Schulte wrote:
>> Hi,
>> 
>> This is possible using Babel, the attached org-mode file will execute
>> its code block every time it is opened.  You can replace the contents of
>> the code block with any arbitrary elisp you would like to have executed
>> in the file.
>> 
>> To see this work, save the attached org-mode file to your system, open
>> the file, answer "y" to allow execution, and then check your messages
>> buffer for the "I have been run" message to see that the code block has
>> in fact been evaluated.
>
> This is indeed very useful (e.g. if I open an R script, to open an R
> session and source the file).
>
> But it seems that all code blocks are evaluated on loading. Is there a
> way of only executing a specific code block?
>

Yes, replace the 

# -*- eval: (org-babel-execute-buffer) -*-

with

# -*- eval: (save-excursion (org-babel-goto-named-src-block NAME) (org-babel-execute-src-block)) -*-

where NAME is replaced with the name of the code block to execute.

Cheers -- Eric

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

* Re: Embedded code
  2011-01-18 16:16       ` Eric Schulte
@ 2011-01-18 16:44         ` Rainer M Krug
  2011-01-18 17:12         ` Ido Magal
  2011-01-19 23:54         ` Dan Davison
  2 siblings, 0 replies; 23+ messages in thread
From: Rainer M Krug @ 2011-01-18 16:44 UTC (permalink / raw)
  To: Eric Schulte; +Cc: Ido Magal, emacs-orgmode

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 01/18/2011 05:16 PM, Eric Schulte wrote:
> Rainer M Krug <r.m.krug@gmail.com> writes:
> 
>> On 01/18/2011 12:48 AM, Eric Schulte wrote:
>>> Hi,
>>>
>>> This is possible using Babel, the attached org-mode file will execute
>>> its code block every time it is opened.  You can replace the contents of
>>> the code block with any arbitrary elisp you would like to have executed
>>> in the file.
>>>
>>> To see this work, save the attached org-mode file to your system, open
>>> the file, answer "y" to allow execution, and then check your messages
>>> buffer for the "I have been run" message to see that the code block has
>>> in fact been evaluated.
>>
>> This is indeed very useful (e.g. if I open an R script, to open an R
>> session and source the file).
>>
>> But it seems that all code blocks are evaluated on loading. Is there a
>> way of only executing a specific code block?
>>
> 
> Yes, replace the 
> 
> # -*- eval: (org-babel-execute-buffer) -*-
> 
> with
> 
> # -*- eval: (save-excursion (org-babel-goto-named-src-block NAME) (org-babel-execute-src-block)) -*-
> 
> where NAME is replaced with the name of the code block to execute.

Thanks - sounds perfect.

Cheers,

Rainer

> 
> Cheers -- Eric


- -- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Natural Sciences Building
Office Suite 2039
Stellenbosch University
Main Campus, Merriman Avenue
Stellenbosch
South Africa

Tel:        +33 - (0)9 53 10 27 44
Cell:       +27 - (0)8 39 47 90 42
Fax (SA):   +27 - (0)8 65 16 27 82
Fax (D) :   +49 - (0)3 21 21 25 22 44
Fax (FR):   +33 - (0)9 58 10 27 44
email:      Rainer@krugs.de

Skype:      RMkrug
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk01w4kACgkQoYgNqgF2egpHFACfaspSlVeXg9oQ6Dr5zJIsEN1z
zT0An2UoPkOi6GiQcmZfzKiFTbQgrCex
=eICm
-----END PGP SIGNATURE-----

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

* Re: Embedded code
  2011-01-18 16:16       ` Eric Schulte
  2011-01-18 16:44         ` Rainer M Krug
@ 2011-01-18 17:12         ` Ido Magal
  2011-01-18 18:35           ` Nick Dokos
  2011-01-18 20:42           ` Eric Schulte
  2011-01-19 23:54         ` Dan Davison
  2 siblings, 2 replies; 23+ messages in thread
From: Ido Magal @ 2011-01-18 17:12 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode, Rainer M Krug


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

Eric,

thanks.  This is great.

Couple of followups:

1. Is it possible to avoid the confirmations on every file load?
2. Is it possible to manipulate or reference the results so that they're not
bound to a RESULTS block.  I'm finding all of the blocks of orgmode
distracting and I'm trying to avoid and eliminate them as much as possible.
 I'm not used to it and they really impedes the readability of my notes.
 Ideally my notes would look something like this:

* note 1
* note 2

* Back-links to this note:
(backlinks-function)
* All notes tagged with /foo/
(tagged-with( foo ))
* All notes tagged with /bar/
(tagged-with( bar ))

Is this possible?

Thanks again.  Cheers.


On Tue, Jan 18, 2011 at 08:16, Eric Schulte <schulte.eric@gmail.com> wrote:

> Rainer M Krug <r.m.krug@gmail.com> writes:
>
> > On 01/18/2011 12:48 AM, Eric Schulte wrote:
> >> Hi,
> >>
> >> This is possible using Babel, the attached org-mode file will execute
> >> its code block every time it is opened.  You can replace the contents of
> >> the code block with any arbitrary elisp you would like to have executed
> >> in the file.
> >>
> >> To see this work, save the attached org-mode file to your system, open
> >> the file, answer "y" to allow execution, and then check your messages
> >> buffer for the "I have been run" message to see that the code block has
> >> in fact been evaluated.
> >
> > This is indeed very useful (e.g. if I open an R script, to open an R
> > session and source the file).
> >
> > But it seems that all code blocks are evaluated on loading. Is there a
> > way of only executing a specific code block?
> >
>
> Yes, replace the
>
> # -*- eval: (org-babel-execute-buffer) -*-
>
> with
>
> # -*- eval: (save-excursion (org-babel-goto-named-src-block NAME)
> (org-babel-execute-src-block)) -*-
>
> where NAME is replaced with the name of the code block to execute.
>
> Cheers -- Eric
>

[-- Attachment #1.2: Type: text/html, Size: 2703 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] 23+ messages in thread

* Re: Embedded code
  2011-01-18 17:12         ` Ido Magal
@ 2011-01-18 18:35           ` Nick Dokos
  2011-01-18 20:42           ` Eric Schulte
  1 sibling, 0 replies; 23+ messages in thread
From: Nick Dokos @ 2011-01-18 18:35 UTC (permalink / raw)
  To: Ido Magal; +Cc: nicholas.dokos, emacs-orgmode, Rainer M Krug

Ido Magal <ido@idomagal.com> wrote:

> 
> 1. Is it possible to avoid the confirmations on every file load?
> 

Yes: check out the variable safe-local-variable-values (and the related
safe-local-eval-forms) for the general emacs-level nagging mechanism and
the variable org-confirm-babel-evaluate for the babel-specific one.

I had already set the latter to nil so when I tried out Eric's solution,
I got the first nag, together with an invitation to type y, no or ! to
resp.  apply, ignore, or apply and save for future sessions. I typed !
and it saved the setting in my customization file. No more nags.[fn:1]

Nick

Footnotes:
[fn:1] I'd have expected it to modify safe-local-eval-forms, but it
modified safe-local-variable-values instead. Regardless, it seems to
work fine.

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

* Re: Embedded code
  2011-01-18 17:12         ` Ido Magal
  2011-01-18 18:35           ` Nick Dokos
@ 2011-01-18 20:42           ` Eric Schulte
  2011-01-19  6:46             ` Ido Magal
  1 sibling, 1 reply; 23+ messages in thread
From: Eric Schulte @ 2011-01-18 20:42 UTC (permalink / raw)
  To: Ido Magal; +Cc: emacs-orgmode, Rainer M Krug

> 
> 2. Is it possible to manipulate or reference the results so that they're not
> bound to a RESULTS block.  I'm finding all of the blocks of orgmode
> distracting and I'm trying to avoid and eliminate them as much as possible.
>  I'm not used to it and they really impedes the readability of my notes.

Yes, you can change the look of the results of code blocks, see the
results header argument for more information.
http://orgmode.org/manual/results.html

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

* Re: Embedded code
  2011-01-18 20:42           ` Eric Schulte
@ 2011-01-19  6:46             ` Ido Magal
  2011-01-21  3:54               ` Ido Magal
  0 siblings, 1 reply; 23+ messages in thread
From: Ido Magal @ 2011-01-19  6:46 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode, Rainer M Krug


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

Excellent.

Now that I see that it's possible, I'm struggling to find sufficient
examples to help me understand how to go about writing the bits of lisp that
would allow to me create useful blocks of org-mode code, such as a
back-links block or a list of links to entries of a certain tag.  I'm
lisp-illiterate but I was expecting that if it was possible then someone had
already done it and that I could cut and paste my way to success.

Do these examples exist?  Does anyone use babel to extend the functionality
of the note organizing aspect of org-mode?  All of the babel examples I've
found relate to manipulating content for export as opposed to enhancing
organizational utility.

Cheers and thanks again.


On Tue, Jan 18, 2011 at 12:42, Eric Schulte <schulte.eric@gmail.com> wrote:

> >
> > 2. Is it possible to manipulate or reference the results so that they're
> not
> > bound to a RESULTS block.  I'm finding all of the blocks of orgmode
> > distracting and I'm trying to avoid and eliminate them as much as
> possible.
> >  I'm not used to it and they really impedes the readability of my notes.
>
> Yes, you can change the look of the results of code blocks, see the
> results header argument for more information.
> http://orgmode.org/manual/results.html
>

[-- Attachment #1.2: Type: text/html, Size: 1809 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] 23+ messages in thread

* Re: Embedded code
  2011-01-18 16:16       ` Eric Schulte
  2011-01-18 16:44         ` Rainer M Krug
  2011-01-18 17:12         ` Ido Magal
@ 2011-01-19 23:54         ` Dan Davison
  2 siblings, 0 replies; 23+ messages in thread
From: Dan Davison @ 2011-01-19 23:54 UTC (permalink / raw)
  To: emacs-orgmode

"Eric Schulte" <schulte.eric@gmail.com> writes:

> Rainer M Krug <r.m.krug@gmail.com> writes:
>
>> On 01/18/2011 12:48 AM, Eric Schulte wrote:
>>> Hi,
>>> 
>>> This is possible using Babel, the attached org-mode file will execute
>>> its code block every time it is opened.  You can replace the contents of
>>> the code block with any arbitrary elisp you would like to have executed
>>> in the file.
>>> 
>>> To see this work, save the attached org-mode file to your system, open
>>> the file, answer "y" to allow execution, and then check your messages
>>> buffer for the "I have been run" message to see that the code block has
>>> in fact been evaluated.
>>
>> This is indeed very useful (e.g. if I open an R script, to open an R
>> session and source the file).
>>
>> But it seems that all code blocks are evaluated on loading. Is there a
>> way of only executing a specific code block?
>>
>
> Yes, replace the 
>
> # -*- eval: (org-babel-execute-buffer) -*-
>
> with
>
> # -*- eval: (save-excursion (org-babel-goto-named-src-block NAME) (org-babel-execute-src-block)) -*-

I think `sbe' can be used here for a nice short version. E.g.

# -*- eval: (sbe NAME) -*-

or this at the end

# Local variables:
# eval:(sbe NAME)
# End:

where NAME is a double-quoted string.

Dan

>
> where NAME is replaced with the name of the code block to execute.
>
> Cheers -- Eric
>
> _______________________________________________
> 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] 23+ messages in thread

* Re: Embedded code
  2011-01-19  6:46             ` Ido Magal
@ 2011-01-21  3:54               ` Ido Magal
  2011-01-22  2:05                 ` Eric Schulte
  0 siblings, 1 reply; 23+ messages in thread
From: Ido Magal @ 2011-01-21  3:54 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode, Rainer M Krug


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

So I was able to construct the following functioning bit of code from
someone else recent post:

#+begin_src emacs-lisp :results output raw
(defun tagged (tag &optional scope)
 (let ((entries ()))
   (org-map-entries
     (lambda ()
       (add-to-list 'entries
                    (list (concat "[[" (nth 4 (org-heading-components))
"]]"))))
     tag scope)

   (sort entries (lambda (f s)
                    (string-lessp (car f) (car s))))))

(tagged "buy" 'agenda)
#+end_src

I have a few elementary questions I hope someone can bother to answer:

1. It seems that when org prints a list, it automatically formats it into a
table.  In lisp, what's a proper way of converting a list to a string so I
can have more control over the format?  My first attempts were unsuccessful.

2. I'd like to use Org's macros to replace

#+begin_src
(tagged "foo")
#+end_src

with

{{{(tagged "foo")}}}

but Org macros only expand on export.  Would it be feasible to change the
macro functionality and hook into file loading?  Or is there some other way
I can slim these down to be terse?


On Tue, Jan 18, 2011 at 22:46, Ido Magal <ido@idomagal.com> wrote:

> Excellent.
>
> Now that I see that it's possible, I'm struggling to find sufficient
> examples to help me understand how to go about writing the bits of lisp that
> would allow to me create useful blocks of org-mode code, such as a
> back-links block or a list of links to entries of a certain tag.  I'm
> lisp-illiterate but I was expecting that if it was possible then someone had
> already done it and that I could cut and paste my way to success.
>
> Do these examples exist?  Does anyone use babel to extend the functionality
> of the note organizing aspect of org-mode?  All of the babel examples I've
> found relate to manipulating content for export as opposed to enhancing
> organizational utility.
>
> Cheers and thanks again.
>
>
> On Tue, Jan 18, 2011 at 12:42, Eric Schulte <schulte.eric@gmail.com>wrote:
>
>> >
>> > 2. Is it possible to manipulate or reference the results so that they're
>> not
>> > bound to a RESULTS block.  I'm finding all of the blocks of orgmode
>> > distracting and I'm trying to avoid and eliminate them as much as
>> possible.
>> >  I'm not used to it and they really impedes the readability of my notes.
>>
>> Yes, you can change the look of the results of code blocks, see the
>> results header argument for more information.
>> http://orgmode.org/manual/results.html
>>
>
>

[-- Attachment #1.2: Type: text/html, Size: 3749 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] 23+ messages in thread

* Re: Embedded code
  2011-01-21  3:54               ` Ido Magal
@ 2011-01-22  2:05                 ` Eric Schulte
  2011-01-22  2:10                   ` Ido Magal
                                     ` (2 more replies)
  0 siblings, 3 replies; 23+ messages in thread
From: Eric Schulte @ 2011-01-22  2:05 UTC (permalink / raw)
  To: Ido Magal; +Cc: emacs-orgmode, Rainer M Krug

>
> I have a few elementary questions I hope someone can bother to answer:
>
> 1. It seems that when org prints a list, it automatically formats it into a
> table.  In lisp, what's a proper way of converting a list to a string so I
> can have more control over the format?  My first attempts were unsuccessful.
>

There are a variety of ways to convert lists to strings, look at the
`format' function for printing any elisp value to a string.  You can
also use something like the following to convert a list to a string

#+begin_src emacs-lisp
  (mapconcat (lambda (el) (format "%S" el)) '(1 2 3 4 5 6) "\t")
#+end_src

>
> 2. I'd like to use Org's macros to replace
>
> #+begin_src
> (tagged "foo")
> #+end_src
>
> with
>
> {{{(tagged "foo")}}}
>
> but Org macros only expand on export.  Would it be feasible to change the
> macro functionality and hook into file loading?  Or is there some other way
> I can slim these down to be terse?
>

You can use the inline code syntax for very small blocks, e.g.

  src_emacs-lisp{(tagged "foo")}

See http://orgmode.org/manual/Structure-of-code-blocks.html

Cheers -- Eric

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

* Re: Embedded code
  2011-01-22  2:05                 ` Eric Schulte
@ 2011-01-22  2:10                   ` Ido Magal
  2011-01-25  4:41                   ` Ido Magal
  2011-02-04  6:52                   ` Ido Magal
  2 siblings, 0 replies; 23+ messages in thread
From: Ido Magal @ 2011-01-22  2:10 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode, Rainer M Krug


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

Perfect!  Thanks on both counts.

On Fri, Jan 21, 2011 at 18:05, Eric Schulte <schulte.eric@gmail.com> wrote:

> >
> > I have a few elementary questions I hope someone can bother to answer:
> >
> > 1. It seems that when org prints a list, it automatically formats it into
> a
> > table.  In lisp, what's a proper way of converting a list to a string so
> I
> > can have more control over the format?  My first attempts were
> unsuccessful.
> >
>
> There are a variety of ways to convert lists to strings, look at the
> `format' function for printing any elisp value to a string.  You can
> also use something like the following to convert a list to a string
>
> #+begin_src emacs-lisp
>  (mapconcat (lambda (el) (format "%S" el)) '(1 2 3 4 5 6) "\t")
> #+end_src
>
> >
> > 2. I'd like to use Org's macros to replace
> >
> > #+begin_src
> > (tagged "foo")
> > #+end_src
> >
> > with
> >
> > {{{(tagged "foo")}}}
> >
> > but Org macros only expand on export.  Would it be feasible to change the
> > macro functionality and hook into file loading?  Or is there some other
> way
> > I can slim these down to be terse?
> >
>
> You can use the inline code syntax for very small blocks, e.g.
>
>  src_emacs-lisp{(tagged "foo")}
>
> See http://orgmode.org/manual/Structure-of-code-blocks.html
>
> Cheers -- Eric
>

[-- Attachment #1.2: Type: text/html, Size: 1955 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] 23+ messages in thread

* Re: Embedded code
  2011-01-22  2:05                 ` Eric Schulte
  2011-01-22  2:10                   ` Ido Magal
@ 2011-01-25  4:41                   ` Ido Magal
  2011-01-25 17:16                     ` Eric Schulte
  2011-02-04  6:52                   ` Ido Magal
  2 siblings, 1 reply; 23+ messages in thread
From: Ido Magal @ 2011-01-25  4:41 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode, Rainer M Krug


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

On Fri, Jan 21, 2011 at 18:05, Eric Schulte <schulte.eric@gmail.com> wrote:

>
> You can use the inline code syntax for very small blocks, e.g.
>
>  src_emacs-lisp{(tagged "foo")}
>

I'm missing something.  This does not evaluate with

# -*- eval: (org-babel-execute-buffer) -*-

[-- Attachment #1.2: Type: text/html, Size: 642 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] 23+ messages in thread

* Re: Embedded code
  2011-01-25  4:41                   ` Ido Magal
@ 2011-01-25 17:16                     ` Eric Schulte
  2011-01-26  4:44                       ` Ido Magal
  0 siblings, 1 reply; 23+ messages in thread
From: Eric Schulte @ 2011-01-25 17:16 UTC (permalink / raw)
  To: Ido Magal; +Cc: emacs-orgmode, Rainer M Krug

Ido Magal <ido@idomagal.com> writes:

> On Fri, Jan 21, 2011 at 18:05, Eric Schulte <schulte.eric@gmail.com> wrote:
>
>>
>> You can use the inline code syntax for very small blocks, e.g.
>>
>>  src_emacs-lisp{(tagged "foo")}
>>
>
> I'm missing something.  This does not evaluate with
>
> # -*- eval: (org-babel-execute-buffer) -*-

Hi,

Thanks for the catch, you are correct, `org-babel-execute-buffer' did
not evaluate inline code blocks, I've just pushed up a fix for this.

Cheers -- Eric

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

* Re: Embedded code
  2011-01-25 17:16                     ` Eric Schulte
@ 2011-01-26  4:44                       ` Ido Magal
  2011-01-26  4:54                         ` Eric Schulte
  2011-01-26  9:41                         ` Sébastien Vauban
  0 siblings, 2 replies; 23+ messages in thread
From: Ido Magal @ 2011-01-26  4:44 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode, Rainer M Krug


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

I've gotten the fix and am trying to verify it, however I keep seeing

>File local-variables error: (invalid-function org-save-outline-visibility)

I'm not sure if it's relevant or not.  This is my test file:

--------------------------------------------------------------------
# -*- eval: (org-babel-execute-buffer) -*-

src_sh[:results append]{ls -t ~/org/ *.txt|head -5}
--------------------------------------------------------------------



>
> Thanks for the catch, you are correct, `org-babel-execute-buffer' did
> not evaluate inline code blocks, I've just pushed up a fix for this.
>
>

[-- Attachment #1.2: Type: text/html, Size: 993 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] 23+ messages in thread

* Re: Embedded code
  2011-01-26  4:44                       ` Ido Magal
@ 2011-01-26  4:54                         ` Eric Schulte
  2011-01-27 20:45                           ` Ido Magal
  2011-01-26  9:41                         ` Sébastien Vauban
  1 sibling, 1 reply; 23+ messages in thread
From: Eric Schulte @ 2011-01-26  4:54 UTC (permalink / raw)
  To: Ido Magal; +Cc: emacs-orgmode, Rainer M Krug

Ido Magal <ido@idomagal.com> writes:

> I've gotten the fix and am trying to verify it, however I keep seeing
>
>>File local-variables error: (invalid-function org-save-outline-visibility)
>

Hmm, this function is defined in org-macs.el, and is required by ob.el
so if you have Org-mode and Babel loaded then the function should be
defined.  I can't reproduce the error, maybe it is specific to your
Emacs version or configuration?

Best -- Eric

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

* Re: Embedded code
  2011-01-26  4:44                       ` Ido Magal
  2011-01-26  4:54                         ` Eric Schulte
@ 2011-01-26  9:41                         ` Sébastien Vauban
  2011-01-27 22:51                           ` Eric Schulte
  1 sibling, 1 reply; 23+ messages in thread
From: Sébastien Vauban @ 2011-01-26  9:41 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi Eric and Ido,

Ido Magal wrote:
> I've gotten the fix and am trying to verify it, however I keep seeing
>
>> File local-variables error: (invalid-function org-save-outline-visibility)
>
> I'm not sure if it's relevant or not.  This is my test file:
>
> --------------------------------------------------------------------
> # -*- eval: (org-babel-execute-buffer) -*-
>
> src_sh[:results append]{ls -t ~/org/ *.txt|head -5}
> --------------------------------------------------------------------

When this call is executed, the table results is inserted *before* the call
line. Is this the intended behavior?

Best regards,
  Seb

-- 
Sébastien Vauban


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

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

* Re: Embedded code
  2011-01-26  4:54                         ` Eric Schulte
@ 2011-01-27 20:45                           ` Ido Magal
  0 siblings, 0 replies; 23+ messages in thread
From: Ido Magal @ 2011-01-27 20:45 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode, Rainer M Krug


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

Thanks.  Removing package.el and replacing (required 'org) with (required
'org-install) fixed it.  I still don't know what the difference is but I
seem to be functional now.

On Tue, Jan 25, 2011 at 20:54, Eric Schulte <schulte.eric@gmail.com> wrote:

> Ido Magal <ido@idomagal.com> writes:
>
> > I've gotten the fix and am trying to verify it, however I keep seeing
> >
> >>File local-variables error: (invalid-function
> org-save-outline-visibility)
> >
>
> Hmm, this function is defined in org-macs.el, and is required by ob.el
> so if you have Org-mode and Babel loaded then the function should be
> defined.  I can't reproduce the error, maybe it is specific to your
> Emacs version or configuration?
>
> Best -- Eric
>
> _______________________________________________
> 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: 1557 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] 23+ messages in thread

* Re: Re: Embedded code
  2011-01-26  9:41                         ` Sébastien Vauban
@ 2011-01-27 22:51                           ` Eric Schulte
  0 siblings, 0 replies; 23+ messages in thread
From: Eric Schulte @ 2011-01-27 22:51 UTC (permalink / raw)
  To: Sébastien Vauban; +Cc: emacs-orgmode

Sébastien Vauban <wxhgmqzgwmuf@spammotel.com> writes:

> Hi Eric and Ido,
>
> Ido Magal wrote:
>> I've gotten the fix and am trying to verify it, however I keep seeing
>>
>>> File local-variables error: (invalid-function org-save-outline-visibility)
>>
>> I'm not sure if it's relevant or not.  This is my test file:
>>
>> --------------------------------------------------------------------
>> # -*- eval: (org-babel-execute-buffer) -*-
>>
>> src_sh[:results append]{ls -t ~/org/ *.txt|head -5}
>> --------------------------------------------------------------------
>
> When this call is executed, the table results is inserted *before* the call
> line. Is this the intended behavior?
>

The implementation of inline code blocks assumed that they would be used
inline for referencing live values from within paragraphs.  The most
common usage replaces the code block with the result upon export.  We
never really anticipated this syntax being used to replace regular code
blocks.

Given that these can and now are being used in other ways, I've updated
the handling of inline code blocks bringing it more inline with regular
code block usage -- and simplifying the export mechanisms.  They should
now insert their results *after* the code block.

Best -- Eric

>
> Best regards,
>   Seb

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

* Re: Embedded code
  2011-01-22  2:05                 ` Eric Schulte
  2011-01-22  2:10                   ` Ido Magal
  2011-01-25  4:41                   ` Ido Magal
@ 2011-02-04  6:52                   ` Ido Magal
  2011-02-04 20:35                     ` Eric Schulte
  2 siblings, 1 reply; 23+ messages in thread
From: Ido Magal @ 2011-02-04  6:52 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode, Rainer M Krug


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

On Fri, Jan 21, 2011 at 18:05, Eric Schulte <schulte.eric@gmail.com> wrote:
>
>
> There are a variety of ways to convert lists to strings, look at the
> `format' function for printing any elisp value to a string.  You can
> also use something like the following to convert a list to a string
>
> #+begin_src emacs-lisp
>  (mapconcat (lambda (el) (format "%S" el)) '(1 2 3 4 5 6) "\t")
> #+end_src
>
> ...

>
> You can use the inline code syntax for very small blocks, e.g.
>
>
I've proceeded with my little project using the dynamic block, since it
seems that this is what it was designed for. I wrote the following bit of
code and would appreciate answers to a couple of questions.

#+begin_src emacs-lisp :results silent
(defun flatten-string-with-links (str)
  (let* ((newstr str))
    ; find [[link][desc]] and replace with 'desc.
    (setq newstr (replace-regexp-in-string
"\\[\\[[^\\[]+\\]\\[[^//[]+\\]\\]"
                (lambda (s) (save-match-data
                         (nth 2 (split-string s "[\]\[]+")))) newstr))
    ; find [[link]] and replace with 'link.
    (setq newstr (replace-regexp-in-string "\\[\\[[^\\[]+\\]\\]"
    (lambda(s) (save-match-data
      (nth 1 (split-string s "[\]\[]+")))) newstr))
  newstr))

(defun org-dblock-write:tagged (params)
  (insert (mapconcat 'identity
     (org-map-entries
      (lambda()
 (let* (link desc innerlink)
  (setq desc (nth 4 (org-heading-components)))
  (setq desc (flatten-string-with-links desc))
  (setq link (concat "file:"
     (abbreviate-file-name (buffer-file-name (buffer-base-buffer)))
     "::"
     (org-make-org-heading-search-string)))
  (org-make-link-string link desc)))
 (plist-get params :tag)
(plist-get params :scope))
      "\n")))
 #+end_src

* example       :links:
** not a link
** [[http://google.com][link]]
** some text.[[http://google.com][link]]
** [[http://google.com]]
** some text. [[http://google.com][link]]. more text.
[[http://google.com][link]].
final text.
** [[
http://www.knifecenter.com/kc_new/store_detail.html?s%3DAOBSHARP][brokenlink]]

#+BEGIN: tagged :tag "links"
#+END


Q1: I've tried to leverage as much built-in org functionality as possible,
but deeply suspect that I'm overlooking some, since agendas do much of this
work.  Is there a simpler solution than mine?

Q2: The link generated for the last item ("broken link") does not work.
 Removing the "%" from the URL fixes it.  This seems to be a bug
in org-make-org-heading-search-string?  Or am I misusing it?

Any help would be greatly appreciated.

[-- Attachment #1.2: Type: text/html, Size: 5285 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] 23+ messages in thread

* Re: Embedded code
  2011-02-04  6:52                   ` Ido Magal
@ 2011-02-04 20:35                     ` Eric Schulte
  0 siblings, 0 replies; 23+ messages in thread
From: Eric Schulte @ 2011-02-04 20:35 UTC (permalink / raw)
  To: Ido Magal; +Cc: emacs-orgmode, Rainer M Krug

Ido Magal <ido@idomagal.com> writes:

> On Fri, Jan 21, 2011 at 18:05, Eric Schulte <schulte.eric@gmail.com> wrote:
>>
>>
>> There are a variety of ways to convert lists to strings, look at the
>> `format' function for printing any elisp value to a string.  You can
>> also use something like the following to convert a list to a string
>>
>> #+begin_src emacs-lisp
>>  (mapconcat (lambda (el) (format "%S" el)) '(1 2 3 4 5 6) "\t")
>> #+end_src
>>
>> ...
>
>>
>> You can use the inline code syntax for very small blocks, e.g.
>>
>>
> I've proceeded with my little project using the dynamic block, since it
> seems that this is what it was designed for. I wrote the following bit of
> code and would appreciate answers to a couple of questions.
>
> #+begin_src emacs-lisp :results silent
> (defun flatten-string-with-links (str)
>   (let* ((newstr str))
>     ; find [[link][desc]] and replace with 'desc.
>     (setq newstr (replace-regexp-in-string
> "\\[\\[[^\\[]+\\]\\[[^//[]+\\]\\]"
>                 (lambda (s) (save-match-data
>                          (nth 2 (split-string s "[\]\[]+")))) newstr))
>     ; find [[link]] and replace with 'link.
>     (setq newstr (replace-regexp-in-string "\\[\\[[^\\[]+\\]\\]"
>     (lambda(s) (save-match-data
>       (nth 1 (split-string s "[\]\[]+")))) newstr))
>   newstr))
>
> (defun org-dblock-write:tagged (params)
>   (insert (mapconcat 'identity
>      (org-map-entries
>       (lambda()
>  (let* (link desc innerlink)
>   (setq desc (nth 4 (org-heading-components)))
>   (setq desc (flatten-string-with-links desc))
>   (setq link (concat "file:"
>      (abbreviate-file-name (buffer-file-name (buffer-base-buffer)))
>      "::"
>      (org-make-org-heading-search-string)))
>   (org-make-link-string link desc)))
>  (plist-get params :tag)
> (plist-get params :scope))
>       "\n")))
>  #+end_src
>
> * example       :links:
> ** not a link
> ** [[http://google.com][link]]
> ** some text.[[http://google.com][link]]
> ** [[http://google.com]]
> ** some text. [[http://google.com][link]]. more text.
> [[http://google.com][link]].
> final text.
> ** [[
> http://www.knifecenter.com/kc_new/store_detail.html?s%3DAOBSHARP][brokenlink]]
>
> #+BEGIN: tagged :tag "links"
> #+END
>
>
> Q1: I've tried to leverage as much built-in org functionality as possible,
> but deeply suspect that I'm overlooking some,

Yes, it is certainly worth-while to look for existing org-* functions, I
am still often finding myself re-implementing existing functions.

> since agendas do much of this work.  Is there a simpler solution than
> mine?

So your goal is to write a bunch of links into the Org-mode file
following the code block?  A couple of suggestions...
- don't call `insert' from your code block, rather output a string and
  let Babel handle the insert for you

- it looks like you are doing a good job of using existing link
  functions, however in addition to searching for functions with org and
  link in their names with C-h f org-link TAB you can try looking for
  org variables (thinking existing org regular expressions) with
  something like C-h v org-link TAB

>
> Q2: The link generated for the last item ("broken link") does not work.
>  Removing the "%" from the URL fixes it.  This seems to be a bug
> in org-make-org-heading-search-string?  Or am I misusing it?
>

I have no idea, I haven't used these functions.

>
> Any help would be greatly appreciated.

Hope this helps.  Best -- Eric

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

end of thread, other threads:[~2011-02-04 20:51 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-17 16:06 Embedded code Ido Magal
2011-01-17 22:01 ` Ido Magal
2011-01-17 23:48   ` Eric Schulte
2011-01-18  8:51     ` Rainer M Krug
2011-01-18 16:16       ` Eric Schulte
2011-01-18 16:44         ` Rainer M Krug
2011-01-18 17:12         ` Ido Magal
2011-01-18 18:35           ` Nick Dokos
2011-01-18 20:42           ` Eric Schulte
2011-01-19  6:46             ` Ido Magal
2011-01-21  3:54               ` Ido Magal
2011-01-22  2:05                 ` Eric Schulte
2011-01-22  2:10                   ` Ido Magal
2011-01-25  4:41                   ` Ido Magal
2011-01-25 17:16                     ` Eric Schulte
2011-01-26  4:44                       ` Ido Magal
2011-01-26  4:54                         ` Eric Schulte
2011-01-27 20:45                           ` Ido Magal
2011-01-26  9:41                         ` Sébastien Vauban
2011-01-27 22:51                           ` Eric Schulte
2011-02-04  6:52                   ` Ido Magal
2011-02-04 20:35                     ` Eric Schulte
2011-01-19 23:54         ` Dan Davison

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