[SOLVED] y-sort (read full info in 1st post)

Something is missing in Far Manager? You have a great idea that should be heard? Write here.
galaxy_far_FAR_away
Posts: 23
Joined: Mon 12 Aug, 2013 14:03
Has thanked: 6 times

[SOLVED] y-sort (read full info in 1st post)

Post by galaxy_far_FAR_away »

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).
User avatar
HaRT
Moderator
Posts: 10822
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

Post by HaRT »

Did you try “Sort by name” (CtrlF3) and “Use sort groups” (ShiftF11) simultaneously?
Фар есть инструмент, а не нянька. © 2009 DrKnS
galaxy_far_FAR_away
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

Post by galaxy_far_FAR_away »

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 :wink: ) 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 (?).
Shmuel
Posts: 6819
Joined: Thu 23 Mar, 2006 21:36
Location: Israel
Has thanked: 41 times
Been thanked: 528 times

Re: SortGroup forced-sort by Name (read full info in 1st pos

Post by Shmuel »

galaxy_far_FAR_away wrote:With the new "Custom sort" feature this function would be just a simple plugin (?).
I could make for you a custom "sort all by extension except by name within groups".
(But there are no "marked groups" currently.)
galaxy_far_FAR_away
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

Post by galaxy_far_FAR_away »

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.)
Hi Shmuel, it's would be honorific and thank You!

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!
Shmuel
Posts: 6819
Joined: Thu 23 Mar, 2006 21:36
Location: Israel
Has thanked: 41 times
Been thanked: 528 times

SortGroup forced-sort by Name (read full info in 1st pos

Post by Shmuel »

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.
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.

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.

galaxy_far_FAR_away
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

Post by galaxy_far_FAR_away »

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!!!
Shmuel
Posts: 6819
Joined: Thu 23 Mar, 2006 21:36
Location: Israel
Has thanked: 41 times
Been thanked: 528 times

SortGroup forced-sort by Name (read full info in 1st pos

Post by Shmuel »

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 :(
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
Posts: 23
Joined: Mon 12 Aug, 2013 14:03
Has thanked: 6 times

Here is the solution! Not so nice but works :)

Post by galaxy_far_FAR_away »

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! :good:

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 316 times
Last edited by galaxy_far_FAR_away on Thu 12 Sep, 2013 05:01, edited 4 times in total.
User avatar
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

Post by t-rex »

Add SORT_STRINGSORT to the flags of CompareStringW to get same behaviour as Far.
Shmuel
Posts: 6819
Joined: Thu 23 Mar, 2006 21:36
Location: Israel
Has thanked: 41 times
Been thanked: 528 times

SortGroup forced-sort by Name (read full info in 1st pos

Post by Shmuel »

  1. local ext1 = GetExt(pi1.FileName)
  2.  
  3. local namesort = 0~=bit.band(pi1.FileAttributes,FILE_ATTRIBUTE_DIRECTORY)
  4.  
  5.  
  6.  
  7. if (not namesort and ext1~=nil)
  8.  
  9. then                           --search for extension forced to sort by name
  10.  
  11.   for i=1,sort_by_name_ext_t_s
  12.  
  13.   do
  14.  
  15.     if (0==CmpStr(ext1,sort_by_name_ext_t[i]))
  16.  
  17.     then
  18.  
  19.       namesort = true
  20.  
  21.       break
  22.  
  23.     end
  24.  
  25.   end
  26.  
  27. end
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?
galaxy_far_FAR_away
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

Post by galaxy_far_FAR_away »

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 (?) (!)
Shmuel
Posts: 6819
Joined: Thu 23 Mar, 2006 21:36
Location: Israel
Has thanked: 41 times
Been thanked: 528 times

Re: SortGroup forced-sort by Name (read full info in 1st pos

Post by Shmuel »

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
-- It is not Far that does custom sorting, it is plugin LuaMacro.
-- 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;
Otherwise you depend on the current Far setting and may be surprised by the results.
(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?)
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.
Feel free to correct me & fix code - seems this is the first CustomSort usage (?) (!)
No, see http://forum.farmanager.com/viewtopic.p ... 10#p112410 and the following posts.
galaxy_far_FAR_away
Posts: 23
Joined: Mon 12 Aug, 2013 14:03
Has thanked: 6 times

[SOLVED] y-sort (read full info in 1st post)

Post by galaxy_far_FAR_away »

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
Attachments
Sort-modes.lua
(6.73 KiB) Downloaded 351 times
Shmuel
Posts: 6819
Joined: Thu 23 Mar, 2006 21:36
Location: Israel
Has thanked: 41 times
Been thanked: 528 times

[SOLVED] y-sort (read full info in 1st post)

Post by Shmuel »

Replace pi1.FileAttributes with tonumber(pi1.FileAttributes).
Post Reply

Return to “Suggestions and Ideas”