My Django Emacs
I describe here some modes I have activated to work with emacs :
Simply put these lines in your .emacs. Most of these modes are part of Emacs
Uniquify
When you have several buffers with same file name, like views.py, it is really boring to switch between views.py<3>, views.py<4>. With Uniquify, buffer names could be prefixed with parent directory, like admin/views.py, forms/views.py.
(require 'uniquify) (setq uniquify-buffer-name-style 'forward)
Ido Mode
There is many modes other modes like Ido. I found it very pleasant to load and switch buffers, in conjunction with Uniquify.
(require 'ido) (ido-mode t)
Emacs 23
Not released yes (perhaps 2009 ?), but I use emacs-snapshot on my debian, to have anti-aliased rendering.
deb http://emacs.orebokech.com lenny main
I have activated bold face for keywords and italics for comments
(set-face-bold-p 'font-lock-keyword-face t) (set-face-italic-p 'font-lock-comment-face t)
JavaScript
I like Js2Mode, with syntax error highliting.
Downlad it and append these lines in your .emacs
(autoload 'js2-mode "js2" nil t)
(add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))
Editing Templates
See http://code.djangoproject.com/wiki/Emacs . I personnaly use Django Html Mode, derived from html-mode : auto-indentation, smart closing html and django tags.
(autoload 'django-html-mode "django-html-mode")
(add-to-list 'auto-mode-alist '("\\.[sx]?html?\\'" . django-html-mode))
Some functions
These two functions are very useful if you have to tag texts for gettext translation. Select your text region in python or html and use the shortcuts below.
(defun django-insert-trans (from to &optional buffer)
(interactive "*r")
(save-excursion
(save-restriction
(narrow-to-region from to)
(goto-char from)
(iso-iso2sgml from to)
(insert "{% trans \"")
(goto-char (point-max))
(insert "\" %}")
(point-max))))
(defun django-insert-transpy (from to &optional buffer)
(interactive "*r")
(save-excursion
(save-restriction
(narrow-to-region from to)
(goto-char from)
(iso-iso2sgml from to)
(insert "_(")
(goto-char (point-max))
(insert ")")
(point-max))))
(add-hook 'sgml-mode-hook
(lambda ()
(local-set-key "\C-c\C-g" 'django-insert-trans)
(setq indent-tabs-mode nil)
))
(add-hook 'python-mode-hook
'(lambda ()
(outline-minor-mode 1)
(setq
tab-width 4
python-indent 4
outline-regexp py-outline-regexp
outline-level 'py-outline-level)
(local-set-key "\C-c\C-t" 'django-insert-transpy)
)

PDF version
Doug Mai 13, 2009 at 11:13 après-midi
Thanks for posting this. uniquify alone made this worth reading. That's a huge win.