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

57 views
Skip to first unread message

Swaroop C H

unread,
Oct 17, 2013, 12:10:29 AM10/17/13
to smart-...@googlegroups.com
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
.emacs.d/init.el:

#+BEGIN_SRC elisp
(require 'elpy)
(elpy-enable)
(elpy-use-ipython)
#+END_SRC

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 io.open("profile"):
    line = line.strip()
    if len(line) == 0:
       continue
    match = re.match('export (?P<key>.+)="(?P<value>.+)"', line)
    if match is not None:
        key = match.group("key")
        value = match.group("value")
        os.environ[key] = value
    else:
        print "Cannot parse line", line
sys.path.append(os.path.expanduser("~/code/project"))
os.environ["DJANGO_SETTINGS_MODULE"] = "project.settings"
#+END_SRC

Thanks in advance.

Regards,
Swaroop

Reply all
Reply to author
Forward
0 new messages