Skip to content
This repository

Python Development Emacs Environment

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 completion
Octocat-spinner-32 devel
Octocat-spinner-32 doc
Octocat-spinner-32 extensions
Octocat-spinner-32 obsolete
Octocat-spinner-32 python-libs
Octocat-spinner-32 scripts
Octocat-spinner-32 snippets
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 CONTRIBUTORS
Octocat-spinner-32 COPYING
Octocat-spinner-32 CREDITS
Octocat-spinner-32 ChangeLog
Octocat-spinner-32 Diskussions.md
Octocat-spinner-32 EXTENSIONS
Octocat-spinner-32 Glossar.md
Octocat-spinner-32 Home.md
Octocat-spinner-32 INSTALL
Octocat-spinner-32 INSTALL-INFO-FILES
Octocat-spinner-32 IPYTHON
Octocat-spinner-32 NEWS
Octocat-spinner-32 Pymacs.md
Octocat-spinner-32 README
Octocat-spinner-32 README-AUTOPAIR.org
Octocat-spinner-32 README.DEVEL.org
Octocat-spinner-32 ToDo.md
Octocat-spinner-32 ToDo.org
Octocat-spinner-32 ar-comment-lor.el
Octocat-spinner-32 auto-complete-pycomplete.el
Octocat-spinner-32 beg-end.el
Octocat-spinner-32 byte-compile-directory.sh
Octocat-spinner-32 company-pycomplete.el
Octocat-spinner-32 index.docbook
Octocat-spinner-32 makeElpa
Octocat-spinner-32 misc-utils.el
Octocat-spinner-32 pdee-completion.el
Octocat-spinner-32 pdee-editing.el
Octocat-spinner-32 pdee-init.el
Octocat-spinner-32 pdee-pkg.el
Octocat-spinner-32 pycomplete+.el
Octocat-spinner-32 pyflakespep8.py
Octocat-spinner-32 pymacs.el
Octocat-spinner-32 python-abbrev-propose.el
Octocat-spinner-32 python-components-auto-fill.el
Octocat-spinner-32 python-components-beginning-forms.el
Octocat-spinner-32 python-components-bol-forms.el
Octocat-spinner-32 python-components-comment.el
Octocat-spinner-32 python-components-completion.el
Octocat-spinner-32 python-components-completion_flymake.el
Octocat-spinner-32 python-components-copy.el
Octocat-spinner-32 python-components-dedicated-shells.el
Octocat-spinner-32 python-components-delete.el
Octocat-spinner-32 python-components-edit.el
Octocat-spinner-32 python-components-electric.el
Octocat-spinner-32 python-components-exec-forms.el
Octocat-spinner-32 python-components-execute-file.el
Octocat-spinner-32 python-components-execute.el
Octocat-spinner-32 python-components-extensions.el
Octocat-spinner-32 python-components-fast-forms.el
Octocat-spinner-32 python-components-forms-code.el
Octocat-spinner-32 python-components-forms.el
Octocat-spinner-32 python-components-help.el
Octocat-spinner-32 python-components-hide-show.el
Octocat-spinner-32 python-components-imenu.el
Octocat-spinner-32 python-components-intern.el
Octocat-spinner-32 python-components-macros.el
Octocat-spinner-32 python-components-mode.el
Octocat-spinner-32 python-components-move.el
Octocat-spinner-32 python-components-named-shells.el
Octocat-spinner-32 python-components-nomacros.el
Octocat-spinner-32 python-components-paragraph.el
Octocat-spinner-32 python-components-pdb.el
Octocat-spinner-32 python-components-re-forms.el
Octocat-spinner-32 python-components-send.el
Octocat-spinner-32 python-components-shell-complete.el
Octocat-spinner-32 python-components-shift-forms.el
Octocat-spinner-32 python-components-skeletons.el
Octocat-spinner-32 python-components-switches.el
Octocat-spinner-32 python-components-unified-completion.el
Octocat-spinner-32 python-components-up-down.el
Octocat-spinner-32 python-components-virtualenv.el
Octocat-spinner-32 python-dedicated-shells.el
Octocat-spinner-32 python-extended-executes.el
Octocat-spinner-32 python-mode-fixed-examples.py
Octocat-spinner-32 python-mode-send.el
Octocat-spinner-32 python-mode-utils.el
Octocat-spinner-32 python-named-shells.el
Octocat-spinner-32 python-shell-complete.el
Octocat-spinner-32 python-shell-install-example-buffer.el
Octocat-spinner-32 setup.py
Octocat-spinner-32 sh-beg-end.el
Octocat-spinner-32 thing-at-point-utils.el
Octocat-spinner-32 thingatpt-highlight.el
Octocat-spinner-32 thingatpt-python-expressions.el
Octocat-spinner-32 thingatpt-utils-base.el
README
Put the following into your initialization file:

  (setq py-install-directory "PATH/TO/PYTHON-MODE/")
  (add-to-list 'load-path py-install-directory)
  (require 'python-mode)

;;;;;;;;;

Customize default Python shell as `py-shell-name'

`py-shell-name' might be an installed executable as
shell command `type' would display, but also a
PATH/TO/(I)PYTHON, of a virtualenv for example

To change the Python default shell see also INSTALL

Most python-mode.el commands start with prefix `py-'

`M-x py- TAB'
displays a list of them in completion-buffer.
See also commands list delivered in directory doc.

List virtualenv related `M-x virtualenv- TAB'
resp. Pymacs commands `M-x pymacs-'

Commands related to a specific shell start with
it's name as `ipython-complete'.
Open an installed shell by

M-x SHELL

With prefix C-u user is prompted to specify a PATH-TO-LOCAL-SHELL
Also evaluating

(py-shell nil DEDICATED PATH-TO-LOCAL-SHELL)

if DEDICATED is set to `t', shell will get an unique name.

Install a local shell by evaluating

(defun MY-LOCAL-SHELL ()
  (interactive)
  (py-shell nil DEDICATED PATH-TO-LOCAL-SHELL))

;;;;;;;;;


Python code might be processed by an

- interactive Python shell (DEFAULT)
- non-interactive Python (`py-fast-process-p', if large output)

Both processes might run in 
- session, i.e. start from possible previous state (DEFAULT)
- dedicated, (`py-dedicated-process-p') run in separate process

There is also
- python-mode-v5-behavior

;;;;;;;;;
To use auto-complete, just prepend the following lines:

  (require 'auto-complete-config)
  (ac-config-default)

or for company:

  (autoload 'company-mode "company" nil t)

;;;;;;;;;

Beside common moves like `defun', `statement', block specific Python-mode edits are delivered:

`py-expression' and `py-partial-expression'. 

Statement below is considered composed of two `py-expression' 

a = ['spam', 'eggs', 100, 1234]
|_| |_________________________|

Assigment operator and all inside comments is ignored.

`py-partial-expression' would match six sections

 a = ['spam', 'eggs', 100, 1234]
|_|   |_____|  |____| |__| |__|
     |_________________________|

When traversing code, `py-partial-expression' climbs down and up
all levels encountered, i.e. at opening `[' `py-expression' would return ['spam', 'eggs', 100, 1234], while one char behind at `''
it yields `'spam','

- py-sexp-function, 
  When set, it's value is called instead of `forward-sexp', `backward-sexp
  Choices are py-partial-expression, py-expression, default nil

;;;;;;;;;

Customize boolean `py-set-fill-column-p'

If `t', enables use Python specific `fill-column' according to

`py-docstring-fill-column', default is 72

and `py-comment-fill-column, default is 79

Comment- and docstring settings might be disabled by
any non-integer value, which means: do not use a
different value of `fill-column' than emacs-wide

;;;;;;;;;

- Output

  `py-execute-...'-commands arrive in buffer created by
  `py-shell'. It's name is composed WRT to Python
  version used, it's path etc. 

  Result of commands ending  "-fast"
  arrives in `py-output-buffer'
  
;;;;;;;;;

Python and IPython

Start IPython shell after loading python-mode via M-x
ipython, not from plain shell.

Executing code through IPython should work as with
regular Python, also getting completions from. However,
with IPython, it feels a demi-second slower. Also when
starting a session, first completion might fail, while
succeeding afterwards. Any bug reports, which might
help truck down the issue, are highly appreciated.

;;;;;;;;;

Troubleshooting

Start with Emacs -Q from the directory where python-mode.el lives.
Open python-mode.el and evaluate it.

Open a file with ending ".py".

M-x python RET

a regular Python-shell should appear

M-x IPython RET

an IPython-shell should be opened
Something went wrong with that request. Please try again.