Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion Calc/calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
- Patch to add variable support to the 'Calc' package
- Patch to add multi-part calculation to the 'Calc' package (10+20+30;*1.3)