[kupfer] plugin.calculator: Save last result in variable "_"



commit 1455c0c076d77a8fa917fdf897200e0feca5070a
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Sun Sep 6 23:13:37 2009 +0200

    plugin.calculator: Save last result in variable "_"

 kupfer/plugin/calculator.py |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
---
diff --git a/kupfer/plugin/calculator.py b/kupfer/plugin/calculator.py
index 882d0fa..995be48 100644
--- a/kupfer/plugin/calculator.py
+++ b/kupfer/plugin/calculator.py
@@ -30,15 +30,17 @@ class Calculate (Action):
 	rank_adjust = 10
 	def __init__(self):
 		Action.__init__(self, _("Calculate"))
+		self.last_result = None
 
 	def has_result(self):
 		return True
 	def activate(self, leaf):
-		text = leaf.object
-		expr = text.lstrip("= ")
+		expr = leaf.object.lstrip("= ")
 		environment = dict(math.__dict__)
 		environment.update(cmath.__dict__)
 		# define some constants missing
+		if self.last_result:
+			environment["_"] = self.last_result
 		environment["kupfer"] = KupferSurprise("inf")
 		# make the builtins inaccessible
 		environment["__builtins__"] = {}
@@ -48,6 +50,7 @@ class Calculate (Action):
 			pretty.print_error(__name__, type(exc).__name__, exc)
 			result = unicode(exc)
 		else:
+			self.last_result = result
 			result = unicode(result)
 		return TextLeaf(result)
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]