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.
- I want to be able to conveniently supply arguments to the
program under test.
-
There are times when I forget to save the buffers that I am
editing, so I would like to have emacs inquire if I want them saved
and respond to my reply.
-
Frequently, my programs involve more than one module and here
python-mode foils me because it saves the current buffer as a
temporary file in a temporary directory with a manufactured,
unique name. There is no way that another module of the program
will be found. I therefore want any changed modules saved and want to
be able to specify the main module to be entered.
-
I would like to have history capability to remember initial
modules and argument lists used in the Emacs session.
- Since python-mode allows me to execute a program with a simple key
sequence, I then want to execute the program with the python debugger
as easily.
- I am a fan of PyChecker, so I want to be able to easily run that
program from Emacs and be able to jump to source lines corresponding
to PyChecker messages.
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.
-
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.
-
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.
-
It next saves all the modified buffers based on a query.
-
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