私は./manage.py shell
をEmacsバッファに入れたいと思っています。魔法のコマンドやオートコンプリートのような、ipythonから得られるすてきなものをすべて使えます。理想的には、バッファからdjangoシェルまでのコードを評価することもできます。Emacsからdjangoシェルを実行するには?
これは可能ですか?
私は./manage.py shell
をEmacsバッファに入れたいと思っています。魔法のコマンドやオートコンプリートのような、ipythonから得られるすてきなものをすべて使えます。理想的には、バッファからdjangoシェルまでのコードを評価することもできます。Emacsからdjangoシェルを実行するには?
これは可能ですか?
shell
で動作しませんか?私は今すぐemacsに行くジャンゴシェルセッションを取得することができました。
はM-x shell
をヒットしてからのようなので、そのbashシェルセッション中にあなたのpythonシェルを起動します。
M-x shell
シェルは
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)
>>>
を生成しますし、それはちょうどあなたかのようにDjangoのシェルを起動する必要があり裸の端末で動作していますが、Emacsのもう一つのバッファです。
インテグレーション(評価するシェルにコードを送信するなど)では、ページ下部のhere (Emacs Wiki for python.el)で探しているものを見つけることができるようです。 iPythonをpython.elで動作させる方法についてはたくさんの情報があります。そこにあるコードをpython.elで変更することでdjangoシェルを実行することができます。
ansi-term
を使用すると、ipythonのタブ補完作業が行われますが、C-x [...]
のキーバインディングはすべてC-c [...]
に再マップされます。
(defun start-my-ipython-term()
(interactive)
(ansi-term "/usr/bin/ipython"))
(global-set-key (kbd "<your keybinding here>") 'start-my-ipython-term)
OK、私は今日自分でこれをハッキング:
あなたがそれを好きなら、あなたは簡単にあなたの.emacsにこれを置くことによって、それのためのキーバインドを作成することができます。その大部分は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))))
私は単純に代わりのipythonシェルスクリプトを作成しました。
私はpython-mode.elとipython.elを使用します。関連.emacs.elフラグメントは、このように書きます:
#!/bin/sh
set -e
/bin/echo -n "Select Django project/dir, or press enter for plain ipython: "
read selection
case $selection in
'') exec ipython ;;
project) cd /Users/japhy/Projekty/some/project/dir ;;
# other often used projects go here
*) cd $selection ;;
esac
exec python manage.py shell
これはかなり古い質問ですが、それはおそらくまだ誰かのために便利です:smart_ipythonスクリプトは次のようになります
(setq ipython-command "/Users/japhy/bin/smart_ipython") (require 'ipython) ;; fix completion for ipython 0.10 (setq ipython-completion-command-string "print(';'.join(__IP.Completer.all_completions('%s'))) #PYTHON-MODE SILENT\n")
。私はこれを行うための最も簡単な方法は、私の.emacsに以下を追加することであることがわかりました
(setq python-shell-interpreter "python"
python-shell-interpreter-args "-i /absolute/path/to/manage.py shell_plus")
そのあとのpython-シェル・インタプリタのコマンドのいずれかを使用することができ、すべてが代わりにDjangoのシェルで実行されます通常のPythonインタープリタを使用します。
私はhereについてのブログ記事を書いています。
スワップするたびに設定を変更せずに複数のdjangoプロジェクトで動作する最適なソリューションはpython-django.el
に加え、ディレクトリローカル変数の正しい設定です。
のpython-djangoのは、それは常にプロジェクト内のときDjangoのシェルを起動するために取得するにはなど
をコマンドを実行するのと同じように、生活の改善の多くの小さな品質で、Djangoのユーザのためにpython.elするための素晴らしい付加でありますプロジェクトのルートに.dir-locals.el
ファイルを作成して、適切なディレクトリローカル変数を設定する必要があります。この設定は.dir-locals.el
ファイルに使用できます。クリティカルな部分は、あなたのプロジェクトのpython-shell-interpreter argsをmanage.py shell
に設定することです。
((python-mode
(python-shell-interpreter . "python")
(python-shell-interpreter-args . "/home/youruser/code/yourproject/manage.py shell")
(python-shell-prompt-regexp . "In \\[[0-9]+\\]: ")
(python-shell-prompt-output-regexp . "Out\\[[0-9]+\\]: ")
(python-shell-completion-setup-code . "from IPython.core.completerlib import module_completion")
(python-shell-completion-module-string-code . "';'.join(module_completion('''%s'''))\n")
(python-shell-completion-string-code . "';'.join(get_ipython().Completer.all_completions('''%s'''))\n")
(python-shell-extra-pythonpaths "/home/youruser/code/yourproject/apps/")
(python-shell-virtualenv-path . "/home/youruser/.virtualenvs/yourproject")))
`` `
設定は、プロジェクトの著者によってfrom this blogpost取られます。
私はipythonバッファを起動するのに問題はありません。 'manage.py shell'バッファが必要です。 ansi-termでは、実行するプログラムに引数を渡すことはできません。 –