I'm trying to use directory local variables so my realgud:pdb invocation can be:

Run pdb (like this): /home/username/work/place/environments/default/bin/python -m pdb /home/username/work/place/scratch.py

Instead of :

Run pdb (like this): python -m pdb /home/username/work/place/scratch.py

as suggested here.

However, in order to transform the suggestion there to be compatible with .dir-locals.el, I understand I need to use nil and eval per this answer.

So I am left with this:

;; .dir-locals.el
;; set the test runner
((nil . ((eval . (add-hook 'python-mode-hook
  (function (lambda ()
              (let* ((conda-python (format "%/envs/default/bin/python -m pdb" (projectile-project-root))))
                (setq-local realgud:pdb-command-name conda-python))

This doesn't complain or fail, except for asking me whether I trust the eval parameters. However, it doesn't seem to work, as my M-x realgud:pdb invocation is still:

Run pdb (like this): python -m pdb /home/username/work/place/scratch.py

My init.el contains:

 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(column-number-mode t)
 '(conda-anaconda-home (expand-file-name "~/anaconda3"))
 '(elpy-test-pytest-runner-command '("py.test"))
 '(elpy-test-runner 'elpy-test-pytest-runner)

...which I don't think interferes but include for completeness.

What should I change so that my .dir-local.el picks up the correct test runner for pdb? Essentially, I am trying to combine the suggestion of the linked answer to modify my init.el, but in a per directory basis, using .dir-locals.el, as my projects have different environment names and I'm stuck having one per project.

  • For instance, this currently gives me: let*: Invalid format operation %/ Commented Nov 9, 2020 at 18:41

1 Answer 1


I tried instead of setting a hook, just eval the variable with the python-mode association and seems to work fine, here is the code:

((python-mode . ((eval .
           (setq-local realgud:pdb-command-name (concat
                             "envs/default/bin/python -m pdb"))))))

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.