Various ways to configure your emacs that you might find useful.
See emacs_python_mode for a good summary.
rst mode automates many important ReST tasks like building and updateing table-of-contents, and promoting or demoting section headings. Here is the basic .emacs configuration:
(require 'rst) (setq auto-mode-alist (append '(("\\.txt$" . rst-mode) ("\\.rst$" . rst-mode) ("\\.rest$" . rst-mode)) auto-mode-alist))
Some helpful functions:
C-c TAB - rst-toc-insert Insert table of contents at point C-c C-u - rst-toc-update Update the table of contents at point C-c C-l rst-shift-region-left Shift region to the left C-c C-r rst-shift-region-right Shift region to the right
On - for example - Ubuntu, the default M-x rst-compile command uses rst2html.py whereas the command installed is rst2html. Time for a symlink.
This useful mode for writing doctests (doctest-mode.el) came with my python-mode package in Ubuntu. Or see doctest-mode project page.
Code checkers within emacs can be useful to check code for errors, unused variables, imports and so on. Alternatives are pychecker, pylint and pyflakes. Note that rope (below) also does some code checking. pylint and pyflakes work best with emacs flymake, which usually comes with emacs.
This appears to be plumbed in with python-mode, just do M-x py-pychecker-run. If you try this, and pychecker is not installed, you will get an error. You can install it using your package manager (pychecker in Ubuntu) or from the pychecker webpage.
#!/usr/bin/env python import re import sys from subprocess import * p = Popen("pylint -f parseable -r n --disable-msg-cat=C,R %s" % sys.argv, shell = True, stdout = PIPE).stdout for line in p.readlines(): match = re.search("\\[([WE])(, (.+?))?\\]", line) if match: kind = match.group(1) func = match.group(3) if kind == "W": msg = "Warning" else: msg = "Error" if func: line = re.sub("\\[([WE])(, (.+?))?\\]", "%s (%s):" % (msg, func), line) else: line = re.sub("\\[([WE])?\\]", "%s:" % msg, line) print line, p.close()
as epylint somewhere on your system path, and test that epylint somepyfile.py works.
Add this to your .emacs file:
;; code checking via flymake ;; set code checker here from "epylint", "pyflakes" (setq pycodechecker "pyflakes") (when (load "flymake" t) (defun flymake-pycodecheck-init () (let* ((temp-file (flymake-init-create-temp-buffer-copy 'flymake-create-temp-inplace)) (local-file (file-relative-name temp-file (file-name-directory buffer-file-name)))) (list pycodechecker (list local-file)))) (add-to-list 'flymake-allowed-file-name-masks '("\\.py\\'" flymake-pycodecheck-init)))
You may also consider using the flymake-cursor functions, see the pyflakes section of the emacs_python_mode page for details.
rope is a python refactoring library, and ropemacs is an emacs interface to it, that uses pymacs. pymacs is an interface between emacs lisp and python that allows emacs to call into python and python to call back into emacs.
You may need to make sure your gnome etc sessions have the correct python path settings - for example settings in .gnomerc as well as the usual .bashrc.
Make sure you can import ropemacs from python (which should drop you into something lispey). Add these lines somewhere in your .emacs file:
(require 'pymacs) (pymacs-load "ropemacs" "rope-")
and restart emacs. When you open a python file, you should have a rope menu. Note C-c g - the excellent goto-definition command.
You may well find it useful to be able to switch fluidly between python mode, doctest mode, ReST mode and flymake mode (pylint). You can attach these modes to function keys in your .emacs file with something like:
(global-set-key [f8] 'flymake-mode) (global-set-key [f9] 'python-mode) (global-set-key [f10] 'doctest-mode) (global-set-key [f11] 'rst-mode)