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?

Amelio Vazquez-Reina
  • 91,494
  • 132
  • 359
  • 564

1 Answers1

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

Amelio Vazquez-Reina
  • 91,494
  • 132
  • 359
  • 564
gavenkoa
  • 45,285
  • 19
  • 251
  • 303
  • 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 documentation – Amelio Vazquez-Reina Feb 07 '12 at 21:07
  • 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... – gavenkoa Feb 08 '12 at 07:16
  • 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-map` – Amelio Vazquez-Reina Feb 08 '12 at 14:20
  • 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. – gavenkoa Feb 08 '12 at 14:29
  • Read about **eval-after-load** http://www.gnu.org/software/emacs/manual/html_node/elisp/Hooks-for-Loading.html – gavenkoa Feb 08 '12 at 14:30
  • Thanks, but what is exactly the `.el` file I need to load for `GUD` to work? I thought GUD was provided natively by Emacs. – Amelio Vazquez-Reina Feb 08 '12 at 14:33
  • @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. – gavenkoa Feb 09 '12 at 08:46
  • Thanks @gavenkoa. Which file do I have to load for GUD? – Amelio Vazquez-Reina Feb 09 '12 at 13:13
  • @intrpc Load debugger in Emacs and examine content of **load-history** variable (to do this type **C-h v load-history RET**) – gavenkoa Feb 09 '12 at 13:42
  • 1
    @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**. – gavenkoa Feb 09 '12 at 13:51