当前位置:  开发笔记 > 编程语言 > 正文

如何从Emacs运行django shell?

如何解决《如何从Emacs运行djangoshell?》经验,为你挑选了1个好方法。

我希望能够./manage.py shell在Emacs缓冲区中运行,包含你从ipython获得的所有好东西,比如魔术命令和自动完成.理想情况下,我还希望能够将缓冲区中的代码计算到django shell.

这可能吗?



1> Ryszard Szop..:

好的,所以我今天自己砍了这个.它的一个主要部分是复制和粘贴来自py-shellpython-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))))

推荐阅读
手机用户2402852307
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有