Adam Hupp


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:

  1. 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.

  2. 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)))
     
  3. 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.