There are two Python modes:
python-mode.el created by
the Python community and
created by the Emacs
community (David Love). The first version of
was included in Emacs 22 and an improved version was included in Emacs 23.
I am currently using the default
python.el included with Emacs 23.
Below are some useful commands. For a complete list, open a Python file and
M-x apropos RET python RET
(setq-default indent-tabs-mode nil) ; use only spaces and no tabs (setq default-tab-width 4)
Ropemacs is an Emacs plugin to use Rope, a powerful Python refactoring library. It supports code completion, renaming, and other refactoring. Pymacs is a prerequisite for Ropemacs. Below are some useful commands. For more information, look in the Rope menu.
C-c r r
Note: pip install does not work with v0.25. Need to use `make install`
$ curl -L https://github.com/pinard/Pymacs/tarball/v0.24-beta2 | tar zx $ cd pinard-Pymacs-016b0bc $ make $ mkdir -p ~/.emacs.d/vendor/pymacs-0.24-beta2 $ cp pymacs.el ~/.emacs.d/vendor/pymacs-0.24-beta2/pymacs.el $ emacs -batch -eval '(byte-compile-file "~/.emacs.d/vendor/pymacs-0.24-beta2/pymacs.el")'
$ sudo pip install https://github.com/pinard/Pymacs/tarball/v0.24-beta2
$ sudo pip install http://bitbucket.org/agr/ropemacs/get/tip.tar.gz
(add-to-list 'load-path "~/.emacs.d/vendor/pymacs-0.24-beta2") (require 'pymacs) (pymacs-load "ropemacs" "rope-") (setq ropemacs-enable-autoimport t)
Auto Complete Mode is an extension to make Emacs auto-completion nicer. It creates a drowpdown in the middle of your text. It can use Ropemacs as a backend.
$ cd ~/.emacs.d/vendor $ curl http://cx4a.org/pub/auto-complete/auto-complete-1.2.tar.bz2 | tar jx $ cd auto-complete-1.2 $ make byte-compile
(add-to-list 'load-path "~/.emacs.d/vendor/auto-complete-1.2") (require 'auto-complete-config) (add-to-list 'ac-dictionary-directories "~/.emacs.d/vendor/auto-complete-1.2/dict") (ac-config-default)
flymake-cursor.elis not required, but it makes flymake less obtrusive.
$ sudo pip install pyflakes pep8
flymake-cursor.eland save it as
(add-to-list 'load-path "~/.emacs.d/vendor") (add-hook 'find-file-hook 'flymake-find-file-hook) (when (load "flymake" t) (defun flymake-pyflakes-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 "pycheckers" (list local-file)))) (add-to-list 'flymake-allowed-file-name-masks '("\\.py\\'" flymake-pyflakes-init))) (load-library "flymake-cursor") (global-set-key [f10] 'flymake-goto-prev-error) (global-set-key [f11] 'flymake-goto-next-error)
pycheckers, make it executable, and put it on your PATH
#!/bin/bash pyflakes "$1" pep8 --ignore=E221,E701,E202 --repeat "$1" true
$ sudo pip install pyflakes
(setq python-check-command "pyflakes")
$ wget http://ourcomments.org/Emacs/DL/elisp/nxhtml/zip/nxhtml-2.08-100425.zip $ unzip nxhtml-2.08-100425.zip
(load "~/.emacs.d/nxhtml/autostart.el") (setq mumamo-background-colors nil) (add-to-list 'auto-mode-alist '("\\.html$" . django-html-mumamo-mode))
This has been the best written (and up to date using current packages!) page I've seen so far for ropemacs, python, and emacs.
Thanks so much.
Very concise and helpful to take python and emacs to the next level, thank you. Just a note too that Auto Complete mode is now at v1.3 instead of 1.2.
Works great on my system, except for two things.
Every time I edit a C-file, a warning pops up that flymake is disabled. I'm guessing either load flymake only for python files, or disable warnings.
Both warnings and errors use the flymake-errline face. Since the messages most often contain "W:" and "E:", it should be possible to fix this somewhere.
I'll dig more into this, but I posted in case you already have the answers.
Thanks for the setup :)
(defun anr78/flymake-hook () ; your flymake-stuff here )
(add-hook 'python-mode-hook 'anr78/flymake-hook)
Anders: Thanks for your comments. I will have to look into #2. I would like to fix this also. Let me know if you figure it out.
Using pylint instead of pyflakes, I have the colors working. The pylint-checker looks like:
#!/usr/bin/env python import re import sys from subprocess import * p = Popen("pylint --rcfile=pylint.rc -f parseable -r n --disable=W0613,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()
Finally I did python autocompletion as I wanted!! Thanks a lot!
Anders: Since the option --disable doesn't seem to exist anymore I switched the command line to
p = Popen("pylint --rcfile=pylint.rc -f parseable -r n --disable-msg=W0613 --disable-msg-cat=C,R %s" % sys.argv, shell = True, stdout = PIPE).stdout
Hi, thanks for the code. But one problem is my yasnippet doesn't work...
Thanks a lot. Getting lots of troubles with the other manuals (I'm an Emacs newbie). This guide is concise, easy to follow and works like charm.
Thanks for the tutorial.
i am having the following error when starting emacs:
"error: Pymacs helper did not start within 30 seconds"
It seems i forgot something... Any help would be appreciated.
i follow your steps up to yasnippet.
This was really great. Unfortunately I've now moved to python 3 so ... yuck. Still, any advice on what can be salvaged? Found pymacs and rope for py3k but no ropemode, ropemacs. Autocomplete for py3k apparently here http://www.rwdev.eu/articles/emacspyeng.