How to keep indentation when expanding in inferior python mode / ipython?

Skip to first unread message

Swaroop C H

Oct 17, 2013, 12:10:29 AM10/17/13
Hi all,

I searched for "indentation" discussion in this group but could not
exactly find a solution to the problem I'm facing:

I've installed ELPY for Python and have added this to my

#+BEGIN_SRC elisp
(require 'elpy)

I have custom snippets for the "inferior-python-mode", so that I have
specific expansions I want to use after running ~M-x virtualenv-workon~
in the ipython shell.

The expansion works but all the indentation is lost and ipython gets
confused about the code. Can you please guide me on how to fix this?
Note that there are no variables in the template, it's a simple
copy/paste snippet. And yes, when I do %paste in the ipython buffer, it
works as expected.

An example snippet I'm trying to use:

#+BEGIN_SRC python
# This parses the "profile" file containing environment variables
# and loads it into current Python environment
import os, sys, io, re
for line in"profile"):
    line = line.strip()
    if len(line) == 0:
    match = re.match('export (?P<key>.+)="(?P<value>.+)"', line)
    if match is not None:
        key ="key")
        value ="value")
        os.environ[key] = value
        print "Cannot parse line", line
os.environ["DJANGO_SETTINGS_MODULE"] = "project.settings"

Thanks in advance.


Reply all
Reply to author
0 new messages