[HOME]: [Mac OS X]: [MacPython]: [Emacs]: [生存報告記]: [MacEmacs JP Project]: [NTEmacs JP Project]:

概要

Emacs上でのPython開発環境を構築する手順を含めてpython-modeの使い方など。

2つのPython用モード

Python用モードとしては Emacs22から標準搭載の python.el と 昔からある python-mode.el の2種類が存在しています。

python-mode.el の方が機能としては高機能ですし、歴史が長いここともありサポートしている関連モードが多いです。

python.el はやや機能的に不足している部分も存在しますが、設定が比較的簡単で、Emacsが標準でサポートしているのが楽です。

http://www.emacswiki.org/emacs/PythonMode

python-mode.el

https://launchpad.net/python-mode/

http://svn.python.org/view/python/trunk/Misc/python-mode.el?view=log

Pymacs

README file for Pymacs

tar xvfz Pymacs.tar.gz
cd Pymacs
sudo python setup.py install

環境によってはパスの設定とかが必要な場合があるけど割愛

.emacsに以下を設定

(require 'pymacs)
(autoload 'pymacs-apply "pymacs")
(autoload 'pymacs-call "pymacs")
(autoload 'pymacs-eval "pymacs" nil t)
(autoload 'pymacs-exec "pymacs" nil t)
(autoload 'pymacs-load "pymacs" nil t)

Emacs上での動作確認

M-x pymacs-eval RET
repr(2L**111) RET
"2596148429267413814265248164610048L"
M-x pymacs-load RET
os RET RET
M-: (os-getcwd) RET

以下の機能が利用できる。

pymacs-exec
(pymacs-exec text)でtextをPythonの文として評価
pymacs-eval
(pymacs-eval text)でtextをPythonの式として評価
pymacs-call
(pymacs-call "function")とか(pymacs-call "function" "arg1" "arg2")みたいにしてpythonの関数を呼びだす
pymacs-apply
callと似た感じ。引数のリストを必須とする。何も渡さない時はnillを書く。(pymacs-apply "function" nil)とか(pymacs-apply "function" ("arg1" "arg2"))な感じ
pymacs-load
(pymacs-load module prefix)のような感じでモジュールのimportができる

ipython.el

FrontPage - IPython

;; ipython
(setq ipython-command "/usr/local/bin/ipython")
(require 'ipython)

http://www.emacswiki.org/emacs/anything-ipython.el

http://ipython.scipy.org/doc/manual/html/config/editors.html

http://ipython.scipy.org/moin/Cookbook/IPythonEmacs23

文法チェック

速度を求めるか、厳密さを求めるかで選択すると良い

補完

ropemacs

http://pypi.python.org/pypi/ropemacs

http://sourceforge.net/projects/rope/files/

pysmell

その他

mattharrison's pycoverage.el at master - GitHub

Emacs上でソース探険

etagsを利用する。

find . -name "*.[ch]" -print | etags - 
find . -name "*.py" -print | etags -a - 

とりあえずPythonのソースコードでこれやってTAGS作成。M-.で検索とかして読んでいる。

参考

http://richardriley.net/projects/emacs/dotprogramming

Setup Perfect Python Environment In Emacs « The website of Lei Chen


EmacsLispPythonLanguage CategoryPrograming CategoryEmacs CategoryPython