From 5b2b3fefb3c4c8e438e4b413e89dd355ce3d7743 Mon Sep 17 00:00:00 2001
From: Hans Hagen <pragma@wxs.nl>
Date: Sun, 14 Apr 2013 00:32:00 +0200
Subject: beta 2013.04.14 00:32

---
 tex/context/base/cont-new.mkiv       |   2 +-
 tex/context/base/context-version.pdf | Bin 4133 -> 4134 bytes
 tex/context/base/context-version.png | Bin 40480 -> 40477 bytes
 tex/context/base/context.mkiv        |   2 +-
 tex/context/base/mult-def.mkiv       |   2 ++
 tex/context/base/mult-sys.mkiv       |   2 ++
 tex/context/base/page-flt.lua        |  20 +++++++++-------
 tex/context/base/status-files.pdf    | Bin 24721 -> 24733 bytes
 tex/context/base/status-lua.pdf      | Bin 211776 -> 211781 bytes
 tex/context/base/strc-doc.lua        |  39 +++++++++++++++++++++----------
 tex/context/base/strc-flt.mkvi       |  34 ++++++++++++++++++++++-----
 tex/context/base/strc-lst.lua        |  44 ++++++++++++++++++++++++++---------
 tex/context/base/strc-num.mkiv       |   8 ++++---
 13 files changed, 110 insertions(+), 43 deletions(-)

diff --git a/tex/context/base/cont-new.mkiv b/tex/context/base/cont-new.mkiv
index 060baa4da..01079a058 100644
--- a/tex/context/base/cont-new.mkiv
+++ b/tex/context/base/cont-new.mkiv
@@ -11,7 +11,7 @@
 %C therefore copyrighted by \PRAGMA. See mreadme.pdf for
 %C details.
 
-\newcontextversion{2013.04.12 17:05}
+\newcontextversion{2013.04.14 00:32}
 
 %D This file is loaded at runtime, thereby providing an excellent place for
 %D hacks, patches, extensions and new features.
diff --git a/tex/context/base/context-version.pdf b/tex/context/base/context-version.pdf
index 6f147a5dd..9206cdae8 100644
Binary files a/tex/context/base/context-version.pdf and b/tex/context/base/context-version.pdf differ
diff --git a/tex/context/base/context-version.png b/tex/context/base/context-version.png
index 5f2043177..2e85a21cd 100644
Binary files a/tex/context/base/context-version.png and b/tex/context/base/context-version.png differ
diff --git a/tex/context/base/context.mkiv b/tex/context/base/context.mkiv
index cdde12823..90b9a3ff2 100644
--- a/tex/context/base/context.mkiv
+++ b/tex/context/base/context.mkiv
@@ -25,7 +25,7 @@
 %D up and the dependencies are more consistent.
 
 \edef\contextformat {\jobname}
-\edef\contextversion{2013.04.12 17:05}
+\edef\contextversion{2013.04.14 00:32}
 \edef\contextkind   {beta}
 
 %D For those who want to use this:
diff --git a/tex/context/base/mult-def.mkiv b/tex/context/base/mult-def.mkiv
index 22b3880f6..274010692 100644
--- a/tex/context/base/mult-def.mkiv
+++ b/tex/context/base/mult-def.mkiv
@@ -54,6 +54,8 @@
 \def\c!down             {down}
 \def\c!instance         {instance}
 \def\c!database         {database}
+\def\c!group            {group}
+\def\c!groupsuffix      {groupsuffix}
 
 \def\v!compressseparator{compressseparator}
 \def\v!notation         {notation}
diff --git a/tex/context/base/mult-sys.mkiv b/tex/context/base/mult-sys.mkiv
index 135d8bcf7..c184d91b5 100644
--- a/tex/context/base/mult-sys.mkiv
+++ b/tex/context/base/mult-sys.mkiv
@@ -264,6 +264,8 @@
 \definesystemconstant {hastitle}
 \definesystemconstant {hascaption}
 \definesystemconstant {haslevel}
+\definesystemconstant {hasparent}
+\definesystemconstant {hassuffix}
 
 \definesystemconstant {mkiv}
 \definesystemconstant {mkii}
diff --git a/tex/context/base/page-flt.lua b/tex/context/base/page-flt.lua
index 68383f175..ab7a534eb 100644
--- a/tex/context/base/page-flt.lua
+++ b/tex/context/base/page-flt.lua
@@ -236,13 +236,15 @@ function floats.nofstacked()
     return #stacks[which or default] or 0
 end
 
+-- todo: check for digits !
+
 local method   = C((1-S(", :"))^1)
