[SOLVED] y-sort (read full info in 1st post)
-
- Posts: 23
- Joined: Mon 12 Aug, 2013 14:03
- Has thanked: 6 times
[SOLVED] y-sort (read full info in 1st post)
Edit: a solution is here: http://forum.farmanager.com/viewtopic.p ... 65#p112565
I give real-world example to describe the problem:
I using a Group for compressed files which placed in the LowerSortGroup. But I having *.7z, *.Zip, *.RAR extensions, so I need to look at 3 areas of the compressed group when I search a file just by my eyes, or when I know filename but don't remember it's compression method.
Same problem when I having much of graphics files: I don't care what the file-format (extension) is, I want to sort these graphics files by name.
The solution would be a "Sort by Name" checkbox under "Groups of File Masks/SomeGroup" dialog (where You enter file mask).
I give real-world example to describe the problem:
I using a Group for compressed files which placed in the LowerSortGroup. But I having *.7z, *.Zip, *.RAR extensions, so I need to look at 3 areas of the compressed group when I search a file just by my eyes, or when I know filename but don't remember it's compression method.
Same problem when I having much of graphics files: I don't care what the file-format (extension) is, I want to sort these graphics files by name.
The solution would be a "Sort by Name" checkbox under "Groups of File Masks/SomeGroup" dialog (where You enter file mask).
- HaRT
- Moderator
- Posts: 10869
- Joined: Tue 30 Aug, 2005 17:21
- Has thanked: 221 times
- Been thanked: 358 times
Re: SortGroup forced-sort by Name (read full info in 1st pos
Did you try “Sort by name” (CtrlF3) and “Use sort groups” (ShiftF11) simultaneously?
Фар есть инструмент, а не нянька. © 2009 DrKnS
-
- Posts: 23
- Joined: Mon 12 Aug, 2013 14:03
- Has thanked: 6 times
Re: SortGroup forced-sort by Name (read full info in 1st pos
Sorry HaRT, that is not a solution because I want sort-by-extension in general BUT sort-by-name in specific (mostly graphics, audio,compressed) groups.
To make things clearer, this is my simplified setup:
And here is an example for the current (BAD ) and the desired orders (take a look at files marked with *) :
I seeking for a picture named "big_pic": in the left (BAD) panel I scanning in all GIFs, JPGs, PNGs, PSDs, TGAs (because I don't remember it's extension) and finally I found it in TIFs - it's was too long and boring. In the right panel I scanning filenames by alphabet too and I found picture right here, where letter 'B' stays - it is convenient. (the situation is the same in case of other marked files)
In other words: sometimes extensions are indifferent in specific groups. (I think all this is meaningful in "Sort by extension" mode only)
I update my initial idea:
Idea #1: a new sort-mode "Sort by Extension except in marked Groups". (and in marked Groups sort by Name )
Idea #2: "Sort by name in marked Groups" checkbox in "Sort by" dialog (Ctrl-F12).
"Marked Groups" means that they have "Sort by Name" checkbox checked under "Groups of File Masks/SomeGroup" dialog (where You enter file mask). This checkbox is needed because (for example) I like to sort <SRC> group by Extension anyway (so I not mark it).
With the new "Custom sort" feature this function would be just a simple plugin (?).
To make things clearer, this is my simplified setup:
And here is an example for the current (BAD ) and the desired orders (take a look at files marked with *) :
I seeking for a picture named "big_pic": in the left (BAD) panel I scanning in all GIFs, JPGs, PNGs, PSDs, TGAs (because I don't remember it's extension) and finally I found it in TIFs - it's was too long and boring. In the right panel I scanning filenames by alphabet too and I found picture right here, where letter 'B' stays - it is convenient. (the situation is the same in case of other marked files)
In other words: sometimes extensions are indifferent in specific groups. (I think all this is meaningful in "Sort by extension" mode only)
I update my initial idea:
Idea #1: a new sort-mode "Sort by Extension except in marked Groups". (and in marked Groups sort by Name )
Idea #2: "Sort by name in marked Groups" checkbox in "Sort by" dialog (Ctrl-F12).
"Marked Groups" means that they have "Sort by Name" checkbox checked under "Groups of File Masks/SomeGroup" dialog (where You enter file mask). This checkbox is needed because (for example) I like to sort <SRC> group by Extension anyway (so I not mark it).
With the new "Custom sort" feature this function would be just a simple plugin (?).
-
- Posts: 6840
- Joined: Thu 23 Mar, 2006 21:36
- Location: Israel
- Has thanked: 41 times
- Been thanked: 530 times
Re: SortGroup forced-sort by Name (read full info in 1st pos
I could make for you a custom "sort all by extension except by name within groups".galaxy_far_FAR_away wrote:With the new "Custom sort" feature this function would be just a simple plugin (?).
(But there are no "marked groups" currently.)
-
- Posts: 23
- Joined: Mon 12 Aug, 2013 14:03
- Has thanked: 6 times
Re: SortGroup forced-sort by Name (read full info in 1st pos
Hi Shmuel, it's would be honorific and thank You!Shmuel wrote:I could make for you a custom "sort all by extension except by name within groups".
(But there are no "marked groups" currently.)
But I need name-sort only for specific groups.
A.) If You can access group names during sort, a solution would be: if a file's GroupName starting by underscore (_) then sort that group by name. And the new sorting mode name would be "Sort all by Extension except sort by Name within Groups started with '_' ". This way we will win "The longest possible sorting rule name" contest, at least
B.) If You can't access GroupName: I never wrote a FAR plugin from scratch but if You can share this custom sort plugin's source then I maybe can even hard-code extensions need to name-sorted and extensions need to extension-sorted.
Thank You anyway!
-
- Posts: 6840
- Joined: Thu 23 Mar, 2006 21:36
- Location: Israel
- Has thanked: 41 times
- Been thanked: 530 times
SortGroup forced-sort by Name (read full info in 1st pos
Currently, we can't access group name of a panel element (even Far itself can't). And keep in mind that a panel element may belong to multiple groups (though Far picks up the first one matched). All we can know about the group is the value of SortGroup: it is 0 if an element doesn't belong to any sort group, otherwise it can be either negative or positive.galaxy_far_FAR_away wrote:But I need name-sort only for specific groups.
[......]
B.) If You can't access GroupName: I never wrote a FAR plugin from scratch but if You can share this custom sort plugin's source then I maybe can even hard-code extensions need to name-sorted and extensions need to extension-sorted.
So, currently only option "B" is available.
Here is the contents of a macrofile, name it e.g. mysort1.lua, place it into %FARPROFILE%\Macros\scripts and restart Far. Pressing CtrlShiftF2 will invoke this custom sorting.
-
- Posts: 23
- Joined: Mon 12 Aug, 2013 14:03
- Has thanked: 6 times
Re: SortGroup forced-sort by Name (read full info in 1st pos
Yes, this works exactly like it's name says! Thank You!
A bit problem is that however I know C/C++ well but I'm absolute stupid in LUA/FARLUA
Can You tell me how can I compare extension of pi1.FileName with the string "cpp"?
I'm lost in dungeons of the C/FARLUA string conversions... Walking in an unknown area is so bad feeling
Sorry for the absolute noob question but You can give an 1 line long answer in no seconds, I think.
Thank You!
PS: petition for direct access SortGroups from custom sort routines!!!
A bit problem is that however I know C/C++ well but I'm absolute stupid in LUA/FARLUA
Can You tell me how can I compare extension of pi1.FileName with the string "cpp"?
I'm lost in dungeons of the C/FARLUA string conversions... Walking in an unknown area is so bad feeling
Sorry for the absolute noob question but You can give an 1 line long answer in no seconds, I think.
Thank You!
PS: petition for direct access SortGroups from custom sort routines!!!
-
- Posts: 6840
- Joined: Thu 23 Mar, 2006 21:36
- Location: Israel
- Has thanked: 41 times
- Been thanked: 530 times
SortGroup forced-sort by Name (read full info in 1st pos
This kind of programming (LuaJIT FFI) is not so pleasant as pure Lua is, it has been chosen due to performance reasons.galaxy_far_FAR_away wrote:A bit problem is that however I know C/C++ well but I'm absolute stupid in LUA/FARLUA
Can You tell me how can I compare extension of pi1.FileName with the string "cpp"?
I'm lost in dungeons of the C/FARLUA string conversions... Walking in an unknown area is so bad feeling
-
- Posts: 23
- Joined: Mon 12 Aug, 2013 14:03
- Has thanked: 6 times
Here is the solution! Not so nice but works :)
Finally here is what I wanted, a new sort-mode named "y-sort" "y-sort" means "Sort by extension but sort audio/graphics/compressed files by name". Of course, I having different SortGroups for audio/graphics/compressed files.
Unzip attachment to %FARPROFILE%\Macros\Scripts, restart FAR then press Ctrl-X to toggle between traditional extension sort/y-sort (...and Ctrl-W for sort by write-time, Ctrl-S for sort by size). You can modify script easily to fit Your needs (no programming knowledge needs), check .lua!
If we could use "Group of file masks" then we could benefit from it's regular expressions too. (not to mention we could eliminate that ugly hard-coded sort_by_name_t )
Again, thanks Shmuel for helping!
Edit1: thanks t-rex for the fix!
Edit2: "DirectoriesFirst=1" added
Edit3: (2013-08-26): Updated for today's nightly build, so works only with version >= 2013-08-26. Thanks Shmuel for speed-up optimization.
Edit4: (2013-09-12): Updated for FAR 3 build 3649
Unzip attachment to %FARPROFILE%\Macros\Scripts, restart FAR then press Ctrl-X to toggle between traditional extension sort/y-sort (...and Ctrl-W for sort by write-time, Ctrl-S for sort by size). You can modify script easily to fit Your needs (no programming knowledge needs), check .lua!
If we could use "Group of file masks" then we could benefit from it's regular expressions too. (not to mention we could eliminate that ugly hard-coded sort_by_name_t )
Again, thanks Shmuel for helping!
Edit1: thanks t-rex for the fix!
Edit2: "DirectoriesFirst=1" added
Edit3: (2013-08-26): Updated for today's nightly build, so works only with version >= 2013-08-26. Thanks Shmuel for speed-up optimization.
Edit4: (2013-09-12): Updated for FAR 3 build 3649
- Attachments
-
- Sort-modes 3649.lua.zip
- (2.12 KiB) Downloaded 318 times
Last edited by galaxy_far_FAR_away on Thu 12 Sep, 2013 05:01, edited 4 times in total.
- t-rex
- Страшный и ужасный
- Posts: 4910
- Joined: Tue 15 Mar, 2005 16:17
- Location: Tel-Aviv
- Has thanked: 1 time
- Been thanked: 8 times
- Contact:
Re: SortGroup forced-sort by Name (read full info in 1st pos
Add SORT_STRINGSORT to the flags of CompareStringW to get same behaviour as Far.
-
- Posts: 6840
- Joined: Thu 23 Mar, 2006 21:36
- Location: Israel
- Has thanked: 41 times
- Been thanked: 530 times
SortGroup forced-sort by Name (read full info in 1st pos
It looks somewhat strange that the above piece of code takes into account only 1-st compared element and completely ignores the 2-nd. Is it logically correct?
-
- Posts: 23
- Joined: Mon 12 Aug, 2013 14:03
- Has thanked: 6 times
Re: SortGroup forced-sort by Name (read full info in 1st pos
Well, I felt the same
But:
1.) You wrote "if pi1.Reserved[1] == pi2.Reserved[1] then", so pi1 & pi2 are in the same SortGroup, means that if "ext1~=nil" then ext2 isn't nil also
2.) I using "Show directories first" and seems FAR not mix directories with files during sort, so enough to check pi1 or pi2 for directory attribute (damn, took hours for me to search letter "d" in pi1.FileAttributes as stated in luafar_manual.chm... Where I goes wrong interpret FAR's documentation?)
3.) Similarly, if pi1 extension is in the sort_by_name_ext_t then pi2 will be also in that table because seems FAR not mix SortGroups during sort (maybe having different extension but both are in the same SortGroup and all extensions of that SortGroup are in table 'sort_by_name_ext_t')
In other words: if both pi1 & pi2 are in the same SortGroup then enough to check only pi1 or pi2.
As long as I using sort groups, and using a sort group only for extensions (and I include an extension in 1 SortGroup only), code seems to be correct and works very well for my pleasure in practice (however not tested by a test-department yet)
Of course, it is possible to write a theoretically more correct code but in practice, this code reached the minimum functionality for me. For now.
Feel free to correct me & fix code - seems this is the first CustomSort usage (?) (!)
But:
1.) You wrote "if pi1.Reserved[1] == pi2.Reserved[1] then", so pi1 & pi2 are in the same SortGroup, means that if "ext1~=nil" then ext2 isn't nil also
2.) I using "Show directories first" and seems FAR not mix directories with files during sort, so enough to check pi1 or pi2 for directory attribute (damn, took hours for me to search letter "d" in pi1.FileAttributes as stated in luafar_manual.chm... Where I goes wrong interpret FAR's documentation?)
3.) Similarly, if pi1 extension is in the sort_by_name_ext_t then pi2 will be also in that table because seems FAR not mix SortGroups during sort (maybe having different extension but both are in the same SortGroup and all extensions of that SortGroup are in table 'sort_by_name_ext_t')
In other words: if both pi1 & pi2 are in the same SortGroup then enough to check only pi1 or pi2.
As long as I using sort groups, and using a sort group only for extensions (and I include an extension in 1 SortGroup only), code seems to be correct and works very well for my pleasure in practice (however not tested by a test-department yet)
Of course, it is possible to write a theoretically more correct code but in practice, this code reached the minimum functionality for me. For now.
Feel free to correct me & fix code - seems this is the first CustomSort usage (?) (!)
-
- Posts: 6840
- Joined: Thu 23 Mar, 2006 21:36
- Location: Israel
- Has thanked: 41 times
- Been thanked: 530 times
Re: SortGroup forced-sort by Name (read full info in 1st pos
-- It is not Far that does custom sorting, it is plugin LuaMacro.galaxy_far_FAR_away wrote:2.) I using "Show directories first" and seems FAR not mix directories with files during sort, so enough to check pi1 or pi2 for directory attribute
-- If your "y-sort" requires "Show directories first" to be on, then put it in explicitly, e.g.:
Code: Select all
SortGroups=1; DirectoriesFirst=1;
As I mentioned earlier today, custom sorting uses LuaJIT FFI. PluginPanelItem described in LuaFAR manual and PluginPanelItem being used in custom sorting are two different beasts: the first is a Lua table (described in the manual) and the second is a pointer/reference to a C-struct residing in physical memory.(damn, took hours for me to search letter "d" in pi1.FileAttributes as stated in luafar_manual.chm... Where I goes wrong interpret FAR's documentation?)
No, see http://forum.farmanager.com/viewtopic.p ... 10#p112410 and the following posts.Feel free to correct me & fix code - seems this is the first CustomSort usage (?) (!)
-
- Posts: 23
- Joined: Mon 12 Aug, 2013 14:03
- Has thanked: 6 times
[SOLVED] y-sort (read full info in 1st post)
Today I changed my PC radically: after years of 32 bit I installed a fresh 64 bit Win7 and downloaded latest FAR (build 4425 x64). Seems like after these changes Y-Sort doesn't work.
"Sort-modes.lua:249: bad argument #1 to 'band' (number expected, got cdata)"
I'm absolutely noob in LUA, but I think a professional can correct this line in NO time.
Of course I can make tests to track-down this problem, but I'm tired for this day and just like to use my PC as before
Many thanks for Your answer!
I attached LUA script to this message
"Sort-modes.lua:249: bad argument #1 to 'band' (number expected, got cdata)"
I'm absolutely noob in LUA, but I think a professional can correct this line in NO time.
Of course I can make tests to track-down this problem, but I'm tired for this day and just like to use my PC as before
Many thanks for Your answer!
I attached LUA script to this message
- Attachments
-
- Sort-modes.lua
- (6.73 KiB) Downloaded 356 times