0

I've been using emacs for 20+ years, but I need to ask for help with some of the more interesting features.

In my software work, I like to set different themes for widely different projects in the same language. In other words, Project X gets the default white background (I use precompiled emacs for Windows from http://ftpmirror.gnu.org/emacs/windows), but I like Project Y to have the manoj-dark theme so I can separate them mentally. Both projects have the same file extensions and major modes. They are in different file trees. In Eclipse, I can set a unique background color in each project file, but emacs doesn't work that way.

This fails:

'-*- Mode: Spin; tab-width: 2; indent-tabs-mode: nil; (eval(load-theme 'manoj-dark t));  -*-

telling me "Malformed mode-line". Likewise with progn instead of eval, with and without the ';', or with just the inner "(load-theme 'manoj-dark t)". That last form works in .emacs, but I don't always want it. It does not work in a .dir-locals.el file.

"theme: 'manoj-dark" also fails in the -*- line, with an "unsafe" message

I've tried setting up a .emacs file in the project folder - emacs ignored it as it ignored .dir-locals.el. I see there is a "project.el" but it looks like a lot more than I am bargaining for.

What is the secret sauce for loading a certain theme or doing other customization for files in some folders but not others, using generic gnu emacs for windows? Thank you.

1 Answer 1

1

I apologize if anyone was working on an answer. Here's what I figured out:

.dir-locals.el is not meant to execute lisp code as much as input a list of values that override default variable settings. You have to trick it:

((nil(eval(lambda()(load-theme 'manoj-dark t)))))

On first run you will get a "risky variable" warning. Press '!' to clear the choice and have emacs store your decision.

See also: https://stackoverflow.com/questions/63578123/setting-a-mode-for-a-particular-file-using-dir-locals-el

Remember permission to execute "risky" local variables

3
  • I think you are over-complicating things a bit: instead of evaluating a call to a lambda form, you can just evaluate whatever the lambda form calls. Something like this: ((nil (eval (load-theme 'manoj-dark t)))) is equivalent, but simpler (although I prefer to write it using dotted-pair notation: ((nil . ((eval . ((load-theme 'manoj-dark t)))))) - it looks more complicated, but it makes it easier to add more entries - see the manual).
    – NickD
    Commented Oct 7 at 11:46
  • @NickD: thanks for contributing, but that fails with "File local-variables error: (invalid-function (load-theme 'manoj-dark t))". The lambda was necessary to make it work. Commented Oct 7 at 12:10
  • Sorry, I messed it up: in dotted-pair notation, the correct form is ((nil . ((eval . (load-theme 'manoj-dark t))))); in list notation, it is ((nil (eval load-theme 'manoj-dark t))).
    – NickD
    Commented Oct 7 at 12:49

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.