Move from django-mode to django-manage

The former depends on yasnippet that I don’t use (but maybe I will
Gergely Polonkai 6 years ago
parent 6d1a74584b
commit 65a3b9a9bf

@ -0,0 +1,22 @@
;;; django-manage-autoloads.el --- automatically extracted autoloads
;;; Code:
(add-to-list 'load-path (or (file-name-directory #$) (car load-path)))
;;;### (autoloads nil "django-manage" "django-manage.el" (22501 5677
;;;;;; 768491 198000))
;;; Generated autoloads from django-manage.el
(autoload 'django-manage "django-manage" "\
Minor mode for handling Django's
\(fn &optional ARG)" t nil)
;; Local Variables:
;; version-control: never
;; no-byte-compile: t
;; no-update-autoloads: t
;; End:
;;; django-manage-autoloads.el ends here

@ -0,0 +1 @@
(define-package "django-manage" "20160818.1912" "Django minor mode for commanding" '((hydra "0.13.2")) :keywords '("languages"))

@ -0,0 +1,319 @@
;;; django-manage.el --- Django minor mode for commanding
;; Copyright (C) 2015 Daniel Gopar
;; Author: Daniel Gopar <>
;; Package-Requires: ((hydra "0.13.2"))
;; Package-Version: 20160818.1912
;; Version: 0.1
;; Keywords: languages
;; This file is NOT part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <>.
;;; Commentary:
;; Simple package to be to be able to control `', the standard
;; file that every Django project comes with. You are able to call any
;; command with `django-manage-command' plus it comes with code
;; completion so third party plugins will also be completed.
;;; Code:
(condition-case nil
(require 'python)
(require 'python-mode)))
(require 'hydra)
(defcustom django-manage-shell-preference 'pyshell
"What shell to use."
:type 'symbol
:options '(eshell term pyshell)
:group 'shell)
(defcustom django-manage-server-ipaddr ""
"What address Django will use when running the dev server."
:type 'string
:group 'server)
(defcustom django-manage-server-port "8000"
"What port Django will use when running the dev server."
:type 'string
:group 'server)
(defcustom django-manage-prompt-for-command nil
"When non-nil will ask for confirmation on command.
Will affect every function other than `django-manage-command'."
:type 'boolean
:group 'django-manage)
(defcustom django-manage-root ""
"The directory where '' lives."
:type 'string
:group 'django-manage)
(make-local-variable 'django-manage-root)
(defun django-manage-root ()
"Return the root directory of Django project."
;; Check if projectile is in use, and if it is. Return root directory
(if (not (string= django-manage-root ""))
(if (fboundp 'projectile-project-root)
;; Try looking for the directory holding ''
(locate-dominating-file default-directory ""))))
(defun django-manage-python-command ()
"Return Python version to use with args."
(if (boundp 'python-shell-interpreter)
(concat python-shell-interpreter " " python-shell-interpreter-args)
;; For old python.el
(mapconcat 'identity (cons python-python-command python-python-command-args) " ")))
(defun django-manage-get-commands ()
"Return list of django commands."
(let ((help-output
(shell-command-to-string (concat python-shell-interpreter " "
(shell-quote-argument (django-manage-root)) " -h"))))
(setq dj-commands-str
(insert help-output)
(delete-region (point) (search-forward "Available subcommands:" nil nil nil))
;; cleanup [auth] and stuff
(replace-regexp "\\[.*\\]" ""))
;; get a list of commands from the output of -h
;; What would be the pattern to optimize this ?
(setq dj-commands-str (s-split "\n" dj-commands-str))
(setq dj-commands-str (-remove (lambda (x) (string= x "")) dj-commands-str))
(setq dj-commands-str (mapcar (lambda (x) (s-trim x)) dj-commands-str))
(sort dj-commands-str 'string-lessp)))
(defun django-manage-command (command &optional no-prompt)
"Allow to run any `' command.
Argument COMMAND command for django to run.
Optional Argument NO-PROMPT if non-nil will *not* ask if you wish to pass extra arguments."
;; nil nil: enable user to exit with any command. Still, he can not edit a completed choice.
(interactive (list (completing-read "Command: " (django-manage-get-commands) nil nil)))
(if (not no-prompt)
;; Now ask to edit the command. How to do the two actions at once ?
(setq command (read-shell-command "Run command like this: " command)))
(compile (concat (django-manage-python-command) " "
(shell-quote-argument (django-manage-root)) " " command)))
(defun django-manage-makemigrations (&optional app-name)
"Run \"makemigrations app-name\", will prompt for \"app-name\".
You can leave blank to simply run \"makemigrations\".
To choose arguments call `django-manage-command'.
Optional argument APP-NAME name of django app create migrations."
(interactive "sName: ")
(django-manage-command (concat "makemigrations " app-name)
(not django-manage-prompt-for-command)))
(defun django-manage-flush ()
"Run \"flush --noinput\". To choose arguments call `django-manage-command'."
(django-manage-command "flush --noinput"
(not django-manage-prompt-for-command)))
(defun django-manage-runserver ()
"Start the development server. To change what address and port to use,
customize `django-manage-server-ipaddr' and `django-manage-server-port'
If you want to pass arguments, then call `django-manage-command'"
(let ((parent-dir (file-name-base (substring (django-manage-root) 0 -1))))
(compile (concat (django-manage-python-command) " "
(shell-quote-argument (django-manage-root)) " runserver "
django-manage-server-ipaddr ":" django-manage-server-port))
(with-current-buffer "*compilation*"
(rename-buffer (format "*runserver[%s]*" parent-dir)))))
(defun django-manage-migrate ()
"Run \"migrate\". To choose arguments call `django-manage-command'."
(django-manage-command "migrate"
(not django-manage-prompt-for-command)))
(defun django-manage-assets-rebuild ()
"Run \"assets rebuild\". To choose arguments call `django-manage-command'."
(django-manage-command "assets rebuild"
(not django-manage-prompt-for-command)))
(defun django-manage-startapp (name)
"Run \"startapp name\". Will prompt for name of app.
To choose arguments call `django-manage-command'.
Argument NAME name of app to create."
(interactive "sName:")
(django-manage-command (concat "startapp " name)
(not django-manage-prompt-for-command)))
(defun django-manage-makemessages ()
"Run \"makemessages --all --symlinks\".
To pass arguments call `django-manage-command'."
(django-manage-command "makemessages --all --symlinks"
(not django-manage-prompt-for-command)))
(defun django-manage-compilemessages ()
"Run \"compilemessages\". To pass arguments call `django-manage-command'."
(django-manage-command "compilemessages"
(not django-manage-prompt-for-command)))
(defun django-manage-test (name)
"Run \"test name\". Will prompt for Django app name to test.
To pass arguments call `django-manage-command'.
Argument NAME name of django app to test."
(interactive "sTest app:")
(django-manage-command (concat "test " name)
(not django-manage-prompt-for-command)))
(defun django-manage--prep-shell (pref-shell)
"Prepare the shell with users preference.
Argument PREF-SHELL users shell of choice"
;; If a preexisting shell buffer exists return that one. If not create it
(let* ((parent-dir (file-name-base (substring (django-manage-root) 0 -1)))
(default-directory (django-manage-root))
(format (if (string= pref-shell "shell") "*Django Shell[%s]*" "*Django DBshell[%s]*") parent-dir)))
;; If it exists return it
(if (get-buffer buffer-shell-name)
(switch-to-buffer buffer-shell-name)
;; Shell didn't exist, so let's create it
(if (eq 'term django-manage-shell-preference)
(term (concat (django-manage-python-command) " "
(shell-quote-argument (django-manage-root)) " " pref-shell)))
(if (eq 'eshell django-manage-shell-preference)
(unless (get-buffer eshell-buffer-name)
(insert (concat (django-manage-python-command) " "
(shell-quote-argument (django-manage-root)) " " pref-shell))
(if (eq 'pyshell django-manage-shell-preference)
(let ((setup-code "os.environ.setdefault(\"DJANGO_SETTINGS_MODULE\", \"%s.settings\")")
(cmd ";from import execute_from_command_line")
(exe (if (string= pref-shell "shell")
";import django;django.setup()"
(format ";execute_from_command_line(['', '%s'])" pref-shell))))
(run-python (python-shell-parse-command))
(python-shell-send-string (concat (format setup-code parent-dir) cmd exe))
(switch-to-buffer (python-shell-get-buffer))))
(rename-buffer buffer-shell-name))))
(defun django-manage-shell ()
"Start Python shell with Django already configured."
(django-manage--prep-shell "shell"))
(defun django-manage-dbshell ()
"Start Database shell."
(django-manage--prep-shell "dbshell"))
(defun django-manage-insert-transpy (from to &optional buffer)
"Wraps highlighted region in _(...) for i18n.
Argument FROM start point TO wrap.
Optional argument BUFFER end point to wrap."
;; From
;; Modified a little
(interactive "*r")
(narrow-to-region from to)
(goto-char from)
(iso-iso2sgml from to)
(insert "_(")
(goto-char (point-max))
(insert ")")
(defhydra django-manage-hydra (:color blue
:hint nil)
_mm_: Enter commnand _r_: runserver _f_: Flush _t_: Run rest
_ma_: Makemigrations _sa_: Start new app _i_: Insert transpy
_mg_: Migrate _ss_: Run shell _a_: Rebuild Assets
_me_: Make messages _sd_: Run DB Shell _c_: Compile messages
_q_: Cancel
("mm" django-manage-command)
("ma" django-manage-makemigrations)
("mg" django-manage-migrate)
("me" django-manage-makemessages)
("r" django-manage-runserver "Start server")
("sa" django-manage-startapp)
("ss" django-manage-shell)
("sd" django-manage-dbshell)
("f" django-manage-flush)
("a" django-manage-assets-rebuild)
("c" django-manage-compilemessages)
("t" django-manage-test)
("i" django-manage-insert-transpy)
("q" nil "cancel"))
(defvar django-manage-map
(let ((map (make-keymap)))
(define-key map (kbd "C-c C-x") 'django-manage-hydra/body)
(defun django-manage-setup ()
"Determine whether to start minor mode or not."
(when (and (stringp buffer-file-name)
(locate-dominating-file default-directory ""))
(define-minor-mode django-manage
"Minor mode for handling Django's"
:lighter " Manage"
:keymap django-manage-map)
(easy-menu-define django-manage-menu django-manage-map "Django menu"
["Start an app" django-manage-startapp t]
["Run tests" django-manage-test t]
["Make migrations" django-manage-makemigrations t]
["Flush database" django-manage-flush t]
["Runserver" django-manage-runserver t]
["Run database migrations" django-manage-migrate t]
["Rebuild assets" django-manage-assets-rebuild t]
["Make translations" django-manage-makemessages t]
["Compile translations" django-manage-compilemessages t]
["Open Python shell" django-manage-shell t]
["Open database shell" django-manage-dbshell t]
["Run other command" django-manage-command t]
["Insert translation mark" django-manage-insert-transpy t]))
(easy-menu-add django-manage-menu django-manage-map)
(provide 'django-manage)
;;; django-manage.el ends here

@ -1,489 +0,0 @@
;;; django-html-mode.el --- Major mode for editing Django HTML templates
;; Author: Eduardo de Oliviera Padoan <>
;; Michael J. Korman <>
;; Török Gábor <>
;; Greg V <>
;; Unknown Original Author
;; Keywords: languages
;;; Commentary:
;; This django-html-mode is mainly derived from nxml-mode.
;;; History:
;; TODO: Make comment-region work with Django comments instead of HTML comments
(require 'nxml-mode)
;;; Code:
(defgroup django-html nil
"Customizations for `django-html-mode'."
:prefix "django-html-"
:group 'django)
(defvar django-html-mode-hook nil
"List of functions to be executed on entry to `django-html-mode'.")
(defvar django-html-mode-map
(let ((django-html-mode-map (make-keymap)))
(define-key django-html-mode-map "\C-c\C-dj" 'newline-and-indent)
(define-key django-html-mode-map "\C-c\C-d]" 'django-html-close-tag)
(define-key django-html-mode-map "\C-c\C-di" 'django-html-insert-tag)
"Keymap for Django major mode.")
;; if : if, if not, if A or B, if not A or B, if not A and B
;; for : for a in alist reversed
;; forloop.counter The current iteration of the loop (1-indexed)
;; forloop.counter0 The current iteration of the loop (0-indexed)
;; forloop.revcounter The number of iterations from the end of the loop
;; (1-indexed)
;; forloop.revcounter0 The number of iterations from the end of the loop
;; (0-indexed)
;; forloop.first True if this is the first time through the loop
;; forloop.last True if this is the last time through the loop
;; forloop.parentloop For nested loops, this is the loop "above" the
;; current one
;; ifequal : ifequal A B
;; comment : {% This is comment %}
;; filter : {{ name | lower }}
;; keyword-end : if, for, ifequal, block, ifnotequal, spaceless
;; keyword-3 : regroup
;; keyword-2 : for, ifequal
;; keyword-1 : if, block, extends, include, ifchanged, load, now, ssi, withratio
;; keyword-0 : else, spaceless
(defconst django-html-open-block "{%"
"Start keyword for template blocks.")
(defconst django-html-close-block "%}"
"End keyword for template blocks.")
(defconst django-html-open-comment "{#"
"Start keyword for template comments.")
(defconst django-html-close-comment "#}"
"End keyword for template comments.")
(defconst django-html-open-variable "{{"
"Start keyword for template variables.")
(defconst django-html-close-variable "}}"
"End keyword for template variables.")
(defconst django-html-font-lock-keywords
`(;; comment
(,(rx (eval django-html-open-comment)
(1+ space)
(0+ (not (any "#")))
(1+ space)
(eval django-html-close-comment))
. font-lock-comment-face)
;; variable font lock
(,(rx (eval django-html-open-variable)
(1+ space)
(group (0+ (not (any "}"))))
(1+ space)
(eval django-html-close-variable))
(1 font-lock-variable-name-face))
;; start, end keyword font lock
(,(rx (group (or (eval django-html-open-block)
(eval django-html-close-block)
(eval django-html-open-comment)
(eval django-html-close-comment)
(eval django-html-open-variable)
(eval django-html-close-variable))))
(1 font-lock-builtin-face))
;; end prefix keyword font lock
(,(rx (eval django-html-open-block)
(1+ space)
(group (and "end"
;; end prefix keywords
(or "autoescape" "block" "blocktrans" "cache" "comment"
"filter" "for" "if" "ifchanged" "ifequal"
"ifnotequal" "spaceless" "trans" "with")))
(1+ space)
(eval django-html-close-block))
(1 font-lock-keyword-face))
;; more words after keyword
(,(rx (eval django-html-open-block)
(1+ space)
(group (or "autoescape" "block" "blocktrans" "cache" "comment"
"cycle" "debug" "else" "empty" "extends" "filter" "firstof" "for"
"if" "ifchanged" "ifequal" "ifnotequal" "include"
"load" "now" "regroup" "spaceless" "ssi" "templatetag"
"trans" "url" "widthratio" "with"))
;; TODO: is there a more beautiful way?
(0+ (not (any "}")))
(1+ space)
(eval django-html-close-block))
(1 font-lock-keyword-face))
;; TODO: if specific cases for supporting "or", "not", and "and"
;; for sepcific cases for supporting in
(,(rx (eval django-html-open-block)
(1+ space)
(1+ space)
(group (1+ (or word ?_ ?.)))
(1+ space)
(group "in")
(1+ space)
(group (1+ (or word ?_ ?.)))
(group (? (1+ space) "reverse"))
(1+ space)
(eval django-html-close-block))
(1 font-lock-variable-name-face) (2 font-lock-keyword-face)
(3 font-lock-variable-name-face) (4 font-lock-keyword-face)))))
(defvar django-html-mode-syntax-table
(let ((django-html-mode-syntax-table (make-syntax-table)))
"Syntax table for django-html-mode.")
;;; Auto-close tags
(defvar django-html-closable-tags
'("autoescape" "blocktrans" "block" "cache"
"comment" "filter" "for" "ifchanged"
"ifequal" "ifnotequal" "if" "spaceless"
;;; Non-auto close tags
(defvar django-html-nonclosable-tags
'("cycle" "debug" "empty" "extends" "firstof" "include"
"load" "now" "regroup" "ssi" "templatetag"
"url" "widthratio"))
(defvar django-html-all-tags
(append django-html-closable-tags django-html-nonclosable-tags))
(defvar django-html-tag-re
"\\s *\\(end\\)?\\("
(mapconcat 'identity django-html-closable-tags "\\|")
(define-derived-mode django-html-mode nxml-mode "django-html"
"Major mode for editing Django html templates (.djhtml).
:group 'django-html
;; it mainly from nxml-mode font lock setting
(set (make-local-variable 'font-lock-defaults)
nil t nil nil
. nxml-font-lock-keywords))))
(add-hook 'django-html-mode-hook (lambda () (setq indent-tabs-mode nil)))
(defun django-html-find-open-tag ()
"Return open tag for closed template tag.
If tags are unbalanced, raise error."
(if (search-backward-regexp django-html-tag-re nil t)
(if (match-string 1) ; If it's an end tag
(if (not (string= (match-string 2) (django-html-find-open-tag)))
(error "Unmatched Django tag")
(match-string 2)) ; Otherwise, return the match
(defun django-html-close-tag ()
"Close the previously opened template tag."
(let ((open-tag (save-excursion (django-html-find-open-tag))))
(if open-tag
(format "%s end%s %s"
django-html-open-block open-tag django-html-close-block))
(error "Nothing to close"))))
(define-skeleton django-html-closing-template
"Insert a generic template with a closing tag." nil
django-html-open-block " " str " " django-html-close-block
django-html-open-block " " "end" str " " django-html-close-block)
(define-skeleton django-html-nonclosing-template
"Insert a generic template without a closing tag." nil
django-html-open-block " " str " " django-html-close-block)
(defun django-html-make-opening-tag (tag)
(format "%s %s %s"
(defun django-html-make-closing-tag (tag)
(concat "end" tag)))
;;;; Skeletons for inserting tags.
;; TODO: regroup tag. This has a more complicated syntax.
;; TODO: url tag. Maybe this should read URLs from the URLconf?
;; TODO: auto-complete filters.
(define-skeleton django-html-autoescape-template
"Insert \"autoescape\" template." nil
(let ((on-or-off (if (y-or-n-p "autoescape on? ")
"on" "off")))
(format "%s autoescape %s %s"
(define-skeleton django-html-for-template
"Insert \"for\" template." nil
(format "%s for %s in %s %s"
(read-string "item: ")
(read-string "array: ")
django-html-close-block) ?\n
_ ?\n
(when (y-or-n-p "\"empty\" clause? ")
(django-html-make-opening-tag "empty")) ?\n
(django-html-make-closing-tag "for"))
(define-skeleton django-html-if-template
"Insert \"if\" template." nil
(format "%s if %s "
(setq v1 (skeleton-read "condition: ")))
(if (string= "" v1) -1)
django-html-close-block ?\n
_ ?\n
(when (y-or-n-p "\"else\" clause? ")
(django-html-make-opening-tag "else")) ?\n
(django-html-make-closing-tag "if"))
(define-skeleton django-html-ifequal-template
"Insert \"ifequal\" template." nil
(format "%s ifequal %s %s %s "
(read-string "variable 1: ")
(read-string "variable 2: ")
django-html-close-block) ?\n
_ ?\n
(when (y-or-n-p "\"else\" clause? ")
(django-html-make-opening-tag "else")) ?\n
(django-html-make-closing-tag "ifequal"))
(define-skeleton django-html-ifnotequal-template
"Insert \"ifnotequal\" template." nil
(format "%s ifnotequal %s %s %s "
(read-string "variable 1: ")
(read-string "variable 2: ")
django-html-close-block) ?\n
_ ?\n
(when (y-or-n-p "\"else\" clause? ")
(django-html-make-opening-tag "else")) ?\n
(django-html-make-closing-tag "ifnotequal"))
(define-skeleton django-html-include-template
"Insert \"include\" template." nil
(format "%s include " django-html-open-block)
(read-string "template: ")
" " django-html-close-block)
(define-skeleton django-html-load-template
"Insert \"load\" template." nil
(format "%s load " django-html-open-block)
(read-string "module: ")
" " django-html-close-block)
(define-skeleton django-html-now-template
"Insert \"now\" template." nil
(format "%s now " django-html-open-block)
"\"" (read-string "format string: ") "\""
" " django-html-close-block)
(define-skeleton django-html-ssi-template
"Insert \"ssi\" template." nil
(format "%s ssi " django-html-open-block)
(read-string "file: ")
" "
(if (y-or-n-p "parsed? ")
"parsed ")
(define-skeleton django-html-templatetag-template
"Insert \"templatetag\" template." nil
(format "%s templatetag " django-html-open-block)
(completing-read "template tag (TAB for completion): "
'("openblock" "closeblock" "openvariable"
"closevariable" "openbrace" "closebrace"
"opencomment" "closecomment") nil t)
" "
(define-skeleton django-html-widthratio-template
"Insert \"widthratio\" template." nil
(format "%s widthratio %s %s %s %s" django-html-open-block
(read-string "given value: ")
(read-string "max value: ")
(read-string "constant: ")
(define-skeleton django-html-with-template
"Insert \"with\" template." nil
(format "%s with %s as %s %s"
(read-string "variable: ")
(read-string "alias: ")
(django-html-make-closing-tag "with"))
(define-skeleton django-html-block-template
"Insert \"block\" template." nil
(let ((block-name (read-string "block: ")))
(format "%s block %s %s"
django-html-close-block)) ?\n
_ ?\n
(django-html-make-closing-tag "block"))
(define-skeleton django-html-cycle-template
"Insert \"cycle\" template." nil
(format "%s cycle " django-html-open-block)
("item: " str " ") -1
" as "
(setq v1 (skeleton-read "name: "))
(if (string= "" v1) -4) " " django-html-close-block)
(define-skeleton django-html-extends-template
"Insert \"extends\" template." nil
(format "%s extends " django-html-open-block)
(read-string "parent: ")
" " django-html-close-block)
(define-skeleton django-html-filter-template
"Insert \"filter\" template." nil
(format "%s filter " django-html-open-block)
("filter: " str "|") -1
" " django-html-close-block)
(define-skeleton django-html-firstof-template
"Insert \"firstof\" template." nil
(format "%s firstof " django-html-open-block)
("item: " str " ") -1
" \"" (setq v1 (skeleton-read "fallback value: ")) "\""
(if (string= "" v1) -3)
" " django-html-close-block)
(defun django-html-insert-tag ()
"Prompts the user for a tag, and inserts opening and closing tags."
(let ((tag (completing-read "Tag (TAB for completion): " django-html-all-tags)))
(cond ((string= tag "autoescape")
((string= tag "cycle")
((string= tag "extends")
((string= tag "filter")
((string= tag "firstof")
((string= tag "for")
((string= tag "if")
((string= tag "ifequal")
((string= tag "ifnotequal")
((string= tag "include")
((string= tag "load")
((string= tag "now")
((string= tag "ssi")
((string= tag "templatetag")
((string= tag "widthratio")
((string= tag "with")
((string= tag "block")
((member tag django-html-closable-tags)
(django-html-closing-template tag))
(django-html-nonclosing-template tag)))))
(easy-menu-define django-html-menu django-html-mode-map "Django-HTML menu"
["Insert Tag" django-html-insert-tag t]
["Auto-close Tag" django-html-close-tag t]
("Tag Templates"
["autoescape" django-html-autoescape-template t]
["block" django-html-block-template t]
["cycle" django-html-cycle-template t]
["extends" django-html-extends-template t]
["filter" django-html-filter-template t]
["firstof" django-html-firstof-template t]
["for" django-html-for-template t]
["if" django-html-if-template t]
["ifequal" django-html-ifequal-template t]
["ifnotequal" django-html-ifnotequal-template t]
["include" django-html-include-template t]
["load" django-html-load-template t]
["now" django-html-now-template t]
["ssi" django-html-ssi-template t]
["templatetag" django-html-templatetag-template t]
["widthratio" django-html-widthratio-template t]
["with" django-html-with-template t])))
(easy-menu-add django-html-menu django-html-mode-map)
;; A part from
;; Modified a little
(defun django-insert-trans (from to &optional buffer)
(interactive "*r")
(narrow-to-region from to)
(goto-char from)
(iso-iso2sgml from to)
(insert "{% trans \"")
(goto-char (point-max))
(insert "\" %}")
(define-key django-html-mode-map (kbd "C-t") 'django-insert-trans)
(add-to-list 'auto-mode-alist '("\\.djhtml$" . django-html-mode))
;; This part ends here
(provide 'django-html-mode)
;;; django-html-mode.el ends here

@ -1,44 +0,0 @@
;;; django-mode-autoloads.el --- automatically extracted autoloads
;;; Code:
(add-to-list 'load-path (or (file-name-directory #$) (car load-path)))
;;;### (autoloads nil "django-html-mode" "django-html-mode.el" (22387
;;;;;; 29372 428700 65000))
;;; Generated autoloads from django-html-mode.el
(autoload 'django-html-mode "django-html-mode" "\
Major mode for editing Django html templates (.djhtml).
\(fn)" t nil)
(add-to-list 'auto-mode-alist '("\\.djhtml$" . django-html-mode))
;;;### (autoloads nil "django-mode" "django-mode.el" (22387 29372
;;;;;; 420706 182000))
;;; Generated autoloads from django-mode.el
(autoload 'django-mode "django-mode" "\
Major mode for Django web framework.
\(fn)" t nil)
(add-to-list 'auto-mode-alist '("\\<\\(models\\|views\\|handlers\\|feeds\\|sitemaps\\|admin\\|context_processors\\|urls\\|settings\\|tests\\|assets\\|forms\\)\\.py\\'" . django-mode))
;;;### (autoloads nil nil ("django-mode-pkg.el") (22387 29372 445484
;;;;;; 219000))
;; Local Variables:
;; version-control: never
;; no-byte-compile: t
;; no-update-autoloads: t
;; End:
;;; django-mode-autoloads.el ends here

@ -1,5 +0,0 @@
(define-package "django-mode" "20150207.517" "Major mode for Django web framework." 'nil :keywords
;; Local Variables:
;; no-byte-compile: t
;; End:

@ -1,189 +0,0 @@
;;; django-mode.el --- Major mode for Django web framework.
;; Copyright (C) 2010-2012 Greg V
;; Author: Greg V <>
;; Keywords: languages
;; This file is NOT part of GNU Emacs.
;; Licensed under the Apache License, Version 2.0 (the "License");
;; you may not use this file except in compliance with the License.
;; You may obtain a copy of the License at
;; Unless required by applicable law or agreed to in writing, software
;; distributed under the License is distributed on an "AS IS" BASIS,
;; See the License for the specific language governing permissions and
;; limitations under the License.
;;; Code:
(condition-case nil
(require 'python)
(require 'python-mode)))
(defvar django-template-regexp ".*\\(@render_to\\|render_to_response\\|TemplateResponse\\)(['\"]\\([^'\"]*\\)['\"].*
(defvar django-view-regexp ".*(.+, ?['\"]\\([^'\",]+\\)['\"].*).*
(defvar django-model-regexp "^[^.]* \\([^.,]+\\)\\(.objects\\|(\\).*
(defun django-root (&optional dir home)
;; Copied from Rinari and modified accordingly.
(or dir (setq dir default-directory))
(if (and (file-exists-p (expand-file-name "" dir))
(file-exists-p (expand-file-name "" dir)))
(let ((new-dir (expand-file-name (file-name-as-directory "..") dir)))
;; regexp to match windows roots, tramp roots, or regular posix roots
(unless (string-match "\\(^[[:alpha:]]:/$\\|^/[^\/]+:\\|^/$\\)" dir)
(django-root new-dir)))))
(defun django-jump-to-template ()
(let ((fname (replace-regexp-in-string django-template-regexp "\\2" (thing-at-point 'line))))
(let ((projfname (concat (django-root) "templates/" fname))
(appfname (concat default-directory "templates/" fname)))
(if (file-exists-p appfname)
(find-file appfname)
(find-file projfname)))))
(defun django-jump-to-view ()
(let ((vname (replace-regexp-in-string django-view-regexp "\\1" (thing-at-point 'line))))
(find-file (concat default-directory ""))
(set-text-properties 0 (length vname) nil vname)
(re-search-forward (concat vname "(.*):
(defun django-jump-to-model ()
(let ((mname (replace-regexp-in-string django-model-regexp "\\1" (thing-at-point 'line))))
(find-file (concat default-directory ""))
(re-search-forward (concat mname "(.*):
(defun django-jump ()
(if (string-match django-template-regexp (thing-at-point 'line))
(if (string-match django-view-regexp (thing-at-point 'line))
(if (string-match django-model-regexp (thing-at-point 'line))
(defun django-python-command ()
(if (boundp 'python-shell-interpreter)
(concat python-shell-interpreter " " python-shell-interpreter-args)
(mapconcat 'identity (cons python-python-command python-python-command-args) " ")))
(defun django-manage (command)
(interactive "sCommand:")
(compile (concat (django-python-command) " " (django-root) " " command)))
(defun django-syncdb ()
(django-manage "syncdb --noinput"))
(defun django-flush ()
(django-manage "flush --noinput"))
(defun django-reset (name)
(interactive "sReset app:")
(django-manage (concat "reset " name " --noinput")))
(defun django-migrate ()
(django-manage "migrate"))
(defun django-assets-rebuild ()
(django-manage "assets rebuild"))
(defun django-startapp (name)
(interactive "sName:")
(django-manage (concat "startapp " name)))
(defun django-makemessages ()
(django-manage "makemessages --all --symlinks"))
(defun django-compilemessages ()
(django-manage "compilemessages"))
(defun django-test (name)
(interactive "sTest app:")
(django-manage (concat "test " name)))
(defun django-shell ()
(term (concat (django-python-command) " " (django-root) " shell")))
(defun django-dbshell ()
(term (concat (django-python-command) " " (django-root) " dbshell")))
(defun django-insert-transpy (from to &optional buffer)
;; From
;; Modified a little
(interactive "*r")
(narrow-to-region from to)
(goto-char from)
(iso-iso2sgml from to)
(insert "_(")
(goto-char (point-max))
(insert ")")
(define-derived-mode django-mode python-mode "Django" "Major mode for Django web framework.")
(define-key django-mode-map (kbd "C-t") 'django-insert-transpy)
(define-key django-mode-map (kbd "C-x j") 'django-jump)
(define-key django-mode-map (kbd "C-c m") 'django-manage)
(define-key django-mode-map (kbd "C-c t") 'django-test)
(define-key django-mode-map (kbd "C-c s") 'django-syncdb)
(define-key django-mode-map (kbd "C-c a") 'django-startapp)
(add-hook 'django-mode-hook
(lambda ()
(font-lock-add-keywords nil
'(("\\<\\(django\\|models\\|forms\\|request\\)\\>" 1 font-lock-type-face)
("\\<\\(get_list_or_404\\|get_object_or_404\\|redirect\\|render_to_response\\)\\>" . font-lock-builtin-face))
(easy-menu-define django-menu django-mode-map "Django menu"
["Start an app" django-startapp t]
["Run tests" django-test t]
["Sync database" django-syncdb t]
["Flush database" django-flush t]
["Reset database" django-reset t]
["Run database migrations" django-migrate t]
["Rebuild assets" django-assets-rebuild t]
["Make translations" django-makemessages t]
["Compile translations" django-compilemessages t]
["Open Python shell" django-shell t]
["Open database shell" django-dbshell t]
["Run other command" django-manage t]
["Jump" django-jump t]
["Insert translation mark" django-insert-transpy t]))
(easy-menu-add django-menu django-mode-map)
(add-to-list 'auto-mode-alist '("\\<\\(models\\|views\\|handlers\\|feeds\\|sitemaps\\|admin\\|context_processors\\|urls\\|settings\\|tests\\|assets\\|forms\\)\\.py\\'" . django-mode))
(provide 'django-mode)
;; django-mode.el ends here

@ -74,7 +74,8 @@
'(show-trailing-whitespace t)
'(sml/theme (quote respectful))
'(tab-width 4)
'(wakatime-api-key "3f97611e-c959-4ce3-a526-bf0241307e17"))
'(wakatime-api-key "3f97611e-c959-4ce3-a526-bf0241307e17")
'(wakatime-cli-path "/usr/local/bin/wakatime"))
(setq magit-auto-revert-mode nil)
(setq magit-last-seen-setup-instructions "1.4.0")
@ -354,3 +355,7 @@ Version 2016-02-16"
(global-set-key (kbd "C-c C-<") 'mc/mark-all-like-this)
(add-hook 'org-mode-hook
(lambda ()
(if (display-graphic-p) (org-bullets-mode t))))