I tried putting a local file variable in an org mode file:

# -*- mode:org; coding:utf-8; org-duration-format: h:mm; -*-

but when I open this file the variable has the original value and not the one I set. Also file-local-variables-alist is nil.

I tried with only:# -*- org-duration-format: h:mm; -*-, with another variables and also with a plain text file, but never the file local variables made any effect.

The value of enable-local-variables is :safe, as default.

  • 1
    Is that the very first line in the file? No empty (or other) lines before it. The only time when it is allowed to be the second line in the file is when the first line is a shebang line (#! /bin/bash or similar).
    – NickD
    Sep 12, 2021 at 18:37
  • Yes it is the very first line
    – DPD-
    Sep 12, 2021 at 19:45
  • 1
    Have you tried setting enable-local-variables to t?
    – NickD
    Sep 12, 2021 at 19:54
  • mhm with enable-local-variables as t it complains that org-duration-format is not safe, so indeed this has to be the problem. I thought it was a safe variable.
    – DPD-
    Sep 12, 2021 at 20:10
  • 1
    Do C-h i g (elisp) File Local Variables. Basically, a variable that has a safe-local-variable property is safe. E.g. (get 'fill-column 'safe-local-variable) returns integerp - a predicate which can test for legal values.
    – NickD
    Sep 12, 2021 at 20:25

1 Answer 1


As explained by @NickD, org-duration-format isn't a safe variable:

(get 'org-duration-format 'safe-local-variable) ; nil

So there are two ways:

  1. Set enable-local-variables to t for getting asked if to trust that variable when the file is opened:
(setq enable-local-variables t)
  1. Push org-duration-format into safe-local-variable-values:
(add-to-list 'safe-local-variable-values '(org-duration-format . h:mm))
  • 1
    Or you can set enable-local-variables to t and when you are asked, then type ! which does the equivalent of your way #2 and saves the result in your custom file, so that it is remembered for the future - note that only the combination of (variable, value) that you set is remembered: if you change the value then it's going to ask you again. Once you have done that, then you can set enable-local-variables to :safe but if you try with a different variable that has not been saved, you are back at the beginning and you'll have to do the whole thing again for the new variable.
    – NickD
    Sep 13, 2021 at 3:50
  • 1
    Or you can add a safe-local-variable property to the variable with a predicate to check the legality of the value, the way emacs does it for the common safe variables - see the function safe-local-variable-p in files.el for how emacs determines whether a variable is safe.
    – NickD
    Sep 13, 2021 at 3:54

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.