# HG changeset patch # User Jeff Hammel # Date 1390011479 28800 # Node ID 71fb16088d5456a6fa7844db152febde6bc54cad # Parent 22c83044960438c1a83adba644d216b85a500a84 add file for indentation; wth did my work go??? :( diff -r 22c830449604 -r 71fb16088d54 textshaper/indent.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/textshaper/indent.py Fri Jan 17 18:17:59 2014 -0800 @@ -0,0 +1,50 @@ +#!/usr/bin/env python + +""" +indentation of text blocks +""" + +import optparse +import os +import sys + +def indent(text, indentation=4, space=' ', strict=False): + """ + indent a block of text + + text -- lines of text to indent + indentation -- number of spaces to indent + space -- what to indent with + strict -- whether to enforce required whitespace for negative indentation + """ + + if not indentation: + # nothing to do + return text + + if indentation > 0: + retval = [space * indentation + line for line in text] + else: + # negative indentation + indentation = -indentation + retval = [] + for line in text: + prefix = line[:indentation] + for index, char in enumerate(prefix): + if not char == space: + if strict: + raise AssertionError("Found non-'%s' charcter at column %d for indentation -%d" % (space, index, indentation)) + break + else: + index = indentation + retval.append(line[index:]) + +def main(args=sys.argv[1:]): + + usage = '%prog [options]' + parser = optparse.OptionParser(usage=usage, description=__doc__) + options, args = parser.parse_args(args) + + +if __name__ == '__main__': + main() diff -r 22c830449604 -r 71fb16088d54 textshaper/main.py --- a/textshaper/main.py Sun Oct 20 18:07:06 2013 -0700 +++ b/textshaper/main.py Fri Jan 17 18:17:59 2014 -0800 @@ -20,6 +20,10 @@ def add_options(parser): """add options to the OptionParser instance""" + # TODO + # parser.add_option('-c', '--clip', '--copy', dest='copy_to_clipboard', + # help="copy to given program on exit") + def main(args=sys.argv[1:]): # parse command line options