5

For some org-mode files, I would like to run specific commands when that file is opened for editing. These commands should be written in the heading of the file somewhere near the #+CONFIG bits.

E.g in my 'WeeklyReport.org' I would like it to automatically run my function NavigateToOrCreateThisWeek()

Is this possible?

As an alternative, I currently have functions that load a file and then do something. But I'd like to instruct the functions to be ran when ever I open that file.

Leo Ufimtsev
  • 4,488
  • 3
  • 22
  • 45
  • 5
    Try [file local variable](http://www.gnu.org/software/emacs/manual/html_node/emacs/Specifying-File-Variables.html#Specifying-File-Variables)? especially `eval` – xuchunyang Jun 08 '15 at 15:13
  • 2
    Does this answer your question? [How can I evaluate elisp in an orgmode file when it is opened?](https://emacs.stackexchange.com/questions/12938/how-can-i-evaluate-elisp-in-an-orgmode-file-when-it-is-opened) – xeruf Mar 20 '21 at 14:12

1 Answers1

8

When using eval with Emacs file-specific variables, then any valid lisp function can be specified at the end of the file as shown here:

;; Local Variables:
;; eval: (myFunction arg1 arg2)
;; End:

If you need variable arguments based on org-mode features, then you can combine the above with in-buffer settings available for org-mode files.

incandescentman
  • 4,111
  • 16
  • 53
Emacs User
  • 5,553
  • 18
  • 48
  • 1
    I found this answer would only work if the Local Variables block were added to the _end_ of the Org Mode file. Using GNU Emacs 26.3. – bgoodr Mar 02 '20 at 02:03