-local position = P(":") * C((1-S("*,"))^1) * P("*") * C((1-S(","))^1)
+local position = P(":") * C((1-S("*,"))^1) * (P("*") * C((1-S(","))^1))^0
 local label    = P(":") * C((1-S(",*: "))^0)
 
 local pattern = method * (
-    label * position
-  + C("") * position
+    label * position * C("")
+  + C("") * position * C("")
   + label * C("") * C("")
   + C("") * C("") * C("")
 ) + C("") * C("") * C("") * C("")
@@ -255,7 +257,7 @@ local pattern = method * (
 -- inspect { lpegmatch(pattern,"somewhere") }
 -- inspect { lpegmatch(pattern,"") }
 
-function floats.analysemethod(str)
+function floats.analysemethod(str) -- will become a more extensive parser
     return lpegmatch(pattern,str or "")
 end
 
@@ -278,10 +280,10 @@ function commands.checkedpagefloat  (...) local v = floats.checkedpagefloat(...)
 function commands.nofstackedfloats  (...) context(floats.nofstacked(...))             end
 function commands.doifelsesavedfloat(...) commands.doifelse(floats.nofstacked(...)>0) end
 
-function commands.analysefloatmethod(str)
+function commands.analysefloatmethod(str) -- currently only one method
     local method, label, row, column = floats.analysemethod(str)
-    setvalue("floatmethod",method)
-    setvalue("floatlabel", label )
-    setvalue("floatrow",   row   )
-    setvalue("floatcolumn",column)
+    setvalue("floatmethod",method or "")
+    setvalue("floatlabel", label  or "")
+    setvalue("floatrow",   row    or "")
+    setvalue("floatcolumn",column or "")
 end
diff --git a/tex/context/base/status-files.pdf b/tex/context/base/status-files.pdf
index 03cdd253e..36f371e1e 100644
Binary files a/tex/context/base/status-files.pdf and b/tex/context/base/status-files.pdf differ
diff --git a/tex/context/base/status-lua.pdf b/tex/context/base/status-lua.pdf
index 02f32d3fd..996325102 100644
Binary files a/tex/context/base/status-lua.pdf and b/tex/context/base/status-lua.pdf differ
diff --git a/tex/context/base/strc-doc.lua b/tex/context/base/strc-doc.lua
index a25d1e1b0..50a9e67a0 100644
--- a/tex/context/base/strc-doc.lua
+++ b/tex/context/base/strc-doc.lua
@@ -593,6 +593,7 @@ function sections.typesetnumber(entry,kind,...) -- kind='section','number','pref
         local separatorset  = ""
         local conversionset = ""
         local conversion    = ""
+        local groupsuffix   = ""
         local stopper       = ""
         local starter       = ""
         local connector     = ""
@@ -605,6 +606,7 @@ function sections.typesetnumber(entry,kind,...) -- kind='section','number','pref
                 if separatorset  == "" then separatorset  = data.separatorset  or "" end
                 if conversionset == "" then conversionset = data.conversionset or "" end
                 if conversion    == "" then conversion    = data.conversion    or "" end
+                if groupsuffix   == "" then groupsuffix   = data.groupsuffix   or "" end
                 if stopper       == "" then stopper       = data.stopper       or "" end
                 if starter       == "" then starter       = data.starter       or "" end
                 if connector     == "" then connector     = data.connector     or "" end
@@ -616,6 +618,7 @@ function sections.typesetnumber(entry,kind,...) -- kind='section','number','pref
         if separatorset  == "" then separatorset  = "default"  end
         if conversionset == "" then conversionset = "default"  end -- not used
         if conversion    == "" then conversion    = nil        end
+        if groupsuffix   == "" then groupsuffix   = nil        end
         if stopper       == "" then stopper       = nil        end
         if starter       == "" then starter       = nil        end
         if connector     == "" then connector     = nil        end
@@ -641,12 +644,13 @@ function sections.typesetnumber(entry,kind,...) -- kind='section','number','pref
             if f and l then
                 -- 0:100, chapter:subsubsection
                 firstprefix = tonumber(f) or sections.getlevel(f) or 0
-                lastprefix = tonumber(l) or sections.getlevel(l) or 100
+                lastprefix  = tonumber(l) or sections.getlevel(l) or 100
             else
                 -- 3, section
                 local fl = tonumber(segments) or sections.getlevel(segments) -- generalize
                 if fl then
-                    firstprefix, lastprefix = fl, fl
+                    firstprefix = fl
+                    lastprefix  = fl
                 end
             end
         end
@@ -724,17 +728,28 @@ function sections.typesetnumber(entry,kind,...) -- kind='section','number','pref
                 end
             end
             --
-            if done and connector and kind == 'prefix' then
-                if result then
-                    -- can't happen as we're in 'direct'
-                else
-                    applyprocessor(connector)
-                end
-            elseif done and stopper then
-                if result then
-                    result[#result+1] = strippedprocessor(stopper)
+            if done then
+                if connector and kind == 'prefix' then
+                    if result then
+                        -- can't happen as we're in 'direct'
+                    else
+                        applyprocessor(connector)
+                    end
                 else
-                    applyprocessor(stopper)
+if groupsuffix and kind ~= "prefix" then
+    if result then
+        result[#result+1] = strippedprocessor(groupsuffix)
+    else
+        applyprocessor(groupsuffix)
+    end
+end
+                    if stopper then
+                        if result then
+                            result[#result+1] = strippedprocessor(stopper)
+                        else
+                            applyprocessor(stopper)
+                        end
+                    end
                 end
             end
             return result -- a table !
diff --git a/tex/context/base/strc-flt.mkvi b/tex/context/base/strc-flt.mkvi
index 4fe1a96ff..b552573d8 100644
--- a/tex/context/base/strc-flt.mkvi
+++ b/tex/context/base/strc-flt.mkvi
@@ -26,7 +26,11 @@
 %
 % todo: move variables from page-flt to strc-flt
 %
+% todo: p_name etc
+%
 % todo: less globals!
+%
+% todo: do all options in lua
 
 %D This module is being converted into a mkvi one.
 %D
@@ -477,6 +481,12 @@
    \ifx\floatlocation\empty
       \edef\floatlocation{\floatparameter\c!default}% beware of a clash between alignment locations
    \fi
+   % moved here, will do more
+   \let\floatlabel \empty
+   \let\floatcolumn\empty
+   \let\floatrow   \empty
+   \setfloatmethodvariables\floatlocation
+   %
    \setupcurrentfloatcaption[\c!reference={#reference},\c!title={#caption},\c!marking=,\c!list=,\c!bookmark=]%
    \doifinsetelse\v!split\floatlocation\strc_floats_place_next_box_split\strc_floats_place_next_box_normal}
 
@@ -778,6 +788,9 @@
 
 \newconditional\usesamefloatnumber
 
+\def\strc_floats_group_index
+  {\numexpr\ctxcommand{listgroupindex("\currentfloat","\currentfloatgroup")}\relax}
+
 \def\strc_floats_place_packaged_boxes
   {\expandafter\strc_floats_place_packaged_boxes_indeed\expandafter{\m_strc_floats_saved_userdata}}
 
@@ -789,10 +802,19 @@
      \globallet\currentfloatsynchronize\relax
    \else
      \edef\currentfloatcounter{\namedcounterparameter\currentfloat\s!name}%
-      % *1* as an alternative we could set counter parameters here if needed
+     \edef\currentfloatgroup  {\floatcaptionparameter\c!group}%
      \ifnofloatnumber \else \ifnofloatcaption \else
-       \strc_counters_increment\currentfloatcounter
+       \ifx\currentfloatgroup\empty
+         % independent
+         \strc_counters_increment\currentfloatcounter
+       \else\ifcase\strc_floats_group_index
+         % first in group
+         \strc_counters_increment\currentfloatcounter
+       \else
+         % next in group
+       \fi \fi
      \fi \fi
+     % *1* as an alternative we could set counter parameters here if needed
      \strc_counters_register_component
        \s!float
        \setupcurrentfloatcaption
@@ -1969,10 +1991,10 @@
 
 \def\strc_floats_get_box
   {\ifvisible
-     \let\floatlabel \empty
-     \let\floatcolumn\empty
-     \let\floatrow   \empty
-     \setfloatmethodvariables\floatlocation
+%      \let\floatlabel \empty
+%      \let\floatcolumn\empty
+%      \let\floatrow   \empty
+%      \setfloatmethodvariables\floatlocation
      % todo: nog algemeen otr
      \ifdefined\OTRSETsetpreferedcolumnslot
        \OTRSETsetpreferedcolumnslot\floatcolumn\floatrow
diff --git a/tex/context/base/strc-lst.lua b/tex/context/base/strc-lst.lua
index 95f5e675e..7d4d8e7e7 100644
--- a/tex/context/base/strc-lst.lua
+++ b/tex/context/base/strc-lst.lua
@@ -115,12 +115,29 @@ end
 
 job.register('structures.lists.collected', tobesaved, initializer)
 
+local groupindices = table.setmetatableindex("table")
+
+function lists.groupindex(name,group)
+    local groupindex = groupindices[name]
+    return groupindex and groupindex[group] or 0
+end
+
 function lists.addto(t)
+    local m = t.metadata
     local u = t.userdata
     if u and type(u) == "string" then
         t.userdata = helpers.touserdata(u) -- nicer at the tex end
     end
-    local m = t.metadata
+    local numberdata = t.numberdata
+    local group = numberdata and numberdata.group or ""
+    if group == "" then
+        numberdata.group = nil
+    else
+        local groupindex = groupindices[m.name][group]
+        if groupindex then
+            numberdata.numbers = cached[groupindex].numberdata.numbers
+        end
+    end
     local r = t.references
     local i = r and r.internal or 0 -- brrr
     local p = pushed[i]
@@ -134,6 +151,9 @@ function lists.addto(t)
     if setcomponent then
         setcomponent(t) -- might move to the tex end
     end
+    if group ~= "" then
+        groupindices[m.name][group] = p
+    end
     return p
 end
 
@@ -196,11 +216,12 @@ end
 local nesting = { }
 
 function lists.pushnesting(i)
-    local r = lists.result[i]
-    local name = r.metadata.name
-    local numberdata = r and r.numberdata
-    local n = (numberdata and numberdata.numbers[sections.getlevel(name)]) or 0
-    insert(nesting, { number = n, name = name, result = lists.result, parent = r })
+    local parent = lists.result[i]
+    local name = parent.metadata.name
+    local numberdata = parent and parent.numberdata
+    local numbers = numberdata and numberdata.numbers
+    local number = numbers and numbers[sections.getlevel(name)] or 0
+    insert(nesting, { number = number, name = name, result = lists.result, parent = parent })
 end
 
 function lists.popnesting()
@@ -656,11 +677,12 @@ commands.listprefixednumber = lists.prefixednumber
 commands.listprefixedpage   = lists.prefixedpage
 
 
-function commands.addtolist   (...) context(lists.addto   (...)) end -- we could use variables instead of print
-function commands.listsize    (...) context(lists.size    (...)) end
-function commands.listlocation(...) context(lists.location(...)) end
-function commands.listlabel   (...) context(lists.label   (...)) end
-function commands.listrealpage(...) context(lists.realpage(...)) end
+function commands.addtolist     (...) context(lists.addto     (...)) end -- we could use variables instead of print
+function commands.listsize      (...) context(lists.size      (...)) end
+function commands.listlocation  (...) context(lists.location  (...)) end
+function commands.listlabel     (...) context(lists.label     (...)) end
+function commands.listrealpage  (...) context(lists.realpage  (...)) end
+function commands.listgroupindex(...) context(lists.groupindex(...)) end
 
 function commands.listuserdata(...)
     local str, metadata = lists.userdata(...)
diff --git a/tex/context/base/strc-num.mkiv b/tex/context/base/strc-num.mkiv
index c4d54e512..679dd0532 100644
--- a/tex/context/base/strc-num.mkiv
+++ b/tex/context/base/strc-num.mkiv
@@ -494,7 +494,7 @@
      \edef\p_prefixsegments{\autostructureprefixsegments#3}%
    \fi
    %
-   \edef\currentname{#3\c!name}%
+   \edef\currentname{#3\s!name}%
    \ifx\currentname\empty
      \edef\currentname{#1}%
    \fi
@@ -504,7 +504,7 @@
    \fi
    %
    \ifx\p_hascaption\v!yes
-     \xdef\currentstructurecomponentname           {#3\c!name}%
+     \xdef\currentstructurecomponentname           {#3\s!name}%
      \xdef\currentstructurecomponentlevel          {#3\c!level}%
      \edef\currentstructurecomponentexpansion      {#3\c!expansion}%
      \xdef\currentstructurecomponentxmlsetup       {#3\c!xmlsetup}%
@@ -593,8 +593,10 @@
             segments      = "\p_prefixsegments",
             connector     = \!!bs#3\c!prefixconnector\!!es,
         },
-        numberdata = {
+        numberdata = { % more helpers here, like compact elsewhere
             numbers       = structures.counters.compact("\currentcounter",nil,true),
+            group         = "#3\c!group",
+            groupsuffix   = \!!bs#3\c!groupsuffix\!!es,
             counter       = "\currentcounter",
             separatorset  = "#3\c!numberseparatorset",
             conversion    = \!!bs#3\c!numberconversion\!!es,
-- 
cgit v1.2.3