Scripts discussion (4)

Discuss and announce AkelPad plugins
  • Author
  • Message
DV
Offline
Posts: 1291
Joined: Thu Nov 16, 2006 11:53 am
Location: Kyiv, Ukraine

Re: Scripts discussion (4)

Post by DV »

Regarding the features of AkelPad's calculators, personally I am very impressed by the CalculatorJS by KDJ.
Take a look at this screenshot that demonstrates how the CalculatorJS deals with variables:

Image

At first, we have a value `x=10` that has been set by means of "Result to X".
Then, we have an inline variable `a=5`.
Finally, the result is an array that uses the current values of both `a` and `x`.
To me, this is simply amazing.

Offline
Posts: 47
Joined: Sat Jul 05, 2008 11:30 am
Location: Odesa, Ukraine

Re: Scripts discussion (4)

Post by ewild »

DV, of cource, you're right. KDJ's CalculatorJS is great, too.
Definitely, I use it from time to time, when needed (overall, I have five js calculators). But it is, to say... too powerful.
It's a scientific-level calculator with a rich interface. However, there are simpler tasks for which mathCalc fits better, from my point of view.
By the way, mathCalc is only one of them that handles in-text % operations, all the other would return syntax errors there.

DV, incidentally, do you know if there are any hints/tricks/settings on how to get rid of those .99999999999999 in CalculatorJS?

DV
Offline
Posts: 1291
Joined: Thu Nov 16, 2006 11:53 am
Location: Kyiv, Ukraine

Re: Scripts discussion (4)

Post by DV »

ewild wrote: Thu Dec 19, 2024 3:03 pmif there are any hints/tricks/settings on how to get rid of those .99999999999999 in CalculatorJS?
We may try an approach similar to this one (the `format_result` method):
https://github.com/d0vgan/nppexec/blob/ ... .cpp#L1018

Though I can't advise where exactly to do something like that in the CalculatorJS.

Offline
Posts: 5
Joined: Tue Nov 12, 2024 10:28 pm

Re: Scripts discussion (4)

Post by xOleg »

MathCalc -- это просто интерфейс к функции eval() Яваскрипта. Он умеет ровно то же, что и она. И не умеет, кстати, тоже (Например, возводит в степень только через Math.pow()). Единственная идея там -- это способ использования, когда математические расчеты являются просто редактированием текста. Подсмотренно у MathCAD, как я и указал в описании.

Offline
Posts: 47
Joined: Sat Jul 05, 2008 11:30 am
Location: Odesa, Ukraine

Re: Scripts discussion (4)

Post by ewild »

xOleg wrote: Fri Dec 20, 2024 10:27 am...Единственная идея там...
A good idea makes the difference.
xOleg,
By the way, I have an idea for your MathCalc script:
An option to sum all the numbers within the text/selection with modes a. sum only, b. sum regarding the minus sign before numbers.
It can work out as follows:

Code: Select all

$start=AkelPad.GetSelStart();
$end=AkelPad.GetSelEnd();
if ($start == $end)
AkelPad.SetSel(0,-1);
$text=AkelPad.GetSelText();

// extract numbers off the text/selection and make a sum expression from it
$plus=$text.replace(/[^0-9.]/g,"+").replace(/^[+.0]+(\d)/g,"$1").replace(/(\d)[+.]+$/g,"$1").replace(/\+(0|[.])+/g,"+").replace(/\++/g,"+").replace(/(\d)[.][+]/g,"$1+")
// same as above but retain minus sign before numbers and use it in the expression as such
$math=$text.replace(/[^0-9.-]/g,"+").replace(/^[+-.0]+(\d)/g,"$1").replace(/(\d)[+-.]+$/g,"$1").replace(/\+0+/g,"+").replace(/\-0+/g,"-").replace(/\+[.-]+\+/g,"+").replace(/\++/g,"+").replace(/(\d)[.][+]/g,"$1+")

$text=$text+'\r'+$math+'\r'+$plus+'\r'

AkelPad.ReplaceSel($text);

AkelPad.SetSel($start,$start);
Video illustration:
https://i.imgur.com/4CyGtax.mp4

Here, the example script prepares the expressions, and then MathCalc does the actual maths.

Text for testing:

