We love designing and developing websites, but what really drives us is solving problems and cultivating strong relationships with our clients
Django emacs setup
By : thejaswi
My colleague Javed had written a fantastic article a short while back on "Seven reasons why you should switch to Vim" and as an emacs user I thought I should share my setup too. One of the coolest things at Agiliq is that we are free to use the development tools of our choice. As a case to explain the point, everyone at agiliq uses a different editor and if someday a flame war would escalate to the third world war, I assure you it would start from Agiliq ;-)
Though I have been using emacs for more than two years now, I still am an amateur. In this post, I am not going to exhort you to switch to emacs but explain my setup.
If you are planning to give emacs a try, I would suggest you start with the inbuilt emacs tutorial (C-h t). After you've gone through the tutorial, start using emacs while noting your most repetitive actions. Later, bind these repetitive actions to suitable shortcuts so that you can maximize your productivity and reduce keystrokes. Whenever in doubt, refer to emacswiki for clarifications. Another wonderful reference would be Steve Yegge's articles on emacs.
Before I explain my setup, let me make it clear that most editors already have a lot of the functionality and I am not being judgemental in this post. If you've come here to see me bash other editors or proclaim that emacs is the best editor, you are going to be disappointed. Emacs has worked for me and a lot of other people and may work for you. Give a couple of editors out there in the market a try (atleast for a fortnight for each editor) and decide the one that you are most comfortable with.
I use emacs without a window system (emacs -nw) and have an alias entry in my .bashrc to load it in this mode by default.
Here are the contents on my .emacs.d/init.el file and I will explain them below line by line:
;; .emacs
;; enable visual feedback on selections
(setq transient-mark-mode t)
;;; interfacing with ELPA, the package archive.
;;; Move this code earlier if you want to reference
;;; packages in your .emacs.
(when
(load
(expand-file-name "~/.emacs.d/elpa/package.el"))
(package-initialize))
;; My customizations
(ido-mode 1)
(icomplete-mode 1)
(column-number-mode 1)
(menu-bar-mode 1)
(setq tags-file-name "~/TAGS")
(global-set-key (kbd "<f5>") 'find-tag)
(global-set-key (kbd "<f6>") 'rgrep)
(global-set-key (kbd "<f7>") 'magit-status)
(setq yas/root-directory "~/.emacs.d/snippets")
(yas/load-directory yas/root-directory)
(load (expand-file-name "~/.emacs.d/multi-term.el"))
(require 'multi-term)
(setq multi-term-program "/bin/bash")
(multi-term)
(defalias 'term 'multi-term)
(defun build-tags ()
(interactive)
(call-process-shell-command
"find ~/django_projects/ -name '*.py' -print \" \
"|xargs etags -o ~/TAGS"
nil (get-buffer-create "Etags Compile") 1)
)
(defalias 'etb 'build-tags)
(defalias 'yes-or-no-p 'y-or-n-p)
The transient-mark-mode symbol when enabled gives feedback while marking regions (highlighting selected regions).
I use ELPA (Emacs Lisp Package Archive) for installing and managing my packages. Though currently, there are a few packages only in ELPA, they've been sufficient for me. There's another emacs package manager that I am looking forward to called epkg which will install packages from the EmacsMirror.
I have a few modes enabled by default like ido-mode (for intelligent auto completion in the minibuffer), icomplete-mode (for helping me complete commands in the minibuffer without remembering the full names), column-number-mode (to display the column number at which the point is currently located, useful if you follow PEP-8 for python) and disable the menu-bar as I hardly use it. The menu-bar is a distraction especially when you are using emacs on a separate display in a maximized state.
I use emacs tags to jump between function calls and definitions very frequently and hence bound this invocation to the F5 key. One thing to note is that F5-F9 are generally unassigned and can be bound to your most frequently used actions.
I also search very often for files or content within files and use rgrep and this has been bound to the F6 key.
I use git a lot and hence use magit, a fantastic emacs mode to interact with git. This mode has been bound to the F7 key of the keyboard.
I am not a big fan of auto-complete but use some snippet based auto-completion using yasnippets. It's very easy to write your own snippets and I've written lots of them for django and some dom elements.
Whenever I start emacs, I also start a shell and multi-term is very useful in this regard. It handles unicode and ncurses based output very well. This is where I run the django development server or deploy using the fabric scripts.
Apart from these elisp packages, I run erc (an IRC client written for emacs) occasionally to lurk on #django. I manage my tasks using the org-mode and synchronize these tasks with my home workstation using the mobileorg android app and dropbox.
As you would've observed my emacs setup is fairly minimal but suffices most of my django and python development. If you are an emacs user and have tips for me and other users, leave your comments. There's always a lot to learn in emacs :)
Comments
If you are doing django development, or any kind of Python development, you should consider pyflakes. Within minutes of installing it, I was hooked. It's an easy install on debian/ubuntu: apt-get install pyflakes
My setup:
;; PyFlakes is highly recommended for Python code
(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 "pyflakes" (list local-file))))
(add-to-list 'flymake-allowed-file-name-masks
'("\\.py\\'" flymake-pyflakes-init)))
(add-hook 'python-mode-hook 'flymake-mode)
Bonus: There is pyflakes for your vim heretics, too.
Do you have any Django-specific tips for emacs users? For about 4 months I've been doing my Django development exclusively in emacs, and I've been mostly satisfied. The one thing I'm lacking is good up-to-date html template support that is aware of Django template tags.
While writing this post I discovered a newer django-mode and django-html-mode. I'll be sure to check it out: http://code.djangoproject.com/wiki/Emacs#Newdjango-modedjango-html-mode
Thomas and Jeff,
Thanks for your comments.
Jeff,
Thanks for the pointer about Pyflakes. It looks very interesting. I gave it a try and need a little more time using it to understand it's functionality.
Thomas,
django-mode and django-html-mode are wrappers around yasnippets and have a few key bindings for common operations.
I am planning to update the post to include my full init.el.
For snippet based completion, I have written a few snippets and make use of https://github.com/theju/my_yasnippets/
As the leading language-learning software in the world, Rosetta Stone makes learning a new language second nature. Millions of learners in more than 150 countries have already used our software to gain the confidence that comes with truly knowing a new language. We’re continually improving our software technology and adding new products. With Rosetta Stone at the helm, the future of language learning is very bright indeed.
Reactions
RT@shabda: http://agiliq.com/blog/2010/12/django-emacs-setup/ Django emacs setup by@theju
http://agiliq.com/blog/2010/12/django-emacs-setup/ Django emacs setup by@theju
- Test Driven Development in Python
- Deploying Django apps on Heroku
- Developing android applications from command line
- Deploy Django App in 5 Easy Steps
- Project Management Tools for Start-Ups
- Generating a pdf from an image using PIL and django
- Dynamically attaching SITE_ID to Django Caching
- Screencast: How to deploy Django on Heroku
- Deploying Django apps on Heroku
- How to use pep8.py to write better Django code
- rails
- django
- linkroundup
- django opinion
- opinion
- business
- API
- appengine
- python
- satire
- startup
- Uncategorized
- marketing
- personal
- rambling
- search
- interviews
- seo-interviews
- 5startupideas
- ideas
- seo
- tips
- forms
- paypal
- utilities
- datetime
- web2.0
- Amazon
- algorithms
- presentations
- products
- pinax
- satchmo
- ecommerce
- microsoft
- yahoo
- book
- tutorial
- models
- aggreagtion
- meta
- India
- apps
- about
- CSS
- Design
- wordpress
- test slug
- vim
- urls
- reviews
- javascript
- xmpp
- emacs
- Typography
- Grid Theory
- Color Theory
- iphone
- android
- titanium
- mobile applications
- CSS3
- Browser Compatibility
- mobile
- jobs
- lamson
- django setup
- files
- upload
- jsTree
- hierarchical view
- web page
- Treeview
- coffeescript
- request
- response
- South
- django south
- django migration
- --fake
- screencasts
- django caching
- SITE_ID prefix
- review
- code hosting
- comparison
- unfuddle
- fogbugz
- assembla
- github
- project management
- ticketing system
- gunicorn
- deploy
- nginx
- ubuntu
- vps
- android terminal
- terminal
- programming
- TDD
- Test Driven
- Development
- May 2012
- April 2012
- March 2012
- February 2012
- January 2012
- December 2011
- October 2011
- September 2011
- July 2011
- June 2011
- April 2011
- February 2011
- January 2011
- December 2010
- November 2010
- October 2010
- September 2010
- June 2010
- April 2010
- March 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- April 2009
- March 2009
- February 2009
- November 2008
- October 2008
- June 2008
- May 2008
- April 2008
"One of the coolest things at Agiliq is that we are free to use the development tools of our choice."
Aww I thought i was one of the cool things, and there are many cooler things. :)