6

I am using auto-insert so that I can get the usual things I use for org mode when opening a new .org file, example:

#+AUTHOR:   Edgar Aroutiounian
#+EMAIL:    edgar.factorial@gmail.com
#+STARTUP:  indent
#+LANGUAGE: en
#+OPTIONS:  toc:nil num:0

and this gets inserted into every new .org file because I added a define-auto-insert for .org files.

The startup in-buffer setting is important to me, unfortunately I can't get it org-mode to respect it. (Before discovering auto-insert, I used a one off function that inserted this stuff and then called org-mode-restart)

Adding a call to revert-buffer at the end of the org-mode-hook doesn't work either because for new files there is nothing to revert to, and obviously putting a org-mode-restart in the add-hook for org-mode will crap out as well.

I found that org-ctrl-c-ctrl-c will redo the in-buffer settings if the mark is placed over the #+STARTUP: indent, so I tried adding (org-ctrl-c-ctrl-c "#+STARTUP: indent\n") to my org-mode-hook, but that didn't work either. (Was that even a good approach?)

How can I get org-mode to reparse my in-buffer settings for all .org files?

  • Consider using the approach described here: you can make auto-insert evaluate arbitrary elisp code before or after inserting text. – Constantine Dec 2 '14 at 17:26
  • But I'm not sure about the ordering. Doesn't auto-insert go off before org-mode gets a chance to load. – Edgar Aroutiounian Dec 2 '14 at 17:31
  • Well, you can evaluate some elisp both before and after inserting text: before to turn on org-mode and after to call org-mode-restart. – Constantine Dec 2 '14 at 17:35
  • 1
    Any reason not to customize org-startup-indented, or set it locally in your org-mode hook? You could still set the options you want in the file but not really on immediately reading those options. – glucas Dec 2 '14 at 17:37
  • @glucas yay, that worked. While I would have preferred to keep it all in the auto-insert skeleton, I'll take what works now. – Edgar Aroutiounian Dec 2 '14 at 17:43
7

You can use a function for your auto-insert action, and in that function call org-mode-restart.

For example, this works for me:

(defun my/org-template ()
  (insert "#+STARTUP: indent")
  (org-mode-restart))

(define-auto-insert "\\.org$" #'my/org-template)

Use (insert-file FILENAME) to insert the contents of a template file instead of just a string.

That said, the simpler approach (as I commented earlier) would be to customize org-mode with the settings you want, so that you do not need to rely on inserting and re-reading content.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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