Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Towards an Python-IDE in Emacs

branch: master

Remaining occurences of dropped py-paragraph-fill-docstring-p

removed

See `py-comment-fill-column', `py-docstring-fill-column'
latest commit 5a69e5f08e
Andreas Röhler andreas-roehler authored
Octocat-spinner-32 completion Missing window-configuration-p, lp:1248633, fixed November 06, 2013
Octocat-spinner-32 devel Some more tests fixed March 10, 2014
Octocat-spinner-32 doc Documentation of commands updated February 27, 2014
Octocat-spinner-32 extensions Don't require `column-marker' July 08, 2013
Octocat-spinner-32 test Remaining occurences of dropped py-paragraph-fill-docstring-p March 12, 2014
Octocat-spinner-32 website actually... not needed. :-/ February 04, 2006
Octocat-spinner-32 .bzrignore non-interactive calls to py-shell should set NO-WINDOW-MANAGMENT September 29, 2013
Octocat-spinner-32 CREDITS `py-newline-and-indent' honor dedent, lp:1280982 February 18, 2014
Octocat-spinner-32 EXTENSIONS column-marker.el merged March 04, 2012
Octocat-spinner-32 INSTALL IPYTHON readme added, lp:835151 March 07, 2012
Octocat-spinner-32 INSTALL-INFO-FILES python-info.el patched, lp:1281950 February 19, 2014
Octocat-spinner-32 IPYTHON IPYTHON readme added, lp:835151 March 07, 2012
Octocat-spinner-32 LICENSE LICENSE text GPLv3 added April 26, 2011
Octocat-spinner-32 NEWS `py-kill-buffer-unconditional', new command March 02, 2014
Octocat-spinner-32 README C-c ! not working from Python-shell, lp:1234539, fixed October 03, 2013
Octocat-spinner-32 README-AUTOPAIR.org autopair-mode delivered, lp:1003263 May 25, 2012
Octocat-spinner-32 README.DEVEL.org inconvenient splitting behavior, lp:1018996, again December 30, 2012
Octocat-spinner-32 byte-compile-directory.sh inconvinient-py-shell-switch-buffers-on-execute, lp:1073986 November 02, 2012
Octocat-spinner-32 pyflakespep8.py Better Python Flymake Integration in Emacs, lp:10010994 May 21, 2012
Octocat-spinner-32 python-mode.el Remaining occurences of dropped py-paragraph-fill-docstring-p March 12, 2014
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)


Unless other libraries depend on python.el, unloading 'python is recommended, as it seems to destroy python-mode user defined abbreviations:

  (when (featurep 'python) (unload-feature 'python t))



;;;;;;;;;

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

;;;;;;;;;

When code is executed from current buffer, either

- python-mode-v5-behavior, a quite simple and effective way.
  Setting `python-mode-v5-behavior-p' to `t' makes it the default.

- if a buffer-file exists and buffer is unchanged, it's file is executed as is.

- in all other cases a temporary file is created.
  Setback: in case of error, returned error code points
  here, i.e. indicated error-line-numbers are not that of
  orginal buffer.

;;;;;;;;;
To enable code auto-completion:

  (setq py-load-pymacs-p t)

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)

If you do not use one of those visual completion interfaces, key bindings exist:
  - C-tab complete symbol
  - f1    show help
  - S-f1  show signature
  - f2    go to

If `py-complete-function' is set, it takes precedence

;;;;;;;;;

smart-operator minor mode

for example with key "+"
inserts " + "

smart-operator extended by augmented-assigments
C-u +
inserts " += "

customizable boolean `py-smart-operator-mode-p'

;;;;;;;;;

Beside common moves like `defun', `statement' 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

;;;;;;;;;

Moving, copying, deleting

When moving over or mark code, commands with suffix
"-bol" take the correspond beginning of line as start
resp. end. Commands without that suffix take the
indentation at the beginning resp. the last printable
character the end - see in menu PyEdit whats implemented.

While commands "py-beginning..." resp. "py-end..." compute the context, 
selecting the corresponding beginning or end
new "py-up...", "py-down..." jump regexp-based to the 
next element in buffer.
Listed in PyMenu. 

;;;;;;;;;

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

;;;;;;;;;

- customizable `py-output-buffer'.

  `py-execute-...'-commands arrive in buffer created by
  `py-shell'. It's name is composed WRT to Python
  version used, it's path etc. If boolean
  `py-enforce-output-buffer-p' is non-nil, value of
  `py-output-buffer' is taken instead.
  
;;;;;;;;;

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.