再转一篇关于emacs+python的好blog
转自:http://www.cnblogs.com/coderzh/archive/2009/12/26/emacspythonide.html
--------------------------------------------------------------------------------------------
本文将介绍,在Emacs中,通过各种扩展,打造强大的Python IDE环境,包括Snippet工具,智能提示,自动补全,重构工具,调试以及GAE的调试,等等。以下各工具的安装前提是你对Emacs的配置文件有一定的了解,所有相关的el文件都必须放在load_path能够加载的地方。
snippet工具,可自定义一些模板,必不可少的好东西!看了下面这个很酷的演示动画就明白了:
http://yasnippet.googlecode.com/files/yasnippet.avi
安装方法:
(require'yasnippet)
(yas/initialize)
(yas/load-directory"~/.emacs.d/plugins/yasnippet-0.6.1c/snippets")
自动完成工具,会像VS里一样,弹出一个列表框让你去选择。
'
安装方法:
(require'auto-complete)
(require'auto-complete-config)
(global-auto-complete-modet)
(setq-defaultac-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-keyac-completing-map"\M-n"'ac-next);;;列表中通过按M-n来向下移动
(define-keyac-completing-map"\M-p"'ac-previous)
(setqac-auto-start2)
(setqac-dwimt)
(define-keyac-mode-map(kbd"M-TAB")'auto-complete)
非常棒的重构工具,比如rename,move,extract method等等。还有非常好用的goto difinition(跳到定义),show documents(显示文档)等等。安装Ropemacs前,必须先安装rope和pymacs。
rope的安装方法:
pymacs的安装方法:
.emacs中:
(autoload'pymacs-apply"pymacs")
(autoload'pymacs-call"pymacs")
(autoload'pymacs-eval"pymacs"nilt)
(autoload'pymacs-exec"pymacs"nilt)
(autoload'pymacs-load"pymacs"nilt)
Ropmacs的安装方法:
.emacs中:
(pymacs-load"ropemacs""rope-")
(setqropemacs-enable-autoimportt)
一个更加强大的智能提示工具,比如,输入time.cl 然后按TAB键,会列出time模块所有cl开头的函数名。在调用函数时,还会在mini buffer中提示函数的参数类型。这个东西需要先安装pymacs。
安装方法:
1. 拷贝python-mode.elandpycomplete.el到Emacs的load_path中。
2. 拷贝pycomplete.py到PYTHONPATH(比如:
c:/python25/Lib/site-packages)
3. .emacs中添加:
(require'pycomplete)
(setqauto-mode-alist(cons'("\\.py$".python-mode)auto-mode-alist))
(autoload'python-mode"python-mode""Pythoneditingmode."t)
(setqinterpreter-mode-alist(cons'("python".python-mode)
interpreter-mode-alist))
5. pdb调试
在Emacs中,通过M-x pdb可调出pdb对python代码进行调试。但是发现在Windows系统中,总进入不了调试模式。主要原因有:
1. windows中,找不到pdb.py位置。需自己制定pdb的路径。可以通过下面的方法设置pdb的路径:
;;pdbsetup,notethepythonversion
(setqpdb-path'c:/python25/Lib/pdb.py
gud-pdb-command-name(symbol-namepdb-path))
(defadvicepdb(beforegud-query-cmdlineactivate)
"Provideabetterdefaultcommandlinewhencalledinteractively."
(interactive
(list(gud-query-cmdlinepdb-path
(file-name-nondirectorybuffer-file-name)))))
2. windows中,调用pdb时,未使用python -i参数。
针对上面两个问题,我的解决办法是,不设置pdb具体路径,M-x pdb 回车后,出现下面命令:
然后手动修改一下:
Runpdb(likethis):python-i-mpdbtest.py
这样就搞定了。
6. 如何调试GAE程序
GAE是一个Web应用,需要跨线程进行调试,而pdb本身对线程调试支持不好。使用pdb进行线程调试时,只有在需要调试的地方插入下面代码:
importpdb
pdb.set_trace()
然后直接运行被调试代码,而不是通过python pdb来执行,就可以多线程代码进行调试了。
但是Google App Engine这样的Web应用,使用这个方法还是不能调试,和stdin和stdout有关,最后找到一个很好的解决方法:
defset_trace():
importpdb,sys
debugger=pdb.Pdb(stdin=sys.__stdin__,
stdout=sys.__stdout__)
debugger.set_trace(sys._getframe().f_back)
在任何需要调试的地方,调用上面的set_trace()函数。
分享到:
相关推荐
docker-vscode:具有Visual Studio Code + Dotnet CLI + NPM + Emacs +的... docker-vscode:具有Visual Studio Code + Dotnet CLI + NPM + Emacs +的Docker映像! docker-vscode:具有Visual Studio Code + ...
Learning_GNU_Emacs_Third_Edition.chm Linux.Commands.Editors.and.Shell.Programming.chm Managing+Projects+with+GNU+Make.pdf O'Reilly.Bash.Cookbook.May.2007.pdf Prentice.Hall.Linux.Debugging.and....
emacs ecb cedet源码包 包括: emacs-23.4.tar.gz emacs-24.3.tar.gz ecb-2.40.zip cedet-1.0.1.tar.gz cedet-1.1.tar.gz
本压缩包包括了:living in emacs, survive in emacs & gnu emacs pocket referrence. 希望大家喜欢
如何在windows下安装coq,并且使用emacs+proofgeneral进行编辑运行。
emacs-python工具及配置
emacs+auctex 写tex文件的利器
Learning_GNU_Emacs_Third_Edition.chm Linux.Commands.Editors.and.Shell.Programming.chm Managing+Projects+with+GNU+Make.pdf O'Reilly.Bash.Cookbook.May.2007.pdf Prentice.Hall.Linux.Debugging.and....
emacs搭建python开发环境(包括一个VIM的perl支持)。
Learning_GNU_Emacs_Third_Edition.chm Linux.Commands.Editors.and.Shell.Programming.chm Managing+Projects+with+GNU+Make.pdf O'Reilly.Bash.Cookbook.May.2007.pdf Prentice.Hall.Linux.Debugging.and....
Learning_GNU_Emacs_Third_Edition.chm Linux.Commands.Editors.and.Shell.Programming.chm Managing+Projects+with+GNU+Make.pdf O'Reilly.Bash.Cookbook.May.2007.pdf Prentice.Hall.Linux.Debugging.and....
Learning_GNU_Emacs_Third_Edition.chm Linux.Commands.Editors.and.Shell.Programming.chm Managing+Projects+with+GNU+Make.pdf O'Reilly.Bash.Cookbook.May.2007.pdf Prentice.Hall.Linux.Debugging.and....
emacs-python-environment, 用于 Emacs Lisp的python virtualenv API 用于 Emacs Lisp的 python-virtualenv API链接:存储库( 位于 GitHub )问题跟踪程序( 位于 GitHub )Travis CI MELPA MELPA稳定 Emacs与使
Learning_GNU_Emacs_Third_Edition.chm Linux.Commands.Editors.and.Shell.Programming.chm Managing+Projects+with+GNU+Make.pdf O'Reilly.Bash.Cookbook.May.2007.pdf Prentice.Hall.Linux.Debugging.and....
Learning_GNU_Emacs_Third_Edition.chm Linux.Commands.Editors.and.Shell.Programming.chm Managing+Projects+with+GNU+Make.pdf O'Reilly.Bash.Cookbook.May.2007.pdf Prentice.Hall.Linux.Debugging.and....
emacs python-moemacs python-mode 及使用方法de 及使用方法
Learning_GNU_Emacs_Third_Edition.chm Linux.Commands.Editors.and.Shell.Programming.chm Managing+Projects+with+GNU+Make.pdf O'Reilly.Bash.Cookbook.May.2007.pdf Prentice.Hall.Linux.Debugging.and....
Learning_GNU_Emacs_Third_Edition.chm Linux.Commands.Editors.and.Shell.Programming.chm Managing+Projects+with+GNU+Make.pdf O'Reilly.Bash.Cookbook.May.2007.pdf Prentice.Hall.Linux.Debugging.and....
emacs python 扩展包
elpy, Emacs python 开发环境 Elpy,Emacs Lisp python-环境Elpy是一个Emacs软件包,可以为Emacs带来强大的python 编辑功能。 它组合并配置了一些它的他软件包,这两个软件包都是用,以及 python 编写的。 文档El