I was reading about dir-locals and wanted to set up per project settings. However whatever I try results in a malformed function. Why is this ?

.dir-locals.el:4:1:Warning: ‘(php-mode (php-executable . /usr/bin/php))’ is a
malformed function

So I tried this as the most basic example I could think of, and even this raises an error.

  (php-executable . /usr/bin/php)))

So what am i doing wrong? I edit the file and then compile it to check things are working and checked multiple examples online and they all seem to use this format.

From the answers below this is an example I wanted to make work, the above was just a simpler test.

((nil . ((pony-settings (make-pony-project :python "/docker:root@app_django_1:/usr/local/bin/python" :pythonpath "/app" :settings "local_settings_file" :appsdir "/app") ))))

This is where my issues stemmed from, I can switch to a file and I hit an error which is what made me try and compile the code so I could test quickly.

eval: Invalid function: (make-pony-project :python "/docker:root@app_django_1:/usr/local/bin/python" :pythonpath "/app" :settings "local_settings_file" :appsdir "/app")

Perhaps this should be another question now, but in away this is still an issue I am getting an error but cant modify and apply changes quickly to see if its valid. Anyone have any idea on the above error ?

  • I don't have answer for your question. But if you use M-x add-dir-local-variable then you don't need to worry about the format. Besides, I guess php-executable requires string type as its value, so you should use "/usr/bin/php" instead.
    – xuchunyang
    Commented Feb 28, 2018 at 10:34
  • funny you should say that the above was generated from add-dir-local-variable then I compiled it to check it was valid which is when i hit the issue, quoting results in the same error.
    – Oly
    Commented Feb 28, 2018 at 10:36
  • 1
    Oops, you can't byte compile .dir-locals.el since it is not valid Emacs Lisp code.
    – xuchunyang
    Commented Feb 28, 2018 at 10:53
  • 1
    Test it by opening a file under the directory it’s in in php-mode, and do M-: php-executable, after having changed the path to be a string as xuchunyang said.
    – InHarmsWay
    Commented Feb 28, 2018 at 11:48
  • 1
    Possible duplicate of Can't get directory local variables to work - Debugger encountered Lisp error
    – phils
    Commented Feb 28, 2018 at 20:16

1 Answer 1


For the original question (repeating my comment):

As others have pointed out, that value needs to be a string: "/usr/bin/php". You need to manually type the quotes because add-dir-local-variable has no idea what type of value is required/valid for any given variable, so string values need to be made explicit. (Despite looking like a file path, the value you'd actually entered was a symbol rather than a string.)

For the revised/new question:

((nil . ((pony-settings (make-pony-project ...

is the same as:

((nil . ((pony-settings . ((make-pony-project ...

So you're setting pony-settings to ((make-pony-project ...))

And it sounds like that form is then evaluated like so:

((make-pony-project ...))


eval: Invalid function: (make-pony-project ...)

Because while make-pony-project may be the name of a function, the form (make-pony-project ...) is not the name of a function.

So in summary, I suspect you're missing a dot. Try:

((nil . ((pony-settings . (make-pony-project ...

See also the "Notation" heading at https://www.emacswiki.org/emacs/DirectoryVariables#toc1

  • Thats is a great answer, but i still see the same invalid function, the code i was using was directly from the pony docs here github.com/davidmiller/pony-mode, possible they are wrong I guess will try a few more things in case i am doing something wrong still
    – Oly
    Commented Mar 1, 2018 at 21:25
  • Thank you pointed me in the correct direction, the answer seems to be the first dot does should not be there the second should, found another page with docs with the correct info here deadpansincerity.com/docs/pony/configuration.html if you want to update i will accept ass a working solution :)
    – Oly
    Commented Mar 1, 2018 at 21:39
  • The structure of the form shown in that linked page is equal to the one in my answer. I suspect that you have again been tripped up by dotted pair notation (or lack thereof), and did not test with the correct dots and parentheses for the notation you were using.
    – phils
    Commented Mar 2, 2018 at 10:22
  • i.e. ((nil (pony-settings ...))) and ((nil . ((pony-settings ...)))) are the same. It's valuable to get familiar with those notation differences/equivalences. (Again, see that Emacs Wiki link for more information.)
    – phils
    Commented Mar 2, 2018 at 10:28
  • FWIW I feel that dotted-pair notation makes the .dir-locals.el format far more readable (bearing in mind that it's generally representing lists of var/value pairs), and that it's unfortunate that add-dir-local-variable does not generate that format. Personally I would recommend writing the file manually using dotted-pair notation.
    – phils
    Commented Mar 2, 2018 at 10:31

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.