plugin Cuda-Ext Align

Plugins for SynWrite and CudaText...
LuNik700
Posts: 18
Joined: 21.08.2021 14:56

Post by LuNik700 »

Thx Alexey. I'm anxious to see the optimizations you will make. To see what you'll change is a good way to learn ...

Best wishes to you and Kvichans
Ludger
main Alexey
Posts: 2245
Joined: 25.08.2021 18:15

Post by main Alexey »

a) I will replace "for crt in carets" with "for (x, y, x1, y1) in carets". crt[0] with x, crt[1] with y.
b) I will remove from "carets" the carets placed on the same line, i.e. (not tested)

Code: Select all

for i in reversed(range(len(carets))):
  if (i>0) and (carets[i][1]==carets[i-1][1]):
    del carets[i]
c) we should disable the action if any carets has a selection.
d) we should change the carets to a new locations (even if some are deleted). ed.set_caret(...).
LuNik700
Posts: 18
Joined: 21.08.2021 14:56

Post by LuNik700 »

main Alexey wrote:I see some places can/must be changed a little (we will change them, don;'t worry); I posted the request to @kvichans on Github.
I just looked at your request for Kvichans on Github...
>>> стоит удалить из списка carets каретки стоящие на одной строке (кроме самой правой)

You are absolutly right! This has to be changed, I didn't test that case :(
Align_by_caret21.png
Align_by_caret21.png (10.16 KiB) Viewed 2570 times
Align_by_caret22.png
Align_by_caret22.png (10.54 KiB) Viewed 2570 times
LuNik700
Posts: 18
Joined: 21.08.2021 14:56

Post by LuNik700 »

Hi Alexey,
I think I fixed most of the things you mentioned. Please find the new source attached.

Especially the issue with more than one caret in a line is solved:
It has to be discussed which of carets have to be skipped - I prefer to skip all carets except the rightmost in a line but it would be a valid approach to process only the leftmost and skip all further carets to the right.
LuNik700 wrote:c) we should disable the action if any carets has a selection.
Up to now I didn't care about this ... To be honest at the moment I wouldn't know how to set multiple carets with one or more having a selection ...

I'm quite sure you'll find an optimization for the code but it really was fun to dive deeper into Python ...

Best regards
Ludger
Attachments
cd_ext_find_repl.py.txt
(89.07 KiB) Downloaded 169 times
main Alexey
Posts: 2245
Joined: 25.08.2021 18:15

Post by main Alexey »

thanks. small notes:
>> #is it correct to set x ynd y to -1 when id=CARET_DELETE_ALL? It seems to work this way
I just added info about this to the API wiki (only in Github yet).
>> spaces = ""
for i in range(max_pos_x - x):
spaces += ' '
Shorter way is: spaces = ' ' * (max_pos_x - x)

How to check - do we have a selection -

Code: Select all

for (x, y, x1, y1) in crts:
  if y1>=0:
    return msg_status(_('This command cannot handle selection(s)'))
main Alexey
Posts: 2245
Joined: 25.08.2021 18:15

Post by main Alexey »

del.
Last edited by main Alexey on 06.09.2021 17:41, edited 1 time in total.
LuNik700
Posts: 18
Joined: 21.08.2021 14:56

Post by LuNik700 »

main Alexey wrote: Shorter way is: spaces = ' ' * (max_pos_x - x)
I didn't know that there is an operator for String repetition in Python. Good to know. Changed it!

I included the check for selections.

What do you think does make more sense if there is more than one caret in a line: keep the rightmost and skip those more left or vice versa? I'm really not sure. Code for both alternatives is included now ...

Thx for your comments and support, Alexey!
Attachments
cd_ext_find_repl.py.txt
(89.49 KiB) Downloaded 156 times
main Alexey
Posts: 2245
Joined: 25.08.2021 18:15

Post by main Alexey »

>keep the rightmost and skip those more left or vice versa?
Yes, keep the rightmost one.
main Alexey
Posts: 2245
Joined: 25.08.2021 18:15

Post by main Alexey »

Patch is applied,
https://github.com/kvichans/cuda_ext/co ... f25df0d6de
Will be released soon.
LuNik700
Posts: 18
Joined: 21.08.2021 14:56

Post by LuNik700 »

Thx!
Post Reply