Patchwork minirst: establish leveling for nested definitions

login
register
mail settings
Submitter timeless@mozdev.org
Date Sept. 10, 2015, 5:48 p.m.
Message ID <c8ae009a6ebd0b0fdd2a.1441907321@waste.org>
Download mbox | patch
Permalink /patch/10471/
State Accepted
Headers show

Comments

timeless@mozdev.org - Sept. 10, 2015, 5:48 p.m.
# HG changeset patch
# User timeless@mozdev.org
# Date 1441896500 14400
#      Thu Sep 10 10:48:20 2015 -0400
# Node ID c8ae009a6ebd0b0fdd2a1dc35f394a26a59e613f
# Parent  ea489d94e1dc1fc3dc1dcbef1c86c18c49605ed1
minirst: establish leveling for nested definitions
Augie Fackler - Sept. 14, 2015, 2:29 a.m.
On Thu, Sep 10, 2015 at 12:48:41PM -0500, timeless@mozdev.org wrote:
> # HG changeset patch
> # User timeless@mozdev.org
> # Date 1441896500 14400
> #      Thu Sep 10 10:48:20 2015 -0400
> # Node ID c8ae009a6ebd0b0fdd2a1dc35f394a26a59e613f
> # Parent  ea489d94e1dc1fc3dc1dcbef1c86c18c49605ed1
> minirst: establish leveling for nested definitions

queued, thanks

>
> diff --git a/mercurial/minirst.py b/mercurial/minirst.py
> --- a/mercurial/minirst.py
> +++ b/mercurial/minirst.py
> @@ -722,6 +722,20 @@
>                  nest += i
>              level = nest.index(i) + 1
>              nest = nest[:level]
> +            for i in range(1, len(secs) + 1):
> +                sec = secs[-i]
> +                if sec[1] < level:
> +                    break
> +                siblings = [a for a in sec[2] if a['type'] == 'definition']
> +                if siblings:
> +                    siblingindent = siblings[-1]['indent']
> +                    indent = b['indent']
> +                    if siblingindent < indent:
> +                        level += 1
> +                        break
> +                    elif siblingindent == indent:
> +                        level = sec[1]
> +                        break
>              secs.append((getname(b), level, [b]))
>          else:
>              if not secs:
> diff --git a/tests/test-help.t b/tests/test-help.t
> --- a/tests/test-help.t
> +++ b/tests/test-help.t
> @@ -936,6 +936,12 @@
>    $ hg help config.charsets |grep "Email example:" > /dev/null
>    [1]
>
> +Show nested definitions
> +("profiling.type"[break]"ls"[break]"stat"[break])
> +
> +  $ hg help config.type|grep '^$'|wc -l
> +  \s*3 (re)
> +
>  Last item in help config.*:
>
>    $ hg help config.`hg help config|grep '^    "'| \
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/minirst.py b/mercurial/minirst.py
--- a/mercurial/minirst.py
+++ b/mercurial/minirst.py
@@ -722,6 +722,20 @@ 
                 nest += i
             level = nest.index(i) + 1
             nest = nest[:level]
+            for i in range(1, len(secs) + 1):
+                sec = secs[-i]
+                if sec[1] < level:
+                    break
+                siblings = [a for a in sec[2] if a['type'] == 'definition']
+                if siblings:
+                    siblingindent = siblings[-1]['indent']
+                    indent = b['indent']
+                    if siblingindent < indent:
+                        level += 1
+                        break
+                    elif siblingindent == indent:
+                        level = sec[1]
+                        break
             secs.append((getname(b), level, [b]))
         else:
             if not secs:
diff --git a/tests/test-help.t b/tests/test-help.t
--- a/tests/test-help.t
+++ b/tests/test-help.t
@@ -936,6 +936,12 @@ 
   $ hg help config.charsets |grep "Email example:" > /dev/null
   [1]
 
+Show nested definitions
+("profiling.type"[break]"ls"[break]"stat"[break])
+
+  $ hg help config.type|grep '^$'|wc -l
+  \s*3 (re)
+
 Last item in help config.*:
 
   $ hg help config.`hg help config|grep '^    "'| \