参考文章:http://www.cnblogs.com/coderzh/archive/2009/12/26/emacspythonide.html
用emacs中进行python开发,总是感觉有点力不从心。按照网上的教程对于emacs进行了改造。先用着再说吧!
使用的插件有YASnippet, autocomplete, Rope and Ropemacs, pycomplete, electric等
对于YASnippet和autocomplete来说:具体安装不写了,请参考网上文章: http://www.oschina.net/question/54100_56621(就是因为这篇文章才走上了不归路)
1. YASnippet
snippet工具,可自定义一些模板,必不可少的好东西!这个不多说吧,直接上emacs配置吧!
1 ;;;;;;;;;;;;;yasnippet;;;;;;;;;;;;;;;;;;;;;2
3 (add-to-list 'load-path
4 "/home/huihui/.emacs.d/plugins/yasnippet")5 (require 'yasnippet)
6 (yas-global-mode 1)
2. autocomplete
自动完成工具,会像VS里一样,弹出一个列表框让你去选择。
直接上emacs配置
1 ;;;;;;;;;;;;;auto-complete;;;;;;;;;;;;;;;;;;;;;2 (add-to-list 'load-path "/home/huihui/.emacs.d/plugins/auto-complete")
3 (require 'auto-complete-config)
4 (add-to-list 'ac-dictionary-directories "/home/huihui/.emacs.d/plugins/auto-complete/ac-dict")
5 (ac-config-default)6
7 (require 'auto-complete)
8 (require 'auto-complete-config)
9 (global-auto-complete-mode t)10 (setq-default ac-sources '(ac-source-words-in-same-mode-buffers))
11 (add-hook 'emacs-lisp-mode-hook (lambda () (add-to-list'ac-sources 'ac-source-symbols)))
12 (add-hook 'auto-complete-mode-hook (lambda () (add-to-list'ac-sources 'ac-source-filename)))
13 (set-face-background 'ac-candidate-face "lightgray")
14 (set-face-underline 'ac-candidate-face "darkgray")
15 (set-face-background 'ac-selection-face "steelblue")
16 ;;; 设置比上面截图中更好看的背景颜色17 (define-key ac-completing-map "\M-n" 'ac-next)
18 ;;; 列表中通过按M-n来向下移动19 (define-key ac-completing-map "\M-p" 'ac-previous)
20 (setq ac-auto-start 2)21 (setq ac-dwim t)22 (define-key ac-mode-map (kbd "M-TAB") 'auto-complete)
3. Rope and Ropemacs
安装方式,我使用的是easy_install进行的安装rope和ropemacs
#/usr/local/python2.7/bin/easy_install rope#/usr/local/python2.7/bin/easy_install ropemacs
安装 pymacs ,使用的是网上下载的Pymacs-master.zip
1 #unzip Pymacs-master.zip
2 #cd Pymacs-master
3 #make install
4 #mkdir /home/huihui/.emacs.d/plugins/pymacs/
5 #cp pymacs.el /home/huihui/.emacs.d/plugins/pymacs/pymacs.el
emacs中的配置
(add-to-list 'load-path
"/home/huihui/.emacs.d/plugins/pymacs")
(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)
(pymacs-load "ropemacs" "rope-")
(setq ropemacs-enable-autoimport t)
4. pycomplete
一个更加强大的智能提示工具,比如,输入time.cl 然后按TAB键,会列出time模块所有cl开头的函数名。在调用函数时,还会在mini buffer中提示函数的参数类型。这个东西需要先安装pymacs。
安装方法:
2. 拷贝 pycomplete.py 到PYTHONPATH (比如: c:/python25/Lib/site-packages)
操作步骤:
1 #wget http://www.rwdev.eu/python/pycomplete/pycomplete.el
2 #wget http://www.rwdev.eu/python/pycomplete/python-mode.el
3 #cp *.el /home/huihui/.emacs.d/plugins/pycomplete/
4 #wget http://www.rwdev.eu/python/pycomplete/pycomplete.py
5 #cp pycomplete.py /usr/local/python2.7/lib/python2.7/site-packages/
emacs中配置:
1 ;;;;;;;;;pycomplete;;;;;;;;;;;;;;2 (add-to-list 'load-path
3 "/home/huihui/.emacs.d/plugins/pycomplete")4 (require 'pycomplete)
5 (require 'python-mode)
6 (setq auto-mode-alist (cons '("\\.py$" . python-mode) auto-mode-alist))
7 (setq interpreter-mode-alist (cons '("python" . python-mode)
8 interpreter-mode-alist))9 (autoload 'python-mode "python-mode" "Python editing mode." t
5. electric
对于这个模块其实不想说,但是在python编辑模式中使用它,每次都好心办坏事,需要在emacs配置中禁用其中的自动缩进
1 ;;;;;;;;;; 自动缩进;;;;;;;;;;;;;;;;;;;;;;;2 ;;; 但是在python里面这个特别的不好用。3 (require 'electric)
4 ;(electric-indent-mode t)5 (electric-pair-mode t)6 (electric-layout-mode t)