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.


1 Answer 1


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.

  • 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 2, 2020 at 2:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.