I would like to have different start up folding in org mode for different directories. is this possible?

I have this in my .dir-locals.el

((org-mode . ((org-startup-folded . showeverything))))

It sets but has no effect when i open a file in that dir.

  • I think that's because buffer-local variables are set after the mode function has finished. The mode function (org-mode in this case) sets the initial visibility according to the global value and then buffer-local variables get their value, so setting org-startup-folded as a file local or dir local variable is ineffective. AFAICT, they are set after the mode hooks has run, so mode hook solutions are ineffective as well. Using an idle timer as in the answer below seems like the only possibility to me.
    – NickD
    Jul 6 at 21:20

2 Answers 2


I see the same behaviour ...

The following snippet helps. I see a flicker even for very small files.

(add-hook 'org-mode-hook
      (defun my-org-mode-hook ()
        ;; Simulate C-u C-u TAB.
        ;; See (info "(org) Global and local cycling")
        (run-with-idle-timer 0 nil 'org-set-startup-visibility))

If the flicker bothers you, instead of installing the above hook, you can just do C-u C-u TAB after visiting the org file.


Do this

 (defun my-org-mode-hook-vmnfgjk0eij0 ()
   (add-hook 'hack-local-variables-hook
             #'org-set-startup-visibility t t)))

This suggestion is based on how outline.el handles file-local-variables-alist

Btw, if you want to showeverything, do M-x visible-mode.

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.