From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nick Dokos Subject: Re: automatically run code blocks when loading an org-mode document Date: Sun, 24 Jul 2016 15:24:03 -0400 Message-ID: References: <4bce9e43b5d240aba4583f721502ac02@HE1PR01MB1898.eurprd01.prod.exchangelabs.com> <87invv30gg.fsf@ucl.ac.uk> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a11401bfe5c71320538669c7d Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:37712) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bRP0S-00027Y-7F for emacs-orgmode@gnu.org; Sun, 24 Jul 2016 15:24:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bRP0Q-0005hN-6T for emacs-orgmode@gnu.org; Sun, 24 Jul 2016 15:24:07 -0400 Received: from mail-lf0-x22d.google.com ([2a00:1450:4010:c07::22d]:33774) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bRP0P-0005hH-Ov for emacs-orgmode@gnu.org; Sun, 24 Jul 2016 15:24:06 -0400 Received: by mail-lf0-x22d.google.com with SMTP id b199so115845399lfe.0 for ; Sun, 24 Jul 2016 12:24:05 -0700 (PDT) In-Reply-To: <87invv30gg.fsf@ucl.ac.uk> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Eric S Fraga , Nick Dokos , "emacs-orgmode@gnu.org" --001a11401bfe5c71320538669c7d Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable =E2=80=8BThat's a better solution indeed.=E2=80=8B On Sun, Jul 24, 2016 at 4:27 AM, Eric S Fraga 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 > --001a11401bfe5c71320538669c7d Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
=E2=80=8BThat's a better solution indeed.=E2= =80=8B

On Sun, Jul 24, 2016 at 4:27 AM, Eric S Fraga <e.fraga@ucl.ac.uk><= /span> wrote:
On Friday, 22 Jul 2016 at 2= 2:11, Nick Dokos wrote:

[...]

> #=C2=A0 -*- find-file-hook: org-babel-execute-buffer -*-
> #+BEGIN_SRC emacs-lisp
> (defun handy-stuff(arg)
>=C2=A0 (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 variab= les when
> you open the file). It also executes *every* code block in the buffer<= br> > 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.=C2=A0 I have:

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

in my org file with

#+begin_src emacs-lisp
=C2=A0 (defun esf/execute-startup-block ()
=C2=A0 =C2=A0 (interactive)
=C2=A0 =C2=A0 (org-babel-goto-named-src-block "startup")
=C2=A0 =C2=A0 (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-g48170= 9

--001a11401bfe5c71320538669c7d--