de-vri-es / weechat-autosort

Automatically keep your buffers sorted.
GNU General Public License v3.0
76 stars 8 forks source link

Sorting rules don't eval properly #14

Closed LenaicTerrier closed 5 years ago

LenaicTerrier commented 5 years ago

Hello,

I can't make autosort output something useful on debug, and it won't sort.

The install:

Here is an output of the rules (default I believe):

    0: ${core_first}
    1: ${irc_last}
    2: ${buffer.plugin.name}
    3: ${irc_raw_first}
    4: ${if:${plugin}==irc?${server}}
    5: ${if:${plugin}==irc?${info:autosort_order,${type},server,*,channel,private}}
    6: ${if:${plugin}==irc?${hashless_name}}
    7: ${buffer.full_name}

And here is a debug:

autosort: core.weechat: ['', '', '', '', '', '', '', 'core.weechat']
autosort: irc.s1.#c1: ['', '', 'irc', '', '', '', '', 'irc.s1.#c1']
autosort: irc.s1.q1: ['', '', 'irc', '', '', '', '', 'irc.s1.q1']
autosort: irc.s2.#c2: ['', '', 'irc', '', '', '', '', 'irc.s2.#c2']
autosort: irc.server.s1: ['', '', 'irc', '', '', '', '', 'irc.server.s1']
autosort: irc.server.s2: ['', '', 'irc', '', '', '', '', 'irc.server.s2']
autosort: irc.server.s3: ['', '', 'irc', '', '', '', '', 'irc.server.s3']
autosort: irc.s3.q2: ['', '', 'irc', '', '', '', '', 'irc.s3.q2']

The strings s1, s2, s3 are three servers weechat is connected to. The strings #c1 and #c2 are two canals weechat has joined. The stings q1 and q2 are two private chat with users (/query). They are anonymized but the output stays coherent except for alphabetical order.

Seems to me, the ${if:} expression isn't doing what it's supposed to do as the only two rules that output something are those who doesn't use the expression.

The other possibility being this is the normal behavior and then it's me who doesn't understand how to make the plugin work.

Thank you for you time.

Edit : I've played a bit with the rules. And I can confirm I can't make the if expression work. Doesn't output anything.

de-vri-es commented 5 years ago

Those indeed look like the default rules. The most likely cause is your weechat version. Version 1.6 is relatively old. If it is possible for you I would recommend updating weechat. I expect that will make the default rules work as intended.

However, it should still be possible to make it more or less work without if statements. For example, you could turn them into:

    0: ${core_first}
    1: ${irc_last}
    2: ${buffer.plugin.name}
    3: ${irc_raw_first}
    4: ${server}
    5: ${info:autosort_order,${type},server,*,channel,private}
    6: ${hashless_name}
    7: ${buffer.full_name}

Some of these will still be broken, but basic functionality should be there. The if statements in rule 4, 5 and 6 are mainly there to avoid doing stupid sorting on slack channels, but that's only a problem if you use the slack script.

LenaicTerrier commented 5 years ago

Oh... Well that's not an option. I'm running Weechat on a Debian stable (stretch) server in a tmux terminal. The current version of Weechat on stable is 1.6. I can't really dive into unstable just for Weechat. I guess I will have unsorted buffers for a time.

de-vri-es commented 5 years ago

Did you try without the ${if:..} for rules 4, 5 and 6? Because I think it would work for most setups that way too.

LenaicTerrier commented 5 years ago

No, mainly because the rules that don't use if use helpers that do. Helpers are

core_first: ${if:${buffer.full_name}!=core.weechat}                                                                                        
hashless_name: ${info:autosort_replace,#,,${buffer.name}}                                                                                      
irc_first: ${if:${buffer.plugin.name}!=irc}                                                                                              
irc_last: ${if:${buffer.plugin.name}==irc}                                                                                                  
irc_raw_first: ${if:${buffer.full_name}!=irc.irc_raw}                                                                                        
irc_raw_last: ${if:${buffer.full_name}==irc.irc_raw} 
de-vri-es commented 5 years ago

True, those wont work, but it's mainly rule 4, 5 and 6 that should ensure the tree-like sorting of IRC buffers. The sorting of non-irc buffers might not be exactly what you want, but there are alternatives even for those.

de-vri-es commented 5 years ago

PR to scripts repo submitted: https://github.com/weechat/scripts/pull/341