只是提个醒
2   Installation
2.1   Check the search paths

You should make sure that both Emacs and Python are usable, whatever the directory happens to be the current one. This is particularly important at the time Emacs launches Python under the scene, as Python ought to be found then started. On most systems, this means setting the search path correctly.

The following notes, for MS Windows, have been provided by Greg Detre.

  • After Start / Run / Cmd, type python. If this works wherever you are, then your Python installation directory is already in your system's PATH environment variable. If that's not the case, follow the instructions here to add it:

  • You may have to add the directory containing the Python scripts that you want to run through Pymacs to your PYTHONPATH variable, in the same fashion as above. You can test this by running Python, and then:

    import sys
    sys.path

    or just:

    import my_python_scripts

    from somewhere besides your scripts directory.

2.2   Edit the configuration file

In most cases, you may safely skip this step, as it is only needed in unusual, problematic circumstances. Merely check that none of the following applies to you.

2.3   Check if Pymacs would work

To know, before installing Pymacs, if it would work on your system, try the validation suite by running make check. The suite is fairly elementary, but nevertheless, it is able to detect some common show stoppers. To check a particular Emacs and Python combination, use make check EMACS=some_Emacs PYTHON=some_Python.

If PYTHON is left unset or empty, then the command for starting the Pymacs helper is python. Otherwise, it may be set to give the full path of the Python executable if it exists at some location outside the program search path. It may also be given when the interpreter name is different, for exemple when the Python version is part of the program name.

If EMACS is left unset or empty, then the command for starting the Emacs editor is emacs. For normal Pymacs usage, Emacs is launched by the user long before Pymacs is itself started, and consequently, there is absolutely no need to tell Pymacs which Emacs is needed. For the validation suite however, it may be set to give the full path of the executable if the Emacs program exists at some location outside the program search path. It may also be given when the editor name is different, for example when the Emacs version is part of the program name, or when this is a different editor. For example, make check EMACS=xemacs runs the validation suite using xemacs for an editor.

The remaining of this section may be safely be skipped for mere Pymacs installation.

I did not base the validation suite on Junit (the Python unit testing framework is a re-implementation of it), but on Codespeak's pylib py.test, which is much simpler, and still very powerful. The pylib project is driven by Holge Kregel, but attracted some Python brains, like Armin Rigo (known for Psyco, among other things -- I think his lsprof has also been added to Python 2.5 under the name cProfile). This gang addresses overdone/heavy methods in Python, and do them better. Even py.test is a bit more complex that I would want, and has (or at least had) flaws on the Unicode side, so I rewrote my own, as a simple single file. I merely translated it from French to English, to make it more distributable within Pymacs.

I initially tried using Emacs stdin and stdout for communicating expressions to evaluate and getting back results, from within the validation suite. This did not prove useful so, so after some fight, I reluctantly put this avenue aside. Currently, the suite writes problems in files, for Emacs to read, and Emacs writes replies in files, for the suite to check. Busy waiting (with small sleep added in the loops) is used on both sides. This is all too heavy, and it slows down the suite. Hopefully, the suite is not run often, this is not a real problem.

2.4   Install the Pymacs proper

Pymacs is a small package. Putting the documentation and administrative files aside, there is one Python file and one Emacs Lisp file to it, to be installed in turn. Always start with the Python file.

  • For the Python part

    From the top-level of the Pymacs distribution, execute make install. If the Python interpreter has a non-standard name or location, rather do make install PYTHON=Some_Python (see the previous section for a discussion). First, the script copies a few source files while configuring them: it presets the version string and the name of the Python interpreter, it also adapts the Python source code which might differ, for example, between Python 2 and Python 3. Second, it installs the Python package through the Python standard Distutils tool. To get an option reminder, do python setup.py install --help. Consult the Distutils documentation if you need more information about this.

    That's normally all to it. To check that pymacs.py is properly installed, start an interactive Python session and type from Pymacs import lisp: you should not receive any error.

    A special difficulty arises when the particular Python you use does not have Distutils already installed. In such a case, make install prints a warning, leaving to you the task of figuring out where the Pymacs/ directory is best copied, and making that copy.

  • For the Emacs part

    This is usually done by hand now. First select some directory along the list kept in your Emacs load-path, for which you have write access, and copy file pymacs.el in that directory.

    If you want speed, you should ideally byte-compile this file. To do so, go to that directory, launch Emacs, then give the command M-x byte-compile-file RET pymacs.el RET. If for some reason you intend to such commands often, you could create a little script to do so. Here is an example of such a script, assuming here that you use Emacs and want to install in directory ~/share/emacs/lisp/:

    #!/bin/bash
    cp pymacs.el ~/share/emacs/lisp/
    emacs -batch -eval '(byte-compile-file "~/share/emacs/lisp/pymacs.el")'

    You should be done now. To check that pymacs.el is properly installed, return to your usual directories, start Emacs and give it the command M-x load-library RET pymacs RET: you should not receive any error.

