Emacs搭建Python开发环境
1. YASnippet
snippet工具,可自定义一些模板,必不可少的好东西!看了下面这个很酷的演示动画就明白了:
http://yasnippet.googlecode.com/files/yasnippet.avi
安装方法:
(require 'yasnippet)
(yas/initialize)
(yas/load-directory "~/.emacs.d/plugins/yasnippet-0.6.1c/snippets")
2. AutoComplete
自动完成工具,会像VS里一样,弹出一个列表框让你去选择。'
安装方法:
(require 'auto-complete)
(require 'auto-complete-config)
(global-auto-complete-mode t)
(setq-default ac-sources '(ac-source-words-in-same-mode-buffers))
(add-hook 'emacs-lisp-mode-hook (lambda () (add-to-list 'ac-sources 'ac-source-symbols)))
(add-hook 'auto-complete-mode-hook (lambda () (add-to-list 'ac-sources 'ac-source-filename)))
(set-face-background 'ac-candidate-face "lightgray")
(set-face-underline 'ac-candidate-face "darkgray")
(set-face-background 'ac-selection-face "steelblue")
(define-key ac-completing-map "\M-n" 'ac-next)
(define-key ac-completing-map "\M-p" 'ac-previous)
(setq ac-auto-start 2)
(setq ac-dwim t)
(define-key ac-mode-map (kbd "M-TAB") 'auto-complete)
3. Rope and Ropemacs
非常棒的重构工具,比如rename,move,extract method等等。还有非常好用的goto difinition(跳到定义),show documents(显示文档)等等。安装Ropemacs前,必须先安装rope和pymacs 。
安装rope,http://rope.sf.net/:
python setup.py install
安装Pymacs, http://pymacs.progiciels-bpi.ca/pymacs.html
python setup.py install
安装ropemode, http://pypi.python.org/pypi/ropemode
python setup.py install
安装ropemacs,http://rope.sourceforge.net/ropemacs.html
python setup.py install
在Emacs配置文件中加入
(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)
(pymacs-load "ropemacs" "rope-")
(setq ropemacs-enable-autoimport t)
4. pycomplete
一个更加强大的智能提示工具。这个东西需要先安装pymacs。
安装方法:
1. 拷贝 python-mode.el and pycomplete.el 到Emacs的load_path中。
2. 拷贝 pycomplete.py 到PYTHONPATH (比如: c:/python26/Lib/site-packages)
3. .emacs中添加:
(require 'pycomplete)
(setq auto-mode-alist (cons '("\\.py$" . python-mode) auto-mode-alist))
(autoload 'python-mode "python-mode" "Python editing mode." t)
(setq interpreter-mode-alist(cons '("python" . python-mode)
interpreter-mode-alist))
5.Python调试
按alt+X 输入python –i –m pdb 文件名.py 可对当前文件进行调试.