<commit_before>--
-- ion/share/ioncore_winprops.lua
-- 
-- Copyright (c) <NAME> 2004-2007.
--
-- See the included file LICENSE for details.
--

local ioncore=_G.ioncore

local winprops={}

local function ifnil(...)
    local n=#arg
    local function nxt(_, i)
        local j=i+1
        if i==n then
            return nil
        else
            local j=i+1
            if not arg[j] then
                return nxt(nil, j)
            else
                return j, arg[j]
            end
        end
    end
            
    return nxt, nil, 0
end

local function ipairs_r(tab)
    local function nxt(_, n)
        if n==1 then
            return nil
        else
            return n-1, tab[n-1]
        end
    end
    return nxt, nil, #tab+1
end

--DOC
-- Find winprop table for \var{cwin}.
function ioncore.getwinprop(cwin)
    local id=cwin:get_ident()
    local props, prop

    for _, c in ifnil(id.class, "*") do
        for _, r in ifnil(id.role, "*") do
            for _, i in ifnil(id.instance, "*") do
                --printpp(c, r, i)
                props={}
                pcall(function() props=winprops[c][r][i] or {} end)
                for idx, prop in ipairs_r(props) do
                    if prop:match(cwin, id) then
                        if prop.oneshot then
                            table.remove(props, idx)
                        end
                        return prop
                    end
                end
            end
        end
    end
end

ioncore.set{_get_winprop=ioncore.getwinprop}

local function ensure_winproptab(class, role, instance)
    if not winprops[class] then
        winprops[class]={}
    end
    if not winprops[class][role] then
        winprops[class][role]={}
    end
    if not winprops[class][role][instance] then
        winprops[class][role][instance]={}
    end
end    

local function do_add_winprop(class, role, instance, prop)
    ensure_winproptab(class, role, instance)
    table.insert(winprops[class][role][instance], prop)
end


--DOC
-- The basic name-based winprop matching criteria.
function ioncore.match_winprop_dflt(prop, cwin, id)
    local function chkf(p, i)
        if p==nil then
            return true
        else
            return (p==(i and true)) 
                           -- hack for nil<commit_msg>Winprop matching hack fix (?)<commit_after>--
-- ion/share/ioncore_winprops.lua
-- 
-- Copyright (c) <NAME> 2004-2007.
--
-- See the included file LICENSE for details.
--

local ioncore=_G.ioncore

local winprops={}

local function ifnil(...)
    local n=#arg
    local function nxt(_, i)
        local j=i+1
        if i==n then
            return nil
        else
            local j=i+1
            if not arg[j] then
                return nxt(nil, j)
            else
                return j, arg[j]
            end
        end
    end
            
    return nxt, nil, 0
end

local function ipairs_r(tab)
    local function nxt(_, n)
        if n==1 then
            return nil
        else
            return n-1, tab[n-1]
        end
    end
    return nxt, nil, #tab+1
end

--DOC
-- Find winprop table for \var{cwin}.
function ioncore.getwinprop(cwin)
    local id=cwin:get_ident()
    local props, prop

    for _, c in ifnil(id.class, "*") do
        for _, r in ifnil(id.role, "*") do
            for _, i in ifnil(id.instance, "*") do
                --printpp(c, r, i)
                props={}
                pcall(function() props=winprops[c][r][i] or {} end)
                for idx, prop in ipairs_r(props) do
                    if prop:match(cwin, id) then
                        if prop.oneshot then
                            table.remove(props, idx)
                        end
                        return prop
                    end
                end
            end
        end
    end
end

ioncore.set{_get_winprop=ioncore.getwinprop}

local function ensure_winproptab(class, role, instance)
    if not winprops[class] then
        winprops[class]={}
    end
    if not winprops[class][role] then
        winprops[class][role]={}
    end
    if not winprops[class][role][instance] then
        winprops[class][role][instance]={}
    end
end    

local function do_add_winprop(class, role, instance, prop)
    ensure_winproptab(class, role, instance)
    table.insert(winprops[class][role][instance], prop)
end


--DOC
-- The basic name-based winprop matching criteria.
function ioncore.match_winprop_dflt(prop, cwin, id)
    local function chkf(p, i)
        if p==nil then
            return true
        else
            return (p==(i and true or false)) 
                           -- hack for nil i
{'fraction_non_alphanumeric': 0.100925328168711, 'fraction_numerical': 0.006455777921239509, 'mean_word_length': 1.5622932745314222, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '491263', 'n_tokens_mistral': 1464, 'n_tokens_neox': 1413, 'n_words': 412}