%D \module
%D   [      file=s-structure-sections,
%D        version=2015.02.02,
%D          title=\CONTEXT\ Style File,
%D       subtitle=Show Structure Sections,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\unprotect

\startluacode
    local context = context
    local ctx_NC, ctx_NR = context.NC, context.NR
    local ctx_bold = context.bold

    structures.tracers = structures.tracers or { }

    function structures.tracers.showsections()

        local list = structures.sections.registered
        local keys = table.keys(list)
        table.sort(keys,function(a,b)
            local la, lb = list[a].level, list[b].level
            if la == lb then
                return a < b
            else
                return la < lb
            end
        end)
        context.start()
        context.switchtobodyfont { "tt" }
        context.starttabulate { "||c||||" }
        context.FL()
        ctx_NC() ctx_bold("name")
        ctx_NC() ctx_bold("level")
        ctx_NC() ctx_bold("parent")
        ctx_NC() ctx_bold("section")
        ctx_NC() ctx_bold("coupling")
        ctx_NC() context.NR()
        context.ML()
        for i=1,#keys do
            local k = keys[i]
            local v = list[k]
            ctx_NC() ctx_bold(k)
            ctx_NC() context(v.level)
            ctx_NC() context(v.parent)
            ctx_NC() context(v.section)
            ctx_NC() context(v.coupling)
            ctx_NC() context.NR()
        end
        context.LL()
        context.stoptabulate()
        context.stop()

    end
\stopluacode


\starttexdefinition showstructuresections

    % no settings yet

    \ctxlua{structures.tracers.showsections()}

\stoptexdefinition

\protect

\continueifinputfile{s-structure-sections.mkiv}

\starttext

    \showstructuresections

\stoptext
