0

When I run realgud for python debugging, with:

M-x realgud:pdb

I see this prompt:

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

I'm using a conda environment installed in ./place/environments/default/, so I'd like to use the python executable at ./place/environments/default/bin/python

This means I have to type out a correction to use a different python:`

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

installed in that directory every time I invoke pdb, which is tedious.

I have multiple projects in

/home/username/work/

So I can't just hard-code /one/, it needs to be configurable---but I'd like something like the following:

  1. Default to using the last python binary I used but otherwise make me type this once.
  2. Multi-step dialog, where the first step chooses a python (and defaults to last time).
  3. Some variable I can set once per project and get picked up
  4. Being able to tab complete here.

What options do I have to reduce the amount I have to type to change the python invoked?

1 Answer 1

1

Realgud:ipdb has a variable that indicate the command-name, is called realdu:pdb-command-name by default is set to "python -m pdb", but it can easily be adapted to use with differents projects (I'm assuming that you are using projectile, if it's not the case, take a look at project.el)

We can assume that the location of the python executable has some similarities between projects (it's in the environment directory in the root project) if it's not the case, Directory-Variables may help you, as you can define this variable in every directory regardless of the project.

So, for the first case, we can use a python-mode-hook and add some logic:

(add-hook 'python-mode-hook
  (lambda ()
    (let* ((conda-python (format "%/environments/default/bin/python -m pdb" (projectile-project-root))))
      (setq-local realgud:pdb-command-name conda-python))
    ))

This hook will ensure that for every file in a project, it will set a different variable, making possible to work with differents projects at the same time, mostly because we are using a buffer-local variable.

When realgud:pdb is launch, it will put the correct projectile base root, and will concat the file name at the end, making the file selection automatic.

For the 2 and 4 request, it is not implemented, but it can be an interesting addition to the realgud project, I really suggest you to contribute it (or open an issue) to the realgud project.

Good luck!

3
  • 1
    This is amazing, thank you! Nov 3, 2020 at 21:28
  • Hmm, this seems to disable my magit, oddly. When I include this n my .dir-locals.el, I get wrong type argument: listp, add-hook Nov 9, 2020 at 16:20
  • 1
    I am combining both of your excellent suggestions poorly and having a bit of trouble, I'll post a new question :) Nov 9, 2020 at 17:12

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.