AtSynEdit - Sort Lines of Text

Post Reply
TomC
Posts: 13
Joined: 29.05.2022 05:11

AtSynEdit - Sort Lines of Text

Post by TomC »

I'm converting over from SynEdit to AtSynEdit

Question:
- What is the best way to sort "selected lines" of text.

Thank You Sincerely..
main Alexey
Posts: 2245
Joined: 25.08.2021 18:15

Post by main Alexey »

ATSynEdit already has the command for sorting,
call Ed.DoCommand(XXXX) with these codes:

Code: Select all

uses ATSynEdit_Commands;

  cCommand_Sort_Asc        = 330;
  cCommand_Sort_AscNoCase  = 331;
  cCommand_Sort_Desc       = 332;
  cCommand_Sort_DescNoCase = 333;
TomC
Posts: 13
Joined: 29.05.2022 05:11

Post by TomC »

I'm still new at all this..

I tried:
Ed.DoCommand(cCommand_Sort_Asc,cInvokeInternal,'');
I'm not fully understanding 2nd Parameter..
This TATEditorCommandInvoke cInvokeInternal, cInvokeHotkey, etc.. is probably? Use Hotkey method if one is available, or Invoke an internal method.. ?
3rd Parameter is a String, not sure is this string is used or altered..

If I run this DoCommand on the Ed:
- Then every line is sorted, blank lines are removed.
If I Select/Block a couple lines:
- Then it sorts all lines from beginning of file, up to my selected lines, but no lines after, and blank lines are removed.
I also noticed that Undo doesn't seem to be available after the sort (again I'm new to all this)

My Goal is (with option to Keep or Not Keep blank lines):
- If "couple lines blocked", then sort only those lines
- If "nothing blocked" then sort all lines in whole file

Maybe (only guessing) there is an "Ed.DoCommand(.." and an Ed.Selected.DoCommand(..",, not sure..

Thank You Sincerely..
main Alexey
Posts: 2245
Joined: 25.08.2021 18:15

Post by main Alexey »

>I'm not fully understanding 2nd Parameter..
That parameter was needed for CudaText plugin;
so you can use any value.
>3rd Parameter is a String, not sure is this string is used or altered..
just pass the empty string.
>Then it sorts all lines from beginning of file, up to my selected lines, but no lines after, and blank lines are removed.
I also noticed that Undo doesn't seem to be available after the sort (again I'm new to all this)
these commands do not keep Undo!
that is limitation of them.

no, they must work for only selected block, not for lines above the block.
i tested it in CudaText.
CudaText Command Palette has these commands, and i tested them.
from file text
z
e
d

f
z
a

a
c
I selected middle part: f z a
and called in CudaText "sort asc, without undo".
it has some issues which I must fix: it removed empty lines above the block, which is bad.

all in all, you should make custom sorting. my current sorting has issues.
main Alexey
Posts: 2245
Joined: 25.08.2021 18:15

Post by main Alexey »

CudaText has 'good sorting' too (plugin 'Sort'), which don't remove empty lines and works ok,
but it's made as Python command, so you must make similar code in Pascal.
main Alexey
Posts: 2245
Joined: 25.08.2021 18:15

Post by main Alexey »

fixed the sorting command - now it must not delete empty lines (ie it deletes them only if all text is handled).
Post Reply