This package allows to run django commands in GNU Emacs
Packages shipped with GNU Emacs: compile
, project
, python
and which-func
django-commands
available on MELPA:
M-x package-install
RET django-commands
RET.
Alternatively, you can download django-commands.el
and run:
M-x package-install-file
RET <path-to-django-commands-el>
RET
Put django-commands.el
somewhere in your load path and add this to init.el
:
(require 'django-commands)
Runs shell command in django-commands-shell-mode
. It's derived from inferior-python-mode
so there are native completions and pdb tracking mode.
Runs server command in comint-mode with pdb tracking mode and compilation-shell-minor-mode
.
Asks test name to run and then runs test command in comint-mode with pdb tracking enabled and compilation-shell-minor-mode
.
Being runned in one of django-commands-mode buffers restarts current django command.
If command is invoked with prefix argument (e.g. C-u M-x django-commands-shell
RET) it allow to edit command arguments.
If command is invoked with prefix numeric value greater 4 (e.g. C-u C-u M-x django-commands-shell
RET) it also prompt for project directory.
Key | Description |
---|---|
C-c C-q | Call django-commands-restart |
M-x customize-group
RET django-commands
RET
For each command you can specify command name and default arguments.
Also all variables can be customized through dir-locals.el
. For example, you can specify python executable and django settings module for particular project:
((nil . ((django-commands-python-executable . "~/.virtualenvs/virtualenvname/bin/python")
(django-commands-settings-module . "settings.module.name"))))
You can set django-commands-projects-dir
to directory containing all your projects (e.g. ~/workspace
), then all prompts for project directory will be started in that directory.
It may be useful to filter out some django server output. For example, don't output static files request and print out separator between server restarts:
(defun my/django-server-preoutput-filter (string)
(cond ((string-match-p "^\\[[^]]+\\] .*\"GET /static/" string) "")
((string-prefix-p "Performing system checks...\n" string) (format "\f\n%s" string))
(t string)))
(add-hook 'django-commands-server-mode-hook
#'(lambda()
(page-break-lines-mode)
(add-to-list 'comint-preoutput-filter-functions #'my/django-server-preoutput-filter)))
Native shell completions can't be enabled in IPython since IPython doesn't support readline. That's why -i python
is default arguments for shell command.
Take a look at rlipython. If you decide to use it you can safely remove -i python
from django-commands-shell-args
.