From mboxrd@z Thu Jan 1 00:00:00 1970 From: "grewil3 ." Subject: Re: automatically run code blocks when loading an org-mode document Date: Sat, 23 Jul 2016 06:46:11 +0200 Message-ID: References: <87bn1pe30y.fsf@alphaville.usersys.redhat.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a114585f2feae790538463a69 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:51970) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQopL-0006qV-1u for emacs-orgmode@gnu.org; Sat, 23 Jul 2016 00:46:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bQopJ-0007WD-4F for emacs-orgmode@gnu.org; Sat, 23 Jul 2016 00:46:14 -0400 Received: from mail-vk0-x236.google.com ([2607:f8b0:400c:c05::236]:33764) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQopI-0007W9-Uq for emacs-orgmode@gnu.org; Sat, 23 Jul 2016 00:46:13 -0400 Received: by mail-vk0-x236.google.com with SMTP id x130so182783138vkc.0 for ; Fri, 22 Jul 2016 21:46:12 -0700 (PDT) In-Reply-To: <87bn1pe30y.fsf@alphaville.usersys.redhat.com> 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: emacs-orgmode@gnu.org --001a114585f2feae790538463a69 Content-Type: text/plain; charset=UTF-8 Sir, you are a great genius - many thanks! On Sat, Jul 23, 2016 at 12:11 AM, Nick Dokos wrote: > "grewil3 ." 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 > > > --001a114585f2feae790538463a69 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Sir, you are a great genius - many thanks!

On Sat, Jul 23, 2016 at 12:= 11 AM, Nick Dokos <ndokos@gmail.com> wrote:
"grewil3 .&qu= ot; <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 w= hen I load the document, making
> the links usable at once.
>
> Is there some clever in-buffer-setting I can use, to specify that I wa= nt the block called on loading,
> some kind of post-load hook?
>
> #+BEGIN_SRC emacs-lisp
> (defun handy-stuff(arg)
> =C2=A0 (message arg))
> #+END_SRC
>
> [[elisp:(handy-stuff "foo")][foo]]
> [[elisp:(handy-stuff "bar")][bar]]
>

--8<---------------cut here---------------start-------------= >8---
#=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]]

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

will do that (but you get a question re. "safe" local variables w= hen
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



--001a114585f2feae790538463a69--