Page 1 of 1

plugin Calc Expression

Posted: 17.12.2019 23:02
by Alexey
plugin for CudaText.
reads selected text as math expression, e.g. "2.4*sin(pi/3)" and evaluates it by Python.
tries to use "safe evaluation", without dangerous python functions enabled.
gives commands (menu Plugins / Calc Expression) to replace selection with number result,
or just show the result in the statusbar.

these Python functions are supported:

abs cosh frexp pow
acos degrees hypot radians
asin e ldexp sin
atan exp log sinh
atan2 fabs log10 sqrt
ceil floor modf tan
cos fmod pi tanh

min(x1, x2, ...)
max(x1, x2, ...)
sum( [x1, x2, ...] )
mean( [x1, x2, ...] )
median( [x1, x2, ...] )

details:
https://docs.python.org/3/library/math.html
https://docs.python.org/3/library/statistics.html

plugin has config file, call menu item "Options / Settings-plugins / Calc Expression / Config".
it has separator options:
[calc_expression]
decimal_separator=.
thousand_separator=
list_separator=,

decimal_separator can be changed to e.g. "," or another.
thousand_separator can be set to non-empty, it will be skipped by Python anyway.
list_separator is used in functions with several arguments, e.g. min, max, mean.

Posted: 18.12.2019 09:19
by miro.matas
appreciate it!
suggestions…
• show the result at statusbar + copy to clipboard
• in addition to "replace selection" > add new command "place result at current caret"

Add default configuration for cuda_calc_expr plugin

Posted: 06.03.2024 03:41
by okuc
I really like to use cuda_calc_expr (https://github.com/CudaText-addons/cuda_calc_expr), but I feel that the way it is set up through the panel is not very user friendly, and it would be nice to have some default configurations, triggering mechanisms.
For example, it could be used to display the result on the status bar by default; when an equal sign is detected, it will take all the inputs from the previous line and fill in the result after the equal sign.

Re: Add default configuration for cuda_calc_expr plugin

Posted: 06.03.2024 07:20
by main Alexey
>the way it is set up through the panel is not very user friendly
what 'panel' do you mean?
I dont understand.
the plugin is configured using 'Options / settings-plugins' menu which opens the 'plugins.ini' with this

[calc_expression]
decimal_separator=.
thousand_separator=
list_separator=,
digits_precision=4

so you edit options, and restart Cud.
these lines are the 'default config' which you mention, no?

Re: Add default configuration for cuda_calc_expr plugin

Posted: 06.03.2024 07:22
by main Alexey
>For example, it could be used to display the result on the status bar by default;
it is also strange message for me.
plugin gives 2 commands in 'Plugins'

- replace result in editor
- show in the statusbar

so anybody can call any of these 2 commands...

Re: Add default configuration for cuda_calc_expr plugin

Posted: 06.03.2024 15:16
by okuc
I apologize for not making myself clear.

Actually what I mean is that when the "=" sign is entered at the end of a line, it can automatically take the expression in front of the "=" sign to do the calculation,

and depending on the configuration, set to display the result in the status bar, or display the calculation result after the "=" sign, or directly replace all the data in this line with the result.

My current requirement is to trigger the calculation with the "=" sign and to display the result of the calculation automatically after the "=" sign.

I don't want to trigger the calculation by selecting a command, and now the result can't be displayed in this line while keeping the original expression, it seems that there is only an option to replace the original expression.

Re: Add default configuration for cuda_calc_expr plugin

Posted: 07.03.2024 17:26
by main Alexey
that will be interactive plugin work. and of course it is bad if some lexer (e.g. C) is active. user types '=' with C syntax and line is changed. bad. so additional option is needed - what lexers to tolerate.
and option 'how to surround =-char with spaces' is also needed.
so I don't like this idea.
also, interactive plugin (on_key event) slows down the editor a bit.