Of course, having read everywhere how difficult Emacs was - i did the lazy thing , spent an hour or so learning, how to start/stop emacs, understand what the status line was, find what "point" meant (it means glorified cursor), realise that "C" in Emacs land means Control, Alt/Meta key is basically Esc on all modern O.S's and keyboards and wallah i was ready to do Python.
For a complete newbie to Emacs and Python - attempting to map my experiences with Eclipse+Java to Emacs+Python turned out to be - shall we say - an "interesting" experience. There is a surfiet of documentation out there on Emacs explaining all sorts of deep-fu but time and again i found myself getting lost in it. I didn't want to learn Elisp, i didn't want my editor to read news, send emails, work as a directory-browser, function as a chat client or talk back to me. As a start, I just wanted to write Python and hopefully have some of the features that i am used to in Eclipse to be present. Additionally, not knowing the Emacs terminology meant i didn't know how to ask questions the "Emacs way" resulting in hair-pulling,teeth-gnashing and sleepless nights filled with console-based non-gui text dreams. There just didn't seem to be a SuperSimple Task Based Startup Guide for Complete Newbies.
So i decided to write one , here is my SuperSimple Task Based Startup Guide for Complete Newbs:
Task 0: Get yourself Emacs 22.x, the current production version, anything other than that and the instructions below may not work. Note this is GNU Emacs 22.x not XEmacs.
Task 1: I want Python syntax highlighting.
Emacs comes with a built-in Python highlighter. (These are called as modes in Emacs). The requisite file for that is python.el. This is developed by the FSF. There is a competing mode python-mode.el developed by the Python community. Stick with the default in-built one.
Task 2: I want to edit and run my Python program.
Download emacs.py from here: http://www.loveshack.ukfsn.org/emacs/emacs.py. Copy this file onto your
Task 3: I want auto-indentation in my program.
Whitespace being significant in Python, this was important to me. I wanted my editor to automatically indent my statements , so for example if i am writing a function i wanted the next line to be properly indented without me having to press "tab"
(add-hook 'python-mode-hook '(lambda () (define-key python-mode-map "\C-m" 'newline-and-indent)))
Save the file and restart Emacs , you should now have auto-indentation in Python.
Task 4: I want listing/auto-completion of functions in Python modules.
Using pydoc and the excellent Python documentation i could see a listing of the builtin modules present in Python and the functions they provided. What i wanted was to have a listing of all the functions a module contained within my editor.This is where things get interesting. Being used to Eclipse+Java this is very simple. Type System.out. and press "tab"
- Installs rope,ropemode,ropemacs . http://rope.sourceforge.net/ropemacs.html
- Installs pymacs. http://pymacs.progiciels-bpi.ca/
- Installs yasnippet. http://code.google.com/p/yasnippet/
If everything goes well , pressing "tab"
Task 5: I want inline documentation for modules and the functions they contain.
Now that we have function completions , i wanted to have inline documentation for those functions. Congratulations. If you have completed Step 3 properly then you have already finished Task 4. If you are like me and didn't actually read through the documentation of the rope library that you installed in the previous step then you will not know that rope can provide Python documentation as well . How-to invoke it : position point on a module name, press C-c d and you should get documentation for that module within your editor.
Task 6: Inline code-checkers (pylint,flymake,pyflakes,pychecker - i don't know)
Task 7: Code browser (ala Outline view in Eclipse)
I hope to accomplish Task 6 and 7 shortly.
An absolute godsend is C-c C-h within your Python mode , it invokes keyboard help for your particular major mode.Fantastic.