My initial goal was to set up Emacs, in the simplest way possible, as a Python development environment that offers basic code browsing and code completion.
This might not be the brightest way to get the job done, and I am open to suggestions, but for now this works just fine for me.
- for code browsing:
- for simple code completion:
OSes and SW versions
The steps described below were tested successfully on Mac OS X 10.6.8 and Ubuntu GNU Linux 12.04 64 bit with GNU Emacs 23.1.1 and cedet-1.0pre7, ecb-2.40 and auto-complete-1.3.1.
This section is programming/scripting language independent (works with Python, Tcl, Lisp and C, at the least).
ECB, needs CEDET >= 1.0pre7.
(If you are using an Emacs release newer that 23.2, CEDET is already included. Check the Emacs Wiki on “How to enable the CEDET tools which were merged with Emacs”.
Haven’t tried it since I decided to use Emacs 23.1.)
CEDET is a very powerful development environment tool collection, but here, it is only used as a requirement for ECB. This means that we only need to add one line to our .emacs file:
Here is the code browsing section of my .emacs:
(add-to-list ‘load-path “~/ecb-snap”)
(setq stack-trace-on-error nil) ;;don’t popup Backtrace window
(setq ecb-tip-of-the-day nil)
(setq ecb-auto-activate t)
(setq ecb-layout-name “left6″)
(setq ecb-options-version “2.40″)
(setq ecb-primary-secondary-mouse-buttons (quote mouse-1–mouse-2))
(setq ecb-source-path (quote (“~/”)))
Restart Emacs after modifying the init file, and this is what it should look like:
Some default key bindings:
- C-c . r – refresh the methods buffer
- C-c . g m – go to methods window
- C-c . g 1 - go to edit buffer
For more info and configuration options check the ECB menu entry or the docs.
Auto Complete Mode
Set up as below, Auto Complete generates completion candidates based on a dictionary and on words entered by the user in the present session (in the form of code or comments).
Check the manual for more info.
“It is a plugin for Auto Complete (in Emacs) which provides a quick, simple completion source for available python symbols.”
Check this link for setup and usage.
The code completion section of my .emacs:
(add-to-list ‘load-path “~/.emacs.d/”)
(add-to-list ‘ac-dictionary-directories “/Users/bogdan/.emacs.d/ac-dict”)
- Great source of nice ideas: http://pedrokroger.net/2010/07/configuring-emacs-as-a-python-ide-2/
- “the best collection of emacs extensions ever” ? - https://github.com/gabrielelanaro/emacs-for-python/blob/master/README.org
- Check Python section in Emacs Wiki http://www.emacswiki.org/emacs/?action=browse;oldid=PythonMode;id=PythonProgrammingInEmacs
- Python quick help (displays docstring popup for the highlighted option while navigating the completion popup – by default auto-complete (?) does something similar for Lisp).
- Key binding for docstring display (e.g. C-c d Display doc string – see “init_python.el” and “How to use” sections here).
- Explore code completion and docstring display with rope.
- Syntax checking on the fly (look here for ideas and configuring example).
- Have a look here for more ideas (semantic, yasnippet, etc.).
- Revision control integration.