[IPython-dev] Issues with IPython and emacs (in ubuntu 14.04)
ssanderson
ssanderson at quantopian.com
Tue May 5 13:15:43 EDT 2015
I use the following in my .emacs, though I use python.el, which is different
from python-mode.el.
(eval-after-load "python" ;; Assumes we're using python.el, not
python-mode.el
'(progn
(setq
python-fill-docstring-style "django"
python-shell-virtualenv-path "~/.virtualenvs"
python-check-command "pylint"
python-shell-interpreter "ipython"
python-shell-interpreter-args "--profile myprofile"
python-shell-prompt-regexp "In \\[[0-9]+\\]: "
python-shell-prompt-output-regexp "Out\\[[0-9]+\\]: "))
The IPython-relevant pieces are the 4 python-shell-* variables. They tell
python.el to use
ipython as its python command, to pass "--profile myprofile" as an argument,
and provide regexps
used to parse IPython's input/output prompts.
Some other .emacs snippets that you might find useful for Python:
;; Automatically run flake8 on .py files on save.
(require 'flymake-python-pyflakes)
(add-hook 'python-mode-hook 'flymake-python-pyflakes-load)
(setq flymake-python-pyflakes-executable "flake8")
;; Mostly useful for transforming imports of the form:
;; from somemodule import (
;; foo,
;; bar,
;; buzz,
;; )
;; to
;; from somemodule import (
;; bar,
;; buzz,
;; foo,
;; )
(defun sort-lines-between-parens(&optional case-sensitive)
(interactive)
(let ((sort-fold-case (not case-sensitive))
(right-paren (save-excursion
(re-search-forward ")" nil t)
(line-end-position 0)))
(left-paren (save-excursion
(re-search-backward "(" nil t)
(line-beginning-position 2))))
(when (and right-paren left-paren)
(sort-lines nil left-paren right-paren))))
;; Transform ['foo', 'bar', 'buzz']
;; into
;; ['foo',
;; 'bar', 'buzz']
;;
;; You can run this repeatedly to columnize a function call or list/dict/set
literal.
;; I bind this to C-, C-,
(defun indent-after-comma()
(interactive)
(re-search-forward ",[ ]*" (line-end-position) t)
(replace-match ",")
(newline-and-indent))
;; Not python-specific, but probably the most useful emacs snippet I've
written for exploring
;; other people's libraries. I bind this to C-c g.
(defun git-grep ()
"Grep for a symbol within the git repo of the current file."
(interactive)
(let* ((sym (thing-at-point 'symbol))
(regex (read-regexp "Expression" sym)))
(require 'vc-git)
(vc-git-grep regex "" (vc-git-root default-directory))))
--
View this message in context: http://python.6.x6.nabble.com/Issues-with-IPython-and-emacs-in-ubuntu-14-04-tp5094072p5094150.html
Sent from the IPython - Development mailing list archive at Nabble.com.
More information about the IPython-dev
mailing list