Some features from previous Pymacs releases have been dropped:

  • Environment variable PYMACS_EMACS is gone, and environment variable PYMACS_PYTHON is usually not needed.
  • There used to be a script for installing the Emacs Lisp file. As it was difficult to get it right in all circumstances; the script grew an interactive mode and lot of options. This is just not worth the complexity, so this script is now gone.
  • Examples were all installed automatically, but at least for some of them, this was more pollution than help. You may browse the contents of the contrib/ directory to learn about available examples.
2.5   Prepare your .emacs file

The .emacs file is not given in the distribution, you likely have one already in your home directory. You need to add these lines:

(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)
;;(eval-after-load "pymacs"
;; '(add-to-list 'pymacs-load-path YOUR-PYMACS-DIRECTORY"))

If you plan to use a special directory to hold your own Pymacs code in Python, which should be searched prior to the usual Python import search path, then uncomment the last two lines (by removing the semi-colons) and replace YOUR-PYMACS-DIRECTORY by the name of your special directory. If the file ~/.emacs does not exist, merely create it with the above lines. You are now all set to use Pymacs.

To check this, start a fresh Emacs session, and type M-x pymacs-eval RET. Emacs should prompt you for a Python expression. Try repr(2L**111) RET (rather use repr(2**111) RET if you are using Python 3). The mini buffer should display "2596148429267413814265248164610048L" (yet there is no L suffix in Python 3).

Let's do a second test. Whether in the same Emacs session or not, M-x pymacs-load RET should prompt you for a Python module name. Reply os RET RET (the second RET is for accepting the default prefix. This should have the effect of importing the Python os module within Emacs. Typing M-: (os-getcwd) RET should echo the current directory in the message buffer, as returned by the os.getcwd Python function.






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 可对当前文件进行调试.






转载-------------------------------

五一放假在家折腾了 Emacs 的 Python 编辑模式,分享一下。

1. 安装 pymacs

从 http://pymacs.progiciels-bpi.ca/ 下载 pymacs,解压,安装过程分两步。

1) python 部分的安装

进入 pymacs 目录,在命令行下执行
> python setup.py install
可以通过如下方法检验是否安装正确,进入 python 环境,执行
from Pymacs import lisp
如果没有报错,说明 pymacs 已经装上。

2) emacs 部分的安装

将 pymacs.el 文件复制到 emacs 安装目录的 /site-lisp/ 下,启动 emacs, 执行
M-x byte-compile-file RET pymacs.el RET
此命令将生成 pymacs.elc 文件。
可以通过如下方法检验是否安装正确,启动 emacs, 执行
M-x load-library RET pymacs RET

在 _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)

ok, 现在可以检查 pymacs 是否可用,启动 emacs, 执行
M-x pymacs-eval RET
emacs 将提示你输入 python 表达式,输入
repr(2L**111) RET
emacs 应该显示 "2596148429267413814265248164610048L"

2. 安装 pycomplete

将 python-mode.el 和 pycomplete.el 两个文件复制到 emacs/site-lisp/ 目录下
其中,
python-mode.el 从 http://www.rwdev.eu/python/pycomplete/python-mode.el 下载
pycomplete.el 从 http://www.rwdev.eu/python/pycomplete/pycomplete.el 下载

将 pycomplete.py 复制到 python 安装目录的 /site-packages/ 下
此文件从 http://www.rwdev.eu/python/pycomplete/pycomplete.py 下载

编辑 _emacs,添加以下几行代码:
(autoload 'python-mode "python-mode" "Python Mode." t)
(add-to-list 'auto-mode-alist '("\\.py\\'" . python-mode))
(add-to-list 'interpreter-mode-alist '("python" . python-mode))

(require 'pycomplete)

现在,所有的安装都已经完成了,可以试试 python 的自动补全,
输入 time.cl -> 按 TAB 键,emacs 将自动生成 time.clock
输入 time. -> 按 TAB 键,emacs 将列出所有可能的选项
输入 time.strftime( ,emacs 将提示 strftime(format[, tuple]) -> string

10-05 06:33