Emacs is a great text-editor and highly extensible. I saw people on Youtube controlling their espresso machine with Emacs. So it should be possible to do some Python programming with this Swiss army-knife. The goals are syntax highlighting, code-completion, syntax-checking and code short-cuts. I'm using my beloved Fedora and Emacs 23.2. Usually, Emacs is already part of every Linux standard installation otherwise you'll find it in your package manager for sure!
I'm using the python-mode.el created by the python-community.
cd ~/.emacs.d curl http://launchpadlibrarian.net/21781107/python-mode.el
(setq auto-mode-alist (cons '("\\.py$" . python-mode) auto-mode-alist)) (setq interpreter-mode-alist (cons '("python" . python-mode) interpreter-mode-alist)) (autoload 'python-mode "python-mode" "Python editing mode." t) (global-font-lock-mode t) (setq font-lock-maximum-decoration t) (setq-default indent-tabs-mode nil) (setq default-tab-width 4)
Next we have to install some more software. Some of this software is written in Python (such a surprise!) and the probably easiest way to install this kind of software is by using python-pip. So we need to install python-pip first:
yum install python-pip
Now we can move on to install Ropemacs. This Python refactoring library will offer code completion among other things.
python-pip install http://pymacs.progiciels-bpi.ca/archives/Pymacs.tar.gz python-pip install http://bitbucket.org/agr/ropemacs/get/tip.tar.gz
cd ~/.emacs.d curl http://pymacs.progiciels-bpi.ca/archives/Pymacs.tar.gz | tar zx cd Pymacs-0.23 make emacs -batch -eval '(byte-compile-file "~/.emacs.d/Pymacs-0.23/pymacs.el")'
(add-to-list 'load-path "~/.emacs.d/Pymacs-0.23") (require 'pymacs) (pymacs-load "ropemacs" "rope-") (setq ropemacs-enable-autoimport t)
Next we are using auto-complete mode which offers nice code completion using drop-down menus which works perfectly together with Ropemacs:
cd ~/.emacs.d curl http://cx4a.org/pub/auto-complete/auto-complete-1.3.tar.bz2 | tar jx cd auto-complete-1.3 make byte-compile
(add-to-list 'load-path "~/.emacs.d/auto-complete-1.3") (require 'auto-complete-config) (add-to-list 'ac-dictionary-directories "~/.emacs.d/vendor/auto-complete-1.2/dict") (ac-config-default)
Next step is installing the Yasnippet (Yet another snippet) template system which offers nice code templates which helps you with writing code faster.
(require 'yasnippet-bundle)
Last step is the on the fly code and syntax checker. We use flymake which already comes with Emacs and extend it by Pyflakes and pep8 which is a syntax style checker.
python-pip install pyflakes pep8
(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)
#!/bin/bash pyflakes "$1" pep8 --ignore=E221,E701,E202 --repeat "$1" true
That's it. Depending on how experienced you are the entire procedure takes you 20 minutes and at the end you get a perfect Emacs Python IDE!
Reference: www.saltycrane.com