1

I understand from here, that I can use dir-locals.el to customize modes, such as given in the example:

      ;; Warn about spaces used for indentation:
      (haskell-mode . ((eval . (highlight-regexp "^ *"))))
      (c-mode . ((c-file-style . "BSD")))
      (java-mode . ((c-file-style . "BSD")))
      ("src/imported"
       . ((nil . ((change-log-default-name . "ChangeLog.local"))))))

However, all of these make 1 change per language-mode. I would like to make multiple changes to the same mode, python-mode, and I think my syntax is only keeping the first one.

What's the right syntax to combine these two variables settings in dir-locals.el?

I have:

;; misc
((python-mode
  (python-shell-buffer-name . "Python[This Project]")))

;; set the local pyvenv ((python-mode . ((pyvenv-activate . "./envs/default") )))

;; find local pylintrc vs global ((python-mode . ((eval . (lambda () (setq flycheck-pylintrc ".pylintrc"))))))

Other refs consulted:

Mittenchops
  • 329
  • 1
  • 9
  • 2
    For each mode you can have an alist. The alist can specify any number of settings. See the example with nil (which stands for any mode) in the Emacs Wiki page you cite. Change nil to python-mode and you have an example of setting multiple things for Python mode. – Drew Nov 10 '20 at 18:46
  • Could you point me to an example? – Mittenchops Dec 23 '20 at 21:22
  • It's like that TV game show where the contestants are given an answer and have to respond with a matching question. – phils Jun 24 '22 at 07:34

2 Answers2

4

The dir-locals file contains an alist of nested alists. This would be the correct form for your example of setting multiple variables for python-mode:

((python-mode . ((python-shell-buffer-name . "Python[This Project]")
                 (pyvenv-activate . "./envs/default")
                 (eval . (lambda ()  (setq flycheck-pylintrc ".pylintrc")))))
 (other-mode . (... ALIST)))
4

This is already answered, but just for another perspective:

If you just want to avoid syntax problems or view correct syntax, you can call add-dir-local-variable. It prompts for a mode, then a variable, then a setting. You can do this twice for the one mode, then open your .dir-locals.el file and view the correct syntax.

martian
  • 548
  • 3
  • 11
  • n.b. This works best since Emacs 27.1, when the command was changed so that it generated the preferred dotted-pair notation. – phils Jun 24 '22 at 11:40