我希望能够./manage.py shell
在Emacs缓冲区中运行,包含你从ipython获得的所有好东西,比如魔术命令和自动完成.理想情况下,我还希望能够将缓冲区中的代码计算到django shell.
这可能吗?
好的,所以我今天自己砍了这个.它的一个主要部分是复制和粘贴来自py-shell
从python-mode.el
.
(defun django-shell (&optional argprompt)
(interactive "P")
;; Set the default shell if not already set
(labels ((read-django-project-dir
(prompt dir)
(let* ((dir (read-directory-name prompt dir))
(manage (expand-file-name (concat dir "manage.py"))))
(if (file-exists-p manage)
(expand-file-name dir)
(progn
(message "%s is not a Django project directory" manage)
(sleep-for .5)
(read-django-project-dir prompt dir))))))
(let* ((dir (read-django-project-dir
"project directory: "
default-directory))
(project-name (first
(remove-if (lambda (s) (or (string= "src" s) (string= "" s)))
(reverse (split-string dir "/")))))
(buffer-name (format "django-%s" project-name))
(manage (concat dir "manage.py")))
(cd dir)
(if (not (equal (buffer-name) buffer-name))
(switch-to-buffer-other-window
(apply 'make-comint buffer-name manage nil '("shell")))
(apply 'make-comint buffer-name manage nil '("shell")))
(make-local-variable 'comint-prompt-regexp)
(setq comint-prompt-regexp (concat py-shell-input-prompt-1-regexp "\\|"
py-shell-input-prompt-2-regexp "\\|"
"^([Pp]db) "))
(add-hook 'comint-output-filter-functions
'py-comint-output-filter-function)
;; pdbtrack
(add-hook 'comint-output-filter-functions 'py-pdbtrack-track-stack-file)
(setq py-pdbtrack-do-tracking-p t)
(set-syntax-table py-mode-syntax-table)
(use-local-map py-shell-map)
(run-hooks 'py-shell-hook))))