安装平台 win7 x64 ,emacs 23.3.1
snippet工具,可自定义一些模板:
http://yasnippet.googlecode.com/files/yasnippet.avi
上面是演示demo
.emacs 配置如下
(add-to-list 'load-path "~/.emacs.d/yasnippet")
(require 'yasnippet) ;; not yasnippet-bundle
(yas/global-mode 1)
2. AutoComplete
自动完成工具,其实只是一个前端工具。当然也可以用ropemacs 作为它补全的后端使用。
.emacs 配置如下:
(add-to-list 'load-path "~/.emacs.d/")
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "~/.emacs.d//ac-dict")
(ac-config-default)
3. Python-mode
安装python-mode :
http://www.loveshack.ukfsn.org/emacs/#python.el 下载后直接丢到load-path 中
4.Rope and Ropemacs
Ropemacs非常棒的重构工具,比如rename,move,extract method等等。还有非常好用的goto difinition(跳到定义),show documents(显示文档)、代码补全等等。安装Ropemacs前,必须先安装rope和pymacs 实际上还要安装rope-mode。
rope的安装方法:
python setup.py install
pymacs的win上安装方法:
python pppp -C ppppconfig.py pppp.rst.in pymacs.el.in \ pymacs.rst.in Pymacs contrib tests
python setup.py install
注意此处:我git pymacs到本地后无法install成功,后来别人给一个pymacs包,我放在git的pymacs里,重新执行上面的安装方法后,成功。pymacs包见本文尾
如果成功,则在python环境中输入以下,不会报错:
from Pymacs import lisp
.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)
注意完成后,将下图552行的Pymacs.pymacs 改成Pymacs
Ropmacs的安装方法:
python setup.py install
.emacs中:
(require 'pymacs)
(pymacs-load "ropemacs" "rope-")
(setq ropemacs-enable-autoimport t)
注意:ropemacs时,先将ropemacs解压缩,然后将刚刚安装好的ropemode拷贝进去,再执行安装,否则会出错。C:\Python27\Lib\site-packages\ropemacs
基本操作
rope-code-assist, M-/
Code completionrope-rename, C-c r r
Rename a variable, function, etc.
5.程序调试
在Emacs中,通过M-x pdb可调出pdb对python代码进行调试。但是发现在Windows系统中,总进入不了调试模式。主要原因有:
1. windows中,找不到pdb.py位置。需自己制定pdb的路径。可以通过下面的方法设置pdb的路径:
;; pdb setup, note the python version
(setq pdb-path 'c:/python25/Lib/pdb.py
gud-pdb-command-name (symbol-name pdb-path))
(defadvice pdb (before gud-query-cmdline activate)
"Provide a better default command line when called interactively."
(interactive
(list (gud-query-cmdline pdb-path
(file-name-nondirectory buffer-file-name)))))
2. windows中,调用pdb时,未使用python -i 参数。
针对上面两个问题,我的解决办法是,不设置pdb具体路径,M-x pdb 回车后,出现下面命令:
Run pdb (like this): pdb
然后手动修改一下:
Run pdb (like this): python -i -m pdb test.py
6.代码检查
基本上都是flymake+pyflakes 或者 flymake +pylint模式,我选择了前者。并安装了pep8
flymake是emacs自带的,下载
pyflakes
pep8
c-c c-w是执行命令!
注意pyflakes 和pep8 都是在cmd中执行命令的。
;pycheck grammer ; indent something
(add-to-list 'load-path "~/.emacs.d/")
(add-hook 'find-file-hook 'flymake-find-file-hook)
(when (load "flymake" t)
(defun flymake-pyflakes-init ()
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace))
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))
(list "pychecker" (list local-file))))
(add-to-list 'flymake-allowed-file-name-masks
'("\\.py\\'" flymake-pyflakes-init)))
(load-library "flymake-cursor")
;(global-set-key [f10] 'flymake-goto-prev-error)
;(global-set-key [f11] 'flymake-goto-next-error)
(setq python-check-command "pyflakes")
然后创建一个pychecker.bat的文档 丢到python里面,我的目录是c:\python27
python C:\Python27\runpyflakes.py %*
pep8 --ignore=E221,E701,E202 --repeat %*
再在该目录创建一个runpyflakes.py的程序
from pyflakes.scripts.pyflakes
import mainmain()
效果如下:
7.文档帮助
我还是喜欢firefox直接上官方文档库查找。
emacs wiki 也给出了sphinx后格式的文档下载,可以直接在emacs info里查看帮助。
具体链接请见本文末尾处
效果可以看最后一个链接。
8.段落注解:
Comment/Uncomment Region
If you have ‘transient-mark-mode’ on, you can just use ‘comment-dwim’:
select a region and hit ‘M-;’.
The DoWhatIMean means that it will comment or uncomment the region
as
appropriate.
If you
do
not have ‘transient-mark-mode’ on by
default
, you can hit C-SPC twice to activate it temporarily.
( doesn’t python-mode.el offer `py-comment-region? --CH )
You can also use “rectangles” with comment/uncomment region (among other things that you can
do
with rectangles).
See RectangleCommands or “(emacs) Rectangles”
in
the Emacs manual.
9.框架支持
django:
https://code.djangoproject.com/wiki/Emacs"
如果不是很熟悉的话,还是建议用pycharm来写吧。
10.测试
待完善,下面的link中含有。