A Few Things About Python and Emacs 22
This week I upgraded to the not-quite-released emacs 22. One of the big changes (for me at least) is the new default implementation of the python major mode, python.el. Some observations:
python.el does not seem to have the same kinds of problems with syntax highlighting of triple-quoted strings that python-mode did. This alone is worth the upgrade in my mind.
In python-mode.el the RET key was bound to py-newline-and-indent. When you typed ‘if condition:RET’ this would automatically indent the next line within the ‘if’ block. In python.el this functionality is bound to “C-j” instead of RET. You can get the old behavior (which I prefer) by putting this in your .emacs:
(add-hook 'python-mode-hook (lambda () (define-key python-mode-map "\C-m" 'newline-and-indent)))Thanks to johan for the suggestion to do this in a hook.
Turn on transient-mark-mode. This is necessary for certain features like region (un)comment region (M-;) to work. In emacs 21 transient-mark-mode didn’t play well with python-mode, (e.g. py-mark-block didn’t work) so I turned it off. That doesn’t seem to be a problem anymore.
I’m sure there are many more changes but those are what I’ve noticed after bit of use. Overall I’m happy with the new implementation.
My next task will be to get Guido’s xreload to work from emacs.
May 12th, 2007 at 4:50 am
I’m running a very recent cvs emacs 22 on windows. When I add
(define-key python-mode-map “C-m” ‘newline-and-indent)
to my init.el (same as .emacs) I get this message on emacs startup:
An error has occurred while loading `c:/Documents and Settings/johan/Application Data/.emacs.d/init.el’:
Symbol’s value as variable is void: python-mode-map
Do you know anything about what this means?
May 14th, 2007 at 11:36 am
You will need to put
before the call to define-key.
-Adam
May 14th, 2007 at 3:45 pm
Thanks.
A little further experimentation shows that you don’t need to require python but instead can do
(add-hook ‘python-mode-hook
‘(lambda ()
(define-key python-mode-map “C-m” ‘newline-and-indent)))
I think this will speed up things when use emacs for other things than python stuff since you dont need to load python mode on startup.