[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.
Post Reply
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 » Mon 12 Aug, 2013 14:36

Edit: a solution is here: viewtopic.php?f=38&t=8135&p=112565#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: 8118
Joined: Tue 30 Aug, 2005 17:21
Location: Санкт-Петербург
Has thanked: 68 times
Been thanked: 107 times

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

Post by HaRT » Mon 12 Aug, 2013 15:25

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 » Wed 14 Aug, 2013 11:29

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: 5232
Joined: Thu 23 Mar, 2006 21:36
Location: Israel
Has thanked: 16 times
Been thanked: 152 times

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

Post by Shmuel » Wed 14 Aug, 2013 12:56

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 » Sat 17 Aug, 2013 12:24

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: 5232
Joined: Thu 23 Mar, 2006 21:36
Location: Israel
Has thanked: 16 times
Been thanked: 152 times

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

Post by Shmuel » Sat 17 Aug, 2013 13:22

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 » Sat 17 Aug, 2013 20:55

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: 5232
Joined: Thu 23 Mar, 2006 21:36
Location: Israel
Has thanked: 16 times
Been thanked: 152 times

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

Post by Shmuel » Sat 17 Aug, 2013 21:31

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 » Sun 18 Aug, 2013 15:52

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 117 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: 4872
Joined: Tue 15 Mar, 2005 16:17
Location: Tel-Aviv
Contact:

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

Post by t-rex » Sun 18 Aug, 2013 16:01

Add SORT_STRINGSORT to the flags of CompareStringW to get same behaviour as Far.

Shmuel
Posts: 5232
Joined: Thu 23 Mar, 2006 21:36
Location: Israel
Has thanked: 16 times
Been thanked: 152 times

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

Post by Shmuel » Sun 18 Aug, 2013 18:15

  1. local ext1 = GetExt(pi1.FileName)
  2. local namesort = 0~=bit.band(pi1.FileAttributes,FILE_ATTRIBUTE_DIRECTORY)
  3.  
  4. if (not namesort and ext1~=nil)
  5. then                           --search for extension forced to sort by name
  6.   for i=1,sort_by_name_ext_t_s
  7.   do
  8.     if (0==CmpStr(ext1,sort_by_name_ext_t[i]))
  9.     then
  10.       namesort = true
  11.       break
  12.     end
  13.   end
  14. 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 » Sun 18 Aug, 2013 20:52

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: 5232
Joined: Thu 23 Mar, 2006 21:36
Location: Israel
Has thanked: 16 times
Been thanked: 152 times

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

Post by Shmuel » Sun 18 Aug, 2013 21:33

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 viewtopic.php?p=112410#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 » Thu 24 Sep, 2015 20:33

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 66 times

Shmuel
Posts: 5232
Joined: Thu 23 Mar, 2006 21:36
Location: Israel
Has thanked: 16 times
Been thanked: 152 times

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

Post by Shmuel » Thu 24 Sep, 2015 21:18

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

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 » Fri 25 Sep, 2015 11:00

Many thanxxxxxxxxxxxxxxxxxx! :)

Post Reply

Return to “Suggestions and Ideas”