;; Kuso - My personal emacs IDE ;; Copyright (C) 2010 Sameer Rahmani ;; ;; This program 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 ;; any later version. ;; ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;; django plugin (require 'cl) ;; ------------------------------------------------------------------- ;; Variables ;; ------------------------------------------------------------------- (defvar project-path "" "Project source tree path.") ;; ------------------------------------------------------------------- ;; Hooks ;; ------------------------------------------------------------------- (defvar django-preinit-hook '() "This hook runs before initializing the Kuso django-plugin minor mode." ) (defvar django-postinit-hook '() "This hook runs after Kuso django-plugin minor mode initialized." ) (defvar django-prerm--hook '() "This hook runs before deactivating Kuso django-plugin minor mode." ) (defvar django-postrm-hook '() "This hook runs after Kuso django-plugin minor mode deactivated." ) ;; --------------------------------------------------------------------- ;; Keymaps ;; --------------------------------------------------------------------- (defvar django-map (make-sparse-keymap) "Default keymap for Kuso django minor mode that hold the global key binding for Kuso IDE django plugin" ) ;; --------------------------------------------------------------------- ;; Custom Variables ;; --------------------------------------------------------------------- (defcustom django-plugin t "KusoIDE Django programming language plugin." :group 'kuso-features :type 'boolean :tag '"django plugins") ;; ---------------------------------------------------------------------- ;; Functions ;; ---------------------------------------------------------------------- (defun init-keymap () "Initialize the keymap for django plugin." (define-key django-map (kbd "") 'django-runserver) (define-key django-map (kbd "") 'django-syncdb) ;; (define-key django-map (kbd "\C-x p f") 'django-buffer) ) (defun init-menus () "Initialize menu entry for django plugin." (define-key-after global-map [menu-bar django] (cons "Django" (make-sparse-keymap "django-map"))) (define-key-after global-map [menu-bar django manage] (cons "Management" (make-sparse-keymap "django-manage-map"))) (define-key-after global-map [menu-bar django manage runserver] '("Development Server" . django-runserver)) (define-key-after global-map [menu-bar django manage runserver-extra] '("Development Server Extended" . django-runserver-extra) 'runserver) (define-key-after global-map [menu-bar django manage syncdb] '("Syncdb" . django-syncdb) 'runserver-extra) (define-key-after global-map [menu-bar django manage syncdb-extra] '("Syncdb with extra options" . django-syncdb-extra) 'syncdb) (define-key-after global-map [menu-bar django sep2] '("--") 'runserver-extra) ) (defun destruct-menus () "Remove menus from menubar" (global-unset-key [menu-bar django]) ;; (global-unset-key [menu-bar edit sep2]) ;; (global-unset-key [menu-bar edit djangoreg]) ;; (global-unset-key [menu-bar edit djangobuf]) ) (defun get-project-path () "Get the project path." (setq project-path (read-directory-name "Project source tree: ")) ) (defun manage-command (buffername command-process-name command) "Run the given command in e new buffer." (let (fullcommand lastslash) (if (string= project-path "") (get-project-path) ) (setq newcommand-buffer (get-buffer-create buffername)) (ansi-color-for-comint-mode-on) (switch-to-buffer newcommand-buffer) (add-hook 'after-change-functions 'buffer-change-colorizing t t) (setq lastslash (substring project-path (- (length project-path) 1) (length project-path))) (message lastslash) (if (not (string= lastslash "/")) (setq project-path (concat project-path "/"))) (setq fullcommand (concat "python " project-path "manage.py " command)) (message fullcommand) (setq commandp (start-process-shell-command command-process-name newcommand-buffer fullcommand)) ) ) (defun* django-syncdb (&optional (extra "")) "Run the django syndb" (interactive) (let (params) (setq params (concat "syncdb " extra)) (manage-command "*Syncdb*" "syncdb" params) ) ) (defun django-syncdb-extra () "Run the django syndb with extra options." (interactive "sEnter extra options for syncdb: ") (django-syncdb extra) ) (defun buffer-change-colorizing (start end length) "colorizing the region from start to end." (ansi-color-apply-on-region start end) ) (defun* django-runserver (&optional (extra "")) "Run the project development server in a new buffer" (interactive) (let (params) (setq params (concat "runserver " extra)) (manage-command "*Runserver*" "Runserver" params) ) ) (defun django-runserver-extra (args) "Run the development server with extra options." (interactive "sEnter extra arguments for runserver: ") (django-runserver args) ) ;; ---------------------------------------------------------------------- ;; Minor Modes ;; ---------------------------------------------------------------------- (define-minor-mode django-mode "Toggle Kuso django plugin mode. This plugin provide some functionality for speedup django development on GNUEmacs." :lighter nil :keymap django-map :global t :group 'kuso-group (if django-mode ;; kuso-cplugin-mode is not loaded (let () ;; before initiazing mode (run-hooks 'django-preinit-hook) (init-keymap) (message "sdfsdfsdf") (init-menus) ;;(put 'django-region 'menu-enable nil) ;;(force-mode-line-update) ;; after mode was initialized (run-hooks 'django-postinit-hook) ) ;; kuso-mode already loaded (let () ;; before deactivating mode (run-hooks 'django-prerm-hook) (destruct-menus) (setq project-path "") ;; after deactivating mode (run-hooks 'django-postrm-hook) ) ) )