Build a powerful Python IDE in Emacs

Source: Internet
Author: User
Tags autoload

This article will introduce how to build a powerful Python IDE environment through various extensions in Emacs, includingSnippet tool, smart prompt, Automatic completion, reconstruction tool, debugging, and Gae debuggingAnd so on. The prerequisites for installing the following tools are that you have a certain understanding of the Emacs configuration file. All the relevant El files must be placed where load_path can be loaded.

1. yasnippet

Snippet tool. You can customize some templates, which are essential! After reading the following cool demo animation, you will understand:

Http://yasnippet.googlecode.com/files/yasnippet.avi

Installation Method:

( Require   ' Yasnippet)
(YAS/initialize)
(YAS/load-directory "~ /. Emacs. d/plugins/yasnippet-0.6.1c/snippets ")
2. AutoComplete

The Automatic completion tool will pop up a list box for you to select, just like in.

'

Installation Method:

( 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 " );;; Set a background color that looks better than above
(Define - Key AC - Completing - Map   " \ M-n "   ' Ac-next );;; Move down by M-N in the list
(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

Great refactoring tools, such as rename, move, and extract method. There are also good goto difinition (jump to definition), show documents (show document) and so on. You must install rope and pymacs before installing ropemacs.

RopeInstallation Method:

Python setup. py install

PymacsInstallation Method:

Python setup. py install

In. 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)

RopmacsInstallation Method:

Python setup. py install

In. emacs:

(Pymacs - Load " Ropemacs "   " Rope- " )
(Setq ropemacs - Enable - Autoimport T)
4. pycomplete

A more powerful smart reminder tool, such as inputting time. CL and then pressing the tab key, lists the function names starting with all CL in the time module. When calling a function, the parameter type of the function is also prompted in mini buffer. Install pymacs first.

Installation Method:

1. Copy the python-mode.el and pycomplete. El to the load_path of Emacs.

2. Copy pycomplete. pyPythonpath(For example, C :/Python25/lib/Site-packages)

3. Add the following to 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. PDB debugging

In Emacs, using M-x PDB, you can call up PDB for pythonCodeFor debugging. However, it is found that in windows, the debugging mode is always unavailable. The main reasons are:

1. In Windows, the location of PDB. py cannot be found. You need to customize the PDB path. You can set the path of the PDB using the following method:

; 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-using line activate)
"Provide a better default command line when called interactively ."
(Interactive
(List (gud-query-rows line PDB-Path
(File-name-nondirectory buffer-file-name )))))

2. In Windows, PDB is not used when it is called.Python-IParameters.

For the above two problems, my solution is not to set the specific PDB path. After M-x PDB returns, the following command is displayed:

Run PDB (like this): PDB

Then manually modify:

Run PDB (like this ): Python - I - M PDB test. py

This is done.

6. How to debug Gae Program

Gae is a Web application that requires cross-thread debugging, while PDB itself does not support thread debugging well. When using PDB for thread debugging, only Insert the following code where debugging is needed:

Import PDB
PDB. set_trace ()

Then run the code to be debugged directly, instead of executing the Code through Python PDB, You can debug the multi-threaded code.

However, for Web applications such as Google App Engine, this method still cannot be debugged. It is related to stdin and stdout. Finally, a good solution is found:

Def Set_trace ():
Import PDB, sys
Debugger = PDB. PDB (stdin = SYS. _ Stdin __ ,
Stdout = SYS. _ Stdout __ )
Debugger. set_trace (SYS. _ getframe (). f_back)

Call the above set_trace () function wherever debugging is required.

If you have more fun stuff, please let me know!

Reference:

Http://www.emacswiki.org/emacs/PythonMode

Http://www.enigmacurry.com/2008/05/09/emacs-as-a-powerful-python-ide/

http://jjinux.blogspot.com/2008/05/python-debugging-google-app-engine-apps.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.