Emacs python-mode: Keyboard shortcuts for pdb step-by-step debugging
Asked Answered
S

1

6

I was wondering if there is a way to associate:

  • n RET (next)
  • p RET (previous)
  • c RET (continue)
  • C-x SPC RET (set/clear breakpoint)

with function keys F1-F12 or other keyboard shortcuts. The idea is to emulate the keyboard shortcuts that other IDEs have for debugging (e.g. Visual Studio, MATLAB, etc.).

Is this already supported by python-mode? Are there any Emacs modes that can be used to complement python-mode for debugging purposes?

Stent answered 7/2, 2012 at 14:53 Comment(0)
E
4

You always can define own key-bindings in Emacs. Firstly type C-h m to see help on mode in pdb buffer (which start by M-x pdb).

Next bind any keyboard combination:

(require 'gud)                                                                                                                                                
(define-key gud-mode-map '[f11] 'gud-step)                                                                                                                    
(define-key gud-mode-map '[f10] 'gud-next)                                                                                                                    
(define-key gud-mode-map '[f5] 'gud-cont)                                                                                                                     
(define-key gud-mode-map '[f12] 'gud-break) 

Read Emacs manual about build-in interface to debuger (type C-h i g (emacs) Debuggers RET) or online:

http://www.gnu.org/software/emacs/manual/html_node/emacs/Debuggers.html

Edibles answered 7/2, 2012 at 15:58 Comment(10)
Thanks! Do you know how I can do exactly this also for C-x SPC RET (i.e. add/remove breakpoint)? I didn't see the name of the command in the GUD documentationStent
You must enter to gud debugging session and then when you type C-h k ANY-KEY-SEQUENSE you get help on command and can copy its name to Elisp script... For C-x SPC RET you must stay in Python file buffer...Edibles
I added those the two lines in your answer to my .emacs file, right after loading python-mode (the latest version, i.e. 6.0.4), but when I start Emacs I get the error: Symbol's value as variable is void: gud-mode-mapStent
To resove your problem you must use (eval-after-load "FILE.el" BODY) or (require "FILE"). gud-mode-map does not defined until you load gud library.Edibles
Read about eval-after-load gnu.org/software/emacs/manual/html_node/elisp/…Edibles
Thanks, but what is exactly the .el file I need to load for GUD to work? I thought GUD was provided natively by Emacs.Stent
@intrpc You correct that GUD come with Emacs. But Emacs come with 1400 ".el" files and loading all of them take a long time. So loaded only small portion of required. To resolve dependencies Emacs have require, load-library funcs. If you want function from my.el you first wrote (require 'my) or (require "my") or (load-library "~/path/to/my.el"). Note that load-path variable take in account.Edibles
Thanks @gavenkoa. Which file do I have to load for GUD?Stent
@intrpc Load debugger in Emacs and examine content of load-history variable (to do this type C-h v load-history RET)Edibles
@intrpc But the best method is to type C-h k KBD-SEQUENCE. You get help on function which called by Emacs when you type KBD-SEQUENCE. In "Help buffer" present link to source file where this function defined. In your case this seems to be (require 'gud). This tequenches always work but for gud-next/gud-finish no as they defined through defalias.Edibles

© 2022 - 2024 — McMap. All rights reserved.