TODO: not work?
not work?
default key-bindings: M-TAB
(=complete-symbol)
default key-bindings: M-TAB
(completion-at-point
)
(if you set tab-always-indent
to complete
, you can use TAB
for completion.)
default key-bindings: M-TAB
(completion-at-point
)
(if you set tab-always-indent
to complete
, you can use TAB
for completion.)
Emacs 24 uses fgnallina’s python.el, which won’t auto-eval import statements in your python code. To
get module members, you need to start python shell (via M-x run-python
) first and import modules
in the shell by yourself.
tested on emacs-23.1 & 24.1.
(defun ac-py-complete-document (symbol)
(py-complete-exec (format "print help(%s)\n" symbol)))
(setq ac-source-py-complete
'( (candidates . (py-complete-completions ac-prefix))
(prefix . "[ \t\n['\",()]\\([^\t\n['\",()]+\\)\\=") ;;py-complete-completion-re
(symbol . "p-c")
(document . ac-py-complete-document)))
part of python-mode.el.
pycomplete.el + pycomplete.py + pymacs
note:
- requires pymacs
cons:
- only works on python-mode.el
https://github.com/pdee/pdee/blob/master/auto-complete-pycomplete.el
part1: http://mail.python.org/pipermail/python-mode/2012-July/001508.html part2: http://mail.python.org/pipermail/python-mode/2012-July/001515.html
https://github.com/pdee/pdee/blob/master/extensions/pycompletemine.el
it works on python.el & python-mode.el
- EmacsPythonCompletion - PythonInfo Wiki (Oct 16, 2003)
- an improved version: http://hg.rooijan.za.net/addons/file/01fe1d4368ed/progmodes/py-complete.el
features:
C-return
: completion using minibufferpy-complete-try-complete-symbol
forhippie-expand
- showing documentation on module, class, method name when pressing F1
- showing function/method signature on
F2
,(
or,
pros:
- single file needed (even pymacs not needed)
- to get better completion, you can send some region of code to the python shell
cons:
- only works on python-mode.el
https://github.com/fgallina/gpycomplete
gpycomplete is a python code autocompletion and helper suite for GNU/Emacs. It feels like having ipython in your buffer.
gpycomplete is written from scratch by Fabián E. Gallina, althought some functions (namely get_help and get_signature) are strongly inspired in the original pycomplete package that was available at http://python-mode.sf.net.
The main feature of gpycomplete is that the completions it returns are actually what the python interpreter running in the background has available in its context. This is what makes gpycomplete so powerful and what it gives the feel of using ipython.
based on jedi, epc, auto-complete
(python-describe-symbol symbol)
Symbol may be anything recognized by the interpreter’s `help’ command – e.g. `CALLS’ – not just variables in scope in the interpreter.
pycomplete’s sub-features
py-complete-help-thing-at-point py-complete-electric-lparen py-complete-electric-comma py-complete-signature-expr py-complete-help
References:
- Linux查看本地Python文档 - Regding - 7hink different
- another workaround is to execute pydoc as suggested by Nikokrock directly in Emacs
https://github.com/syohex/emacs-helm-pydoc
For python <= 2.5, info document for python is included in the python release packages. http://packages.debian.org/squeeze/python2.5-doc
But with python 2.6’s switching to sphinx as documentation tool, the texinfo document no longer provided with python official releases.
You can generate texinfo documents following these info: http://stackoverflow.com/questions/1054903/how-do-you-get-python-documentation-in-texinfo-info-format http://bitbucket.org/jonwaltman/sphinx-info http://bitbucket.org/jonwaltman/rst2texinfo/src
pros:
- no external browser needed
- emacs already has a query system for info index (info-lookup-symbol (C-h S))
cons:
- info format not officially distributed with python-2.6 & 2.7
- `info-lookup-add-help’ is a little complicated to add new info index
- `python-after-info-look’ of loveshack’s python.el
- pydoc-info
https://bitbucket.org/jonwaltman/pydoc-info/
advantages:
- info document for python-2.7 already provided with pydoc-info
- you can add other sphinx-based documents to lookup
disadvantages:
- for python versions other than 2.7, you need to generate info document by yourself (or just use info files for python-2.7 provided by pydoc-info
with pdb:
- With your Python program on buffer, type M-x pdb. It would ask if you want to run PDB like, pdb a.out. Replace a.out with your Python module name. In the screenshot, it is adder.py (doing nothing useful).
- This opens a new PDB windows (Screenshot)
- Go to the lines where you need breakpoint, type C-x (you can notice the screenshot for the statement about it). If you are using Ubuntu, you get a very good look-n-feel, like that screenshot.
- Type c on the PDB buffer to run upto the breakpoint
- From the breakpoint, n for next line or s to explore into functions on that line. In Ubuntu, you’d have a GUI to assist you.
- To watch a variable, type p var, as in the screenshot.
- Any time during debugging, w prints out the stack and u and d lets you go up and down the stack.
For most of the standalone Python script, this would improve your productivity a lot. You can do more complex debug operations, but this is a very good start.
Virtualenv.el (something similar is included in python-mode.el
- Matt McClure | Python Development In A VM Using Emacs And Virtualenv (2012-06-05)
- Matt McClure | Using Python Virtualenvs Over Emacs TRAMP Is Getting Simpler (2012-07-23)
- Matt McClure | Update: Refactoring Python In Emacs Remote Virtualenvs
http://virtualenvwrapper.readthedocs.org/en/latest/extensions.html#emacs-desktop
- Using Pymacs and virtualenv together (slacy.com)
- How to use Rope to automatically change virtualenv for you
- Ropemacs and virtualenv (almostobsolete.net)
http://rope.sourceforge.net/ropemacs.html
Ropemacs is a plugin for performing python refactorings in emacs. It uses rope library and pymacs. You should install rope library, ropemode and pymacs before using ropemacs.
Features
Supports many of the refactorings that are supported by rope_ library:
- Rename
- Extract method/local variable
- Move class/function/module/package/method
- Inline method/local variable/parameter
- Restructuring
- Change signature
- …
Other refactoring-related features:
- Previewing refactorings
- Undo/redo refactorings
- Showing refactoring progress
Code-assists:
- Code-completion
- Goto definition
- Show pydoc
- Find occurrences
- Organize imports (remove unused and duplicate imports and sort them)
- Generating python elements
Traad is a client-server approach to using the rope Python refactory library. It involves two basic components:
- An XMLRPC server exposing the rope API, and
- Client libraries (currently just emacs lisp) for talking to the server
- EmacsWiki: Python Programming In Emacs
- Emacs as a powerful Python IDE - EnigmaCurry (May 09, 2008)
- Setup Perfect Python Environment In Emacs « The website of Lei Chen (Jan 30, 2009)
- My Emacs Python environment << SaltyCrane Blog (May 10, 2010, Updated at Apr 24, 2011)
- Configuring Emacs as a Python IDE - Pedro Kroger (Jul 15, 2010)
- emacs as python ide | coder . cl (Sep 30, 2010)
- Neuroimaging in Python — Community Page (Jul 23, 2011)
- Emacs for Python Programming - Vinod Kurup (Oct 24, 2012)
- Emacs中打造强大的Python IDE - CoderZh - 博客园 (Dec 26, 2009)
- Enjoy Python under Emacs - Justin’s Blog (Mar 28, 2010)
https://github.com/gabrielelanaro/emacs-for-python
https://github.com/pdee/pdee Based on emacs-for-python
- Code completion (using auto-complete and rope)
- Indentation highlighting (using highlight-indentation)
- Snippet Expansion (using yasnippet and auto-complete)
- Code hinting (using eldoc and rope)
- Code Navigation (using rope and python.el)
- Inline Documentation (using rope)
- On-the-fly checks (using flymake)
- Virtualenv support (using virtualenv)
- Python web documentation
- Refactoring (using rope)
- Easy IPython support for those who use it
cons:
- it requires emacs-24
- empetado
https://github.com/haplo/empetado
empetado stands for EMacs Python Enhanced Tight Ass DOmination. It’s a funny word in Spanish, but you won’t find it in your usual dictionary. Let’s just say that it refers to this configuration being full of coolness, awesomeness and wonderfulness.
empetado is basically my emacs configuration, anything I find useful will probably find its way here. The first thing I wanted to have was good Python support (hint: it didn’t come first, nor second, nor third…), but there are more things in there, like git and subversion support, org-mode, ido/smex, yasnippet, desktop-mode, EMMS…
based on emacs-for-python. There’re seems no too much added value.
(emacs-24 uses fgallina’s python.el)
https://launchpad.net/python-mode
http://github.com/fgallina/python.el (now part of Emacs-24)
Here is the list of what it currently implements:
- Syntax highlighting
- Solid (auto)indentation support
- auto-detection of indentation levels for current file
- Triple quoted strings support (stolen without guilt from GNU/Emacs’ original python.el)
- Fancy variable assignment colorization
- Movement commands you’ll expect from a major-mode.
- Python shell integration (not only for Python 2 but also Python 3!)
- Python shell completion (Same as above!)
- Nice generic shell integration that could support virtually any text based python shell
- PDB Tracking (it even supports ipdb!)
- Symbol completion that sucks because a running inferior shell process and valid code in the current buffer are needed (Don’t blame me, it’s like that in every python-mode I know). I don’t use this thing a lot, I use ropemacs instead
- Eldoc support (this suffers the same drawbacks as the symbol completion, but it’s the only sane way to do it from Elisp)
- add-log-current-defun support
- hideshow support
- outline support
- fill paragraph
Things that (perhaps) are good to add at some point:
- python-check
- ffap support (I never used it though)
- some skeletons (I never used them since I use yasnippet)
Things I don’t think are necessary to be added:
- Bicycle Repair Man integration: since it is discontinued and there are other really nice refactoring tools out there (like rope which can be integrated via ropemacs).
http://www.loveshack.ukfsn.org/emacs/#python.el
- django-html-mumamo-mode
- New django-mode, django-html-mode (recommended) http://github.com/myfreeweb/django-mode
- Old modes
- django-mode
- django-html-mode
Python-mode Extensions (py-mode-ext, pyp)
(defface codepilot-folding-overlay
'((default (:inherit region :box (:line-width 1 :color "DarkSeaGreen1" :style released-button)))
(((class color)) (:background "DarkSeaGreen2" :foreground "black")))
"*Font used by folding overlay."
:group 'codepilot)
(defun cptree-ov-delete ()
(interactive)
(dolist (o (overlays-at (point)))
(cptree-delete-overlay o 'cptree)))
(defvar cptree--overlay-keymap nil "keymap for folding overlay")
(unless cptree--overlay-keymap
(let ((map (make-sparse-keymap)))
(define-key map [mouse-1] 'cptree-ov-delete)
(define-key map "\r" 'cptree-ov-delete)
(setq cptree--overlay-keymap map)))
(defun cptree-delete-overlay(o prop)
(when (eq (overlay-get o 'cptree-tag) prop)
(delete-overlay o)
t))
(defun cptree-hide-region (from to prop)
"Hides a region by making an invisible overlay over it and save the
overlay on the hide-region-overlays \"ring\""
(interactive)
(let ((new-overlay (make-overlay from to)))
;;(overlay-put new-overlay 'invisible nil)
(overlay-put new-overlay 'cptree-tag prop)
(overlay-put new-overlay 'face 'codepilot-folding-overlay)
(overlay-put new-overlay 'display
(propertize
(format "...<%d lines>..."
(1- (count-lines (overlay-start new-overlay)
(overlay-end new-overlay))))))
(overlay-put new-overlay 'priority (- 0 from))
(overlay-put new-overlay 'keymap cptree--overlay-keymap)
(overlay-put new-overlay 'pointer 'hand)))
(require 'python)
(defun mypython-fold/unfold-block ()
"fold the block"
(interactive)
(let (ret b e)
(dolist (o (overlays-at (if (python-open-block-statement-p)
(save-excursion
(python-end-of-statement)
(point)
)
(point))))
(when (cptree-delete-overlay o 'cptree)
(setq ret t)))
(unless ret
(save-excursion
(unless (python-open-block-statement-p)
(python-beginning-of-block))
(python-end-of-statement)
(setq b (point))
(python-end-of-block)
(setq e (1- (point)))
(cptree-hide-region b e 'cptree)))))
(define-key python-mode-map [(f10)] 'mypython-fold/unfold-block)