diff --git a/Calc/calc.py b/Calc/calc.py index 37f2925..dc60c6c 100644 --- a/Calc/calc.py +++ b/Calc/calc.py @@ -413,6 +413,20 @@ def on_catalog(self): args_hint=kp.ItemArgsHint.REQUIRED, hit_hint=kp.ItemHitHint.NOARGS)]) + def semicalc(self, expression): + while True: + semipos = expression.find(";") + if semipos < 0: + return expression + elif semipos == 0: + expression = expression[1:] + elif semipos + 1 == len(expression): + expression = expression[0:-1] + elif len(expression) > semipos and (expression[semipos+1].isalnum() or expression[semipos+1] in "(){}[]"): + return f"error: {expression}" + else: + expression = f"({expression[0:semipos]}){expression[semipos+1:]}" + def on_suggest(self, user_input, items_chain): if items_chain and items_chain[0].category() == self.ITEMCAT_VAR: suggestions = [] @@ -447,7 +461,7 @@ def on_suggest(self, user_input, items_chain): suggestions = [] try: - results = self._eval(expression) + results = self._eval(self.semicalc(expression)) if not isinstance(results, (tuple, list)): results = (results,) for res in results: diff --git a/README.md b/README.md index 407d3d7..d462b76 100644 --- a/README.md +++ b/README.md @@ -46,4 +46,5 @@ license, which you can find in the `LICENSE` file located in this directory. - Patch to add `Copy...` actions for the `RegBrowser` package * [@DrorHarari](https://github.com/DrorHarari): - Patch to add string reverse and camel-like case changes to the `String` package - - Patch to add variable support to the 'Calc' package \ No newline at end of file + - Patch to add variable support to the 'Calc' package + - Patch to add multi-part calculation to the 'Calc' package (10+20+30;*1.3)