Code: Select all

Lorem ipsum 000 dolor 111 sit amet,
Nullam ut 222 finibus 333 lectus.
"Praesent 444 eusem 555 lorem."
Fusce 05-09-2024 elementum gravida luctus?
Sed non 2,5 accumsan lorem!
1. Vivamus at mauris mi[1]
2. Duis ac faucibus elit.[2][3]
3. Sed sed 'tempor' diam.
Vivamus tincidunt tristique dolor.[4,5]
Morbi vel 25.25 blandit augue.

Offline
Posts: 5
Joined: Tue Nov 12, 2024 10:28 pm

Re: Scripts discussion (4)

Post by xOleg »

I have an idea for your MathCalc script
Смысл понятен, но для латинницы такого не сделать, поскольку будут отброшены встроенные функции и еще много разных интересных вещей. Например:

{sin(PI/6)} = 0.5

Но, самое главное, что такое изменение противоречило бы самой концепции скрипта как "живых" математических вычислений. Вот небольшая демонстрация, как все работает:

https://youtu.be/oNnZl-bF5E8

Offline
Posts: 47
Joined: Sat Jul 05, 2008 11:30 am
Location: Odesa, Ukraine

Re: Scripts discussion (4)

Post by ewild »

xOleg,
It could be a part of such a live math-in-text flow, too.
That's why I offered it.
From my point of view, it fits MathCalc conception pretty harmonically.
For instance, you're typing 'I bought 5 apples in the morning, and then Maria gifted me 7 more apples in the noon, so now I have' {hitting a magic button, and voila!} 5+7 = 12 {typing further} 'ones!'

OK then, meet mathText.js.
Yet another math script in the collection.
https://akelpad.sourceforge.net/forum/v ... 657#p36657

Offline
Posts: 3234
Joined: Wed Nov 29, 2006 1:19 pm
Location: Киев, Русь
Contact:

Re: Scripts discussion (4)

Post by VladSh »

ewild
Подобный скрипт уже был - SumNumbers.js.

Offline
Posts: 11
Joined: Sat Nov 30, 2024 1:56 pm

Re: Scripts collection

Post by AkulaBig »

В скрипте FindReplaceFiles.js под Вин 11 выдает ошибку:
строка 663: nID = oSys.Call("User32::GetDlgCtrlID", oSys.Call("User32::GetFocus"));
Если нажать Отмена, новая ошибка:
строка 744: oSys.Call("User32::SetWindowTextW", hWnd, sText);
Image
Пробовал различные сборки с AkelPad различных версий. Поэтому решил, что ошибка, скорей всего из-за Винды.
Помогите устранить ошибку.
Попробовал скрипт на Вин 7. Отлично работает. Все дело, как я и предполагал в Вин 11.

Offline
Posts: 47
Joined: Sat Jul 05, 2008 11:30 am
Location: Odesa, Ukraine

Re: Scripts discussion (4)

Post by ewild »

VladSh wrote: Fri Jan 10, 2025 8:21 am ewild
Подобный скрипт уже был - SumNumbers.js.
There are no similar scripts.
Moreover, my script went way farther than that.
Its feature-complete version supports all basic arithmetic operations [+-*/%] in the whole text, or in the selection, or in the current line, or all that at once.
It is the only math script for AkelPad that handles percent calculations properly.
And it doesn't have the 0.999999999(9)-like issue.
Unfortunately, I have no motivation for the script to reach the publication-ready phase.
Example text:

Code: Select all

.1
+20 Lorem ipsum .5 dolor sit amet.
80+50% 80-50% 80*50% 80/50%
.2 "Morbi vel blandit augue?"
Morbi eu tortor 20 ligula.
30%
Example feature-complete script output:

Code: Select all

all text plus  : 0.1+20+0.5+80+50+80+50+80+50+80+50+0.2+20+30 = 590.8
all text minus : 0.1+20+0.5+80+50+80-50+80+50+80+50+0.2+20+30 = 490.8
all text basic : 0.1+20+0.5+80+50+80-50+80*50+80/50+0.2+20+30 = 4232.4
all text full  : 0.1+20+0.5+80+50%+80-50%+80*50%+80/50%+0.2+20+30 = 3432.8
Post Reply