about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-01-03 15:05:31 +0100
committerhut <hut@lavabit.com>2010-01-03 15:05:31 +0100
commitb91d7c348e1077e02741fa40f90904c376ce807c (patch)
tree83178deaa71f383eab120a06e27ad00e15467e64
parentc25ba934d0e5e6118963e3bf75e31f350d652ea9 (diff)
downloadranger-b91d7c348e1077e02741fa40f90904c376ce807c.tar.gz
actions: use inspect.cleandoc instead of a custom function
-rw-r--r--ranger/actions.py3
-rw-r--r--ranger/ext/trim.py31
2 files changed, 2 insertions, 32 deletions
diff --git a/ranger/actions.py b/ranger/actions.py
index 25c8262c..bc6da7b8 100644
--- a/ranger/actions.py
+++ b/ranger/actions.py
@@ -1,5 +1,6 @@
 import os
 import shutil
+from inspect import cleandoc
 
 from ranger.shared import EnvironmentAware, SettingsAware
 from ranger import fsobject
@@ -183,7 +184,7 @@ class Actions(EnvironmentAware, SettingsAware):
 			return
 
 		pager = self.ui.open_pager()
-		lines = trimmed_lines_of_docstring(command.__doc__)
+		lines = cleandoc(command.__doc__).split('\n')
 		pager.set_source(lines)
 	
 	def display_log(self):
diff --git a/ranger/ext/trim.py b/ranger/ext/trim.py
deleted file mode 100644
index d469435d..00000000
--- a/ranger/ext/trim.py
+++ /dev/null
@@ -1,31 +0,0 @@
-import sys
-
-def trim_docstring(docstring):
-	if not docstring:
-		return ''
-	return '\n'.join(trimmed_lines_of_docstring(docstring))
-
-def trimmed_lines_of_docstring(docstring):
-	if not docstring:
-		return []
-	# Convert tabs to spaces (following the normal Python rules)
-	# and split into a list of lines:
-	lines = docstring.expandtabs().splitlines()
-	# Determine minimum indentation (first line doesn't count):
-	indent = sys.maxint
-	for line in lines[1:]:
-		stripped = line.lstrip()
-		if stripped:
-			indent = min(indent, len(line) - len(stripped))
-	# Remove indentation (first line is special):
-	trimmed = [lines[0].strip()]
-	if indent < sys.maxint:
-		for line in lines[1:]:
-			trimmed.append(line[indent:].rstrip())
-	# Strip off trailing and leading blank lines:
-	while trimmed and not trimmed[-1]:
-		trimmed.pop()
-	while trimmed and not trimmed[0]:
-		trimmed.pop(0)
-	# Return a single string:
-	return trimmed