Extensions to python-mode in emacs

I really like to run and debugging python programs from inside of emacs but I have wanted to see a couple of additional features added to python-mode.el This applies to executing the program as well as running with a symbolic debugger.

py-mode-ext.el is a short bit of emacs lisp which I assert accomplishes the above. I am new to writing elisp so I welcome comments and suggestions.

To use these extensions, py-mode-ext.el is placed in my emacs load path. I have the following code in my .emacs.


(add-hook 'python-mode-hook
       	  '(lambda ()
       		 (define-key py-mode-map "\C-c\C-c" 'py-execute-prog)
       		 (define-key py-mode-map "\C-c\C-g" 'py-call-pdb)
       		 (define-key py-mode-map "\C-c\C-w" 'pychecker)))
(load "py-mode-ext.el")

When the user press one of the above key sequences for py-execute-prog or py-call-pdb, he will first be asked for the initial module.

  1. It first reads from the mini-buffer the name of the initial file to be executed by the interpreter. If no history exists, then the file behind the current buffer is suggested. The user may then substitute any file he wishes as the initial file to be executed by the interpreter. It will be save in a history list.

  2. Next, it reads from the mini-buffer the argument string to be passed to the program being interpreted. Again, if there is a history of arguments, the most recent will be selected. The user may over ride the suggestion. The argument string passed to the program will be saved in a history list.

  3. It next saves all the modified buffers based on a query.

  4. Finally, it invokes python on the initial file or it invokes pdb on the initial file.

If there is a history item for initial modules that will be suggested otherwise the file corresponding to the current buffer is suggested. Change the item if desired and then hit return. The next question to be asked is the argument list for the execution. Again, if there is a history then the most recent argument list will be selected. If you want to change it, go ahead and then hit return. At that point execution or the debugger is initiated.

When the user initiates the command for pychecker, it will check whether any buffers have been changed and ask whether you want any of those saved. Then it will run PyChecker against the file behind the current buffer.

PAGE Home