好的,所以我今天自己砍了这个.它的一个主要部分是复制和粘贴来自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))))
Run Code Online (Sandbox Code Playgroud)
它不会工作在shell?我刚刚成功在 emacs 中启动了 django shell 会话。
点击M-x shell然后在 bash shell 会话中启动 python shell,如下所示:
M-x shell
Run Code Online (Sandbox Code Playgroud)
贝壳产生
prompt> cd path/to/my/django/directory
prompt> python manage.py shell
Python 2.6.1 (r261:67515, Jul 7 2009, 23:51:51)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>>
Run Code Online (Sandbox Code Playgroud)
它应该会打开一个 django shell,就像您在裸终端中工作一样,但它是 Emacs 中的另一个缓冲区。
至于集成(将代码发送到 shell 进行评估等),您似乎可以在此处的页面底部找到您正在寻找的内容(Emacs Wiki for python.el)。那里有很多关于让 iPython 与 python.el 一起工作的信息,您可以通过修改那里或 python.el 中的代码来运行您的 django shell。