[telepathy-doc/master] Trim empty leading space off the front of examples
Davyd Madeley
davyd at madeley.id.au
Wed Apr 1 01:25:10 PDT 2009
---
docs/book/insert-examples.py | 13 ++++++++++++-
1 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/docs/book/insert-examples.py b/docs/book/insert-examples.py
index dde3a31..fdf8b94 100755
--- a/docs/book/insert-examples.py
+++ b/docs/book/insert-examples.py
@@ -65,7 +65,18 @@ for example in examples:
begin = True
continue
- if lines != []: contents = '\n'.join (lines)
+ if lines != []:
+ # trip the common indent off the front of the example
+ def leading_space (s):
+ n = 0
+ for c in s:
+ if not c.isspace (): break
+ n += 1
+ return n
+ lines = map (lambda s: s.expandtabs(), lines)
+ trim = min ([ leading_space(s) for s in lines if s != "" ])
+
+ contents = '\n'.join (map (lambda s: s[trim:], lines))
else:
print >> sys.stderr, "Including file `%s'..." % filename
--
1.5.6.5
More information about the telepathy-commits
mailing list