Skip to content
This repository has been archived by the owner on Nov 12, 2017. It is now read-only.

Commit

Permalink
Add indentaion level matching.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bogdanp committed May 18, 2011
1 parent c31dbf9 commit 1b277a9
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions plugin/pyrepl.vim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
" =======================================================================
" File: pyrepl.vim
" Version: 0.1.6
" Version: 0.1.7
" Description: Vim plugin that provides a Python REPL inside a buffer.
" Maintainer: Bogdan Popa <[email protected]>
" License: Copyright (C) 2011 Bogdan Popa
Expand Down Expand Up @@ -93,11 +93,26 @@ class PyREPL(object):
return self.tq_literal in string
return '"""' in string or "'''" in string

def match_indentation(self):
try:
previous_line = self.block[-1]
if not previous_line: return ""
except IndexError:
return ""
indent_level = self.count_char(previous_line, " ")
if previous_line[-1] == ":":
return "{0} ".format(" " * indent_level)
else:
return " " * indent_level

def insert_prompt(self, block=False):
"Inserts a prompt at the end of the buffer."
vim.current.buffer.append(
"... " if block else ">>> "
)
if block:
vim.current.buffer.append(
"... {0} ".format(self.match_indentation())
)
else:
vim.current.buffer.append(">>> ")
vim.command("normal! G$")
vim.command("startinsert")

Expand Down

0 comments on commit 1b277a9

Please sign in to comment.