Skip to content

bamanzi/dotemacs-py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Knowledge Base of Python on Emacs

Code Navigation

etags/ctags

pycscope

TODO: not work?

not work?

Code Completion

built-in

emacs <= 23.1

default key-bindings: M-TAB (=complete-symbol)

emacs 23.2 ~ 23.4

default key-bindings: M-TAB (completion-at-point) (if you set tab-always-indent to complete, you can use TAB for completion.)

emacs 24.x

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.

auto-complete front-end

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

pycomplete

part of python-mode.el.

pycomplete.el + pycomplete.py + pymacs

note:

  • requires pymacs

cons:

  • only works on python-mode.el

auto-complete front-end

https://github.com/pdee/pdee/blob/master/auto-complete-pycomplete.el

patch: [Python-mode] [PATCH] Improved pycomplete]

part1: http://mail.python.org/pipermail/python-mode/2012-July/001508.html part2: http://mail.python.org/pipermail/python-mode/2012-July/001515.html

pycompletemine

https://github.com/pdee/pdee/blob/master/extensions/pycompletemine.el

it works on python.el & python-mode.el

py-complete

features:

  • C-return: completion using minibuffer
  • py-complete-try-complete-symbol for hippie-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

gpycomplete

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.

others

based on jedi, epc, auto-complete

Document Lookup

built-in

(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

external utility: pydoc

References:

emacs-helm-pydoc

https://github.com/syohex/emacs-helm-pydoc

eldoc

info format

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

pydoc-info

https://bitbucket.org/jonwaltman/pydoc-info/

advantages:

  1. info document for python-2.7 already provided with pydoc-info
  2. you can add other sphinx-based documents to lookup

disadvantages:

  1. 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

pylookup

haddoc

Syntax Check (compile & flymake)

compilation style

built-in: python-check (C-c C-v)

python-pylint.el

python-pep8.el

flymake style (on-the-fly checking whlle editing)

flymake-python-pyflakes.el

flymake-python.el

flycheck.el

References

Interactive Shell

IPython

bpython

Debug

pdb

References

with pdb:

  1. 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).
  2. This opens a new PDB windows (Screenshot)
  3. 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.
  4. Type c on the PDB buffer to run upto the breakpoint
  5. 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.
  6. To watch a variable, type p var, as in the screenshot.
  7. 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.

others

misc

VirtualEnv

Virtualenv.el (something similar is included in python-mode.el

virtualenv + remote (tramp)

virtualenvwrapper + desktop

http://virtualenvwrapper.readthedocs.org/en/latest/extensions.html#emacs-desktop

references:

Rope

ropemacs: rope in emacs

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:

  1. An XMLRPC server exposing the rope API, and
  2. Client libraries (currently just emacs lisp) for talking to the server

Backup Info

General How-to

Chinese

All-in-one suite

emacs-for-python

https://github.com/gabrielelanaro/emacs-for-python

pdee

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

others

  • 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.

Major modes

built-in

(emacs-24 uses fgallina’s python.el)

python-mode.el

https://launchpad.net/python-mode

fgallina’ python.el

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

loveshack’s python.el

http://www.loveshack.ukfsn.org/emacs/#python.el

Django

misc

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) 

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published