all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Where to define functions for use with org
@ 2008-10-30 14:47 Daniel Clemente
  2008-10-30 15:47 ` Paul R
  2008-10-31 21:39 ` Eric Schulte
  0 siblings, 2 replies; 3+ messages in thread
From: Daniel Clemente @ 2008-10-30 14:47 UTC (permalink / raw
  To: emacs-orgmode


Hi, I'd like some suggestions about storing (defun)s in .org-files.

  Sometimes Org must use ELisp functions, for instance:
 - a dynamic table uses a function org-dblock-write:some_name to create its contents
 - a table uses a formula like $5='(my-function $2) which does a calculation not available in calc

  These scenarios require that you have already the functions you will use. If you wrote the (defun ...) in your code, you must go there and do C-x C-e to evaluate all of them.

  My question is: ¿how would you make this process automatic and still distribute the function code together with the .org file?

  org provides already contrib/org-eval.el, but I don't want to enable org-eval *globally*, and I am not interested in outputting content; just in defining functions.
  Maybe there are other methods: ideally something similar to Emacs' „local variables“ in headers but for functions.

  How do you do this?

  Thanks,
Daniel

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

* Re: Where to define functions for use with org
  2008-10-30 14:47 Where to define functions for use with org Daniel Clemente
@ 2008-10-30 15:47 ` Paul R
  2008-10-31 21:39 ` Eric Schulte
  1 sibling, 0 replies; 3+ messages in thread
From: Paul R @ 2008-10-30 15:47 UTC (permalink / raw
  To: Daniel Clemente; +Cc: emacs-orgmode

On Thu, 30 Oct 2008 15:47:57 +0100, Daniel Clemente <n142857@gmail.com> said:

Daniel> Maybe there are other methods: ideally something similar to
Daniel> Emacs' „local variables“ in headers but for functions.

The only difference between a function and a variable in emacs lisp, and
in any other Lisp-2, is the register where the name is bound. So if you
can store a value in a variable, you can also store some code through
the use of (lambda ...). Because of this Lisp-2 design, you will have to
call it later with (funcall name arg1 arg2 ...). Try the code below if
you want, in emacs :

    (setq myorgfunction (lambda (a b) (+ a b)))

    (funcall myorgfunction 5 6)

It might help you.

-- 
  Paul

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

* Re: Where to define functions for use with org
  2008-10-30 14:47 Where to define functions for use with org Daniel Clemente
  2008-10-30 15:47 ` Paul R
@ 2008-10-31 21:39 ` Eric Schulte
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Schulte @ 2008-10-31 21:39 UTC (permalink / raw
  To: Daniel Clemente; +Cc: emacs-orgmode

Daniel Clemente <n142857@gmail.com> writes:

> Hi, I'd like some suggestions about storing (defun)s in .org-files.
>
>   Sometimes Org must use ELisp functions, for instance:
>  - a dynamic table uses a function org-dblock-write:some_name to create its contents
>  - a table uses a formula like $5='(my-function $2) which does a calculation not available in calc
>
>   These scenarios require that you have already the functions you will
>   use. If you wrote the (defun ...) in your code, you must go there
>   and do C-x C-e to evaluate all of them.
>
>   My question is: ¿how would you make this process automatic and still
>   distribute the function code together with the .org file?
>

Hi Daniel,

I ran into a problem similar to you description above, and developed a
solution in the form of a modified version of org-eval.el (in the
contrib directory of the org-mode source).  It is like org-eval except
for the following changes...

,----[org-eval-light.el]
| ;;; Changes: by Eric Schulte
| ;;
| ;; 1) forms are only executed manually, (allowing for the execution of
| ;;    an entire subtree of forms)
| ;; 2) use the org-mode style src blocks, rather than the muse style
| ;;    <code></code> blocks
| ;; 3) forms are not replaced by their outputs, but rather the output
| ;;    is placed in the buffer immediately following the src block
| ;;    commented by `org-eval-light-make-region-example' (when
| ;;    evaluated with a prefix argument no output is placed in the
| ;;    buffer)
| ;; 4) add defadvice to org-ctrl-c-ctrl-c so that when called inside of
| ;;    a source block it will call `org-eval-light-current-snippet'
`----

My modified version is available at
http://github.com/eschulte/org-contrib/tree/master/org-eval-light.el

It's been working fairly well for me, in fact I was going to push this
to the mailing list anyways, but wanted to play with it some more.

Cheers -- Eric

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

end of thread, other threads:[~2008-10-31 21:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-30 14:47 Where to define functions for use with org Daniel Clemente
2008-10-30 15:47 ` Paul R
2008-10-31 21:39 ` Eric Schulte

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.