Skip to content

muffinmad/emacs-django-commands

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 

Repository files navigation

Stand With Ukraine

License GPL 3 MELPA MELPA Stable

emacs-django-commands

This package allows to run django commands in GNU Emacs

Installation

Dependencies

Packages shipped with GNU Emacs: compile, project, python and which-func

With package.el

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

Without package.el

Put django-commands.el somewhere in your load path and add this to init.el:

(require 'django-commands)

Usage

Interactive commands

django-commands-shell

Runs shell command in django-commands-shell-mode. It's derived from inferior-python-mode so there are native completions and pdb tracking mode.

django-commands-server

Runs server command in comint-mode with pdb tracking mode and compilation-shell-minor-mode.

django-commands-test

Asks test name to run and then runs test command in comint-mode with pdb tracking enabled and compilation-shell-minor-mode.

django-commands-restart

Being runned in one of django-commands-mode buffers restarts current django command.

Commands arguments

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 bindings

Key Description
C-c C-q Call django-commands-restart

Customization

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"))))

Projects directory

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.

Filtering django-commands-server output

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)))

Django shell and IPython

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.