emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* automatically run code blocks when loading an org-mode document
@ 2016-07-22 21:11 grewil3 .
  2016-07-22 22:11 ` Nick Dokos
       [not found] ` <4bce9e43b5d240aba4583f721502ac02@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>
  0 siblings, 2 replies; 5+ messages in thread
From: grewil3 . @ 2016-07-22 21:11 UTC (permalink / raw)
  To: emacs-orgmode

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

Hi! When I load the document below, I first need to manually evaluate the
code block before I can use the links. I would like the code block to be
automatically evaluated when I load the document, making the links usable
at once.

Is there some clever in-buffer-setting I can use, to specify that I want
the block called on loading, some kind of post-load hook?

#+BEGIN_SRC emacs-lisp
(defun handy-stuff(arg)
  (message arg))
#+END_SRC

[[elisp:(handy-stuff "foo")][foo]]
[[elisp:(handy-stuff "bar")][bar]]

[-- Attachment #2: Type: text/html, Size: 693 bytes --]

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

* Re: automatically run code blocks when loading an org-mode document
  2016-07-22 21:11 automatically run code blocks when loading an org-mode document grewil3 .
@ 2016-07-22 22:11 ` Nick Dokos
  2016-07-23  4:46   ` grewil3 .
       [not found] ` <4bce9e43b5d240aba4583f721502ac02@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>
  1 sibling, 1 reply; 5+ messages in thread
From: Nick Dokos @ 2016-07-22 22:11 UTC (permalink / raw)
  To: emacs-orgmode

"grewil3 ." <grewil@gmail.com> writes:

> Hi! When I load the document below, I first need to manually evaluate the code block before I can use
> the links. I would like the code block to be automatically evaluated when I load the document, making
> the links usable at once.
>
> Is there some clever in-buffer-setting I can use, to specify that I want the block called on loading,
> some kind of post-load hook?
>
> #+BEGIN_SRC emacs-lisp
> (defun handy-stuff(arg)
>   (message arg))
> #+END_SRC
>
> [[elisp:(handy-stuff "foo")][foo]]
> [[elisp:(handy-stuff "bar")][bar]]
>

--8<---------------cut here---------------start------------->8---
#  -*- find-file-hook: org-babel-execute-buffer -*-
#+BEGIN_SRC emacs-lisp
(defun handy-stuff(arg)
 (message arg))
#+END_SRC

[[elisp:(handy-stuff "foo")][foo]]
[[elisp:(handy-stuff "bar")][bar]]

--8<---------------cut here---------------end--------------->8---

will do that (but you get a question re. "safe" local variables when
you open the file). It also executes *every* code block in the buffer
which you might not want to do (although it does not matter in this
case).

-- 
Nick

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

* Re: automatically run code blocks when loading an org-mode document
  2016-07-22 22:11 ` Nick Dokos
@ 2016-07-23  4:46   ` grewil3 .
  0 siblings, 0 replies; 5+ messages in thread
From: grewil3 . @ 2016-07-23  4:46 UTC (permalink / raw)
  To: emacs-orgmode

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

Sir, you are a great genius - many thanks!

On Sat, Jul 23, 2016 at 12:11 AM, Nick Dokos <ndokos@gmail.com> wrote:

> "grewil3 ." <grewil@gmail.com> writes:
>
> > Hi! When I load the document below, I first need to manually evaluate
> the code block before I can use
> > the links. I would like the code block to be automatically evaluated
> when I load the document, making
> > the links usable at once.
> >
> > Is there some clever in-buffer-setting I can use, to specify that I want
> the block called on loading,
> > some kind of post-load hook?
> >
> > #+BEGIN_SRC emacs-lisp
> > (defun handy-stuff(arg)
> >   (message arg))
> > #+END_SRC
> >
> > [[elisp:(handy-stuff "foo")][foo]]
> > [[elisp:(handy-stuff "bar")][bar]]
> >
>
> --8<---------------cut here---------------start------------->8---
> #  -*- find-file-hook: org-babel-execute-buffer -*-
> #+BEGIN_SRC emacs-lisp
> (defun handy-stuff(arg)
>  (message arg))
> #+END_SRC
>
> [[elisp:(handy-stuff "foo")][foo]]
> [[elisp:(handy-stuff "bar")][bar]]
>
> --8<---------------cut here---------------end--------------->8---
>
> will do that (but you get a question re. "safe" local variables when
> you open the file). It also executes *every* code block in the buffer
> which you might not want to do (although it does not matter in this
> case).
>
> --
> Nick
>
>
>

[-- Attachment #2: Type: text/html, Size: 2024 bytes --]

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

* Re: automatically run code blocks when loading an org-mode document
       [not found] ` <4bce9e43b5d240aba4583f721502ac02@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>
@ 2016-07-24  8:27   ` Eric S Fraga
  2016-07-24 19:24     ` Nick Dokos
  0 siblings, 1 reply; 5+ messages in thread
From: Eric S Fraga @ 2016-07-24  8:27 UTC (permalink / raw)
  To: Nick Dokos; +Cc: emacs-orgmode@gnu.org

On Friday, 22 Jul 2016 at 22:11, Nick Dokos wrote:

[...]

> #  -*- find-file-hook: org-babel-execute-buffer -*-
> #+BEGIN_SRC emacs-lisp
> (defun handy-stuff(arg)
>  (message arg))
> #+END_SRC
>
> [[elisp:(handy-stuff "foo")][foo]]
> [[elisp:(handy-stuff "bar")][bar]]
>
> will do that (but you get a question re. "safe" local variables when
> you open the file). It also executes *every* code block in the buffer
> which you might not want to do (although it does not matter in this
> case).

For the OP, instead of evaluating every code block, it is possible to
evaluate just one code block.  I have:

# Local Variables:
# eval: (esf/execute-startup-block)
# End:

in my org file with

#+begin_src emacs-lisp
  (defun esf/execute-startup-block ()
    (interactive)
    (org-babel-goto-named-src-block "startup")
    (org-babel-execute-src-block))
#+end_src

and so only a block named startup will be executed.

-- 
: Eric S Fraga (0xFFFCF67D), Emacs 25.0.94.1, Org release_8.3.4-1049-g481709

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

* Re: automatically run code blocks when loading an org-mode document
  2016-07-24  8:27   ` Eric S Fraga
@ 2016-07-24 19:24     ` Nick Dokos
  0 siblings, 0 replies; 5+ messages in thread
From: Nick Dokos @ 2016-07-24 19:24 UTC (permalink / raw)
  To: Eric S Fraga, Nick Dokos, emacs-orgmode@gnu.org

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

​That's a better solution indeed.​

On Sun, Jul 24, 2016 at 4:27 AM, Eric S Fraga <e.fraga@ucl.ac.uk> wrote:

> On Friday, 22 Jul 2016 at 22:11, Nick Dokos wrote:
>
> [...]
>
> > #  -*- find-file-hook: org-babel-execute-buffer -*-
> > #+BEGIN_SRC emacs-lisp
> > (defun handy-stuff(arg)
> >  (message arg))
> > #+END_SRC
> >
> > [[elisp:(handy-stuff "foo")][foo]]
> > [[elisp:(handy-stuff "bar")][bar]]
> >
> > will do that (but you get a question re. "safe" local variables when
> > you open the file). It also executes *every* code block in the buffer
> > which you might not want to do (although it does not matter in this
> > case).
>
> For the OP, instead of evaluating every code block, it is possible to
> evaluate just one code block.  I have:
>
> # Local Variables:
> # eval: (esf/execute-startup-block)
> # End:
>
> in my org file with
>
> #+begin_src emacs-lisp
>   (defun esf/execute-startup-block ()
>     (interactive)
>     (org-babel-goto-named-src-block "startup")
>     (org-babel-execute-src-block))
> #+end_src
>
> and so only a block named startup will be executed.
>
> --
> : Eric S Fraga (0xFFFCF67D), Emacs 25.0.94.1, Org
> release_8.3.4-1049-g481709
>

[-- Attachment #2: Type: text/html, Size: 1827 bytes --]

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

end of thread, other threads:[~2016-07-24 19:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-22 21:11 automatically run code blocks when loading an org-mode document grewil3 .
2016-07-22 22:11 ` Nick Dokos
2016-07-23  4:46   ` grewil3 .
     [not found] ` <4bce9e43b5d240aba4583f721502ac02@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>
2016-07-24  8:27   ` Eric S Fraga
2016-07-24 19:24     ` Nick Dokos

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