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: Fri, 22 Jul 2016 18:11:57 -0400 Message-ID: <87bn1pe30y.fsf@alphaville.usersys.redhat.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:35936) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQig8-0003FV-DW for emacs-orgmode@gnu.org; Fri, 22 Jul 2016 18:12:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bQig3-0005xZ-As for emacs-orgmode@gnu.org; Fri, 22 Jul 2016 18:12:19 -0400 Received: from plane.gmane.org ([80.91.229.3]:41526) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQig3-0005xB-3y for emacs-orgmode@gnu.org; Fri, 22 Jul 2016 18:12:15 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1bQify-0003Sc-St for emacs-orgmode@gnu.org; Sat, 23 Jul 2016 00:12:10 +0200 Received: from nat-pool-bos-t.redhat.com ([66.187.233.206]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 23 Jul 2016 00:12:10 +0200 Received: from ndokos by nat-pool-bos-t.redhat.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 23 Jul 2016 00:12:10 +0200 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 "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