Wiki: DebugInfo: SuperRetab


Detailed view of a page, which is probably more useful for debugging than anything else.

Querying backend directly for 'SuperRetab'

get_pagedata('SuperRetab')
 _cached_html 
transformedtext Object
(
    [_type] => pagetype_wikitext Object
        (
        )

    [_basepage] => SuperRetab
    [_content] => Array
        (
            [0] => <div class="wikitext"><hr />
<h3>The Challenge</h3>
<p class="tightenable top">The challenge is to write a function that redoes the tabbing only along the left side of the text.  It is a ranged function that takes a single parameter which is the # of spaces used to represent a single indent in the file.</p>
<p class="tightenable bottom">The differences between this and the standard retab are</p>
<ol><li class="tightenable top bottom">it takes a parameter for the # of spaces to equal a tab (doesn't use tabstop)</li>
<li class="tightenable top">it only replaces groups of spaces at the start of a line.</li>
</ol>
<p class="tightenable bottom">So it could take a file that looks like</p>
<pre class="tightenable top">
  for {
    that;
  }</pre>
<p class="tightenable">and turn it into  (|------- represents a tab char) via :call 
            [1] => cached_wikilink Object
                (
                    [_page] => SuperRetab
                )

            [2] => (2)</p>
<pre class="tightenable">
|-------for {
|-------|-------that;
|-------}</pre>
<p class="tightenable bottom">and could create the same output from</p>
<pre class="tightenable top bottom">
     for {
          that;
     }</pre>
<p class="tightenable top bottom">via :call 
            [3] => cached_wikilink Object
                (
                    [_page] => SuperRetab
                )

            [4] => (5)</p>
<hr />
<hr />
<p class="tightenable bottom">
            [5] => cached_wikilink Object
                (
                    [_page] => p0g
                )

            [6] => 's attempt: (I think we have a winner here! --
            [7] => cached_userlink Object
                (
                    [_page] => MetaCosm
                )

            [8] => )</p>
<pre class="tightenable top">
function! 
            [9] => cached_wikilink Object
                (
                    [_page] => SuperRetab
                )

            [10] => (width) range
  exe a:firstline . ',' . a:lastline . 's/\v%(^ *)@&lt;= {'. a:width .'}/\t/g'
endfunction
OR as a command:
:command! -nargs=1 -range 
            [11] => cached_wikilink Object
                (
                    [_page] => SuperRetab
                )

            [12] =>  &lt;line1&gt;,&lt;line2&gt;s/\v%(^ *)@&lt;= {&lt;args&gt;}/\t/g</pre>
<p class="tightenable">Cleaned up function by 
            [13] => cached_wikilink Object
                (
                    [_page] => FallingCow
                )

            [14] =>  (*Wow, much better --
            [15] => cached_userlink Object
                (
                    [_page] => MetaCosm
                )

            [16] => )</p>
<p class="tightenable bottom"><i>version 1</i></p>
<pre class="tightenable top">
function! 
            [17] => cached_wikilink Object
                (
                    [_page] => SuperRetab
                )

            [18] => () range
        let x = 0
        while x &lt; 10
                exe a:firstline . ',' . a:lastline . 's/^\([ ]*\)[ ]\{' . &amp;sw . '}/\1\t\2/e'
                let x = x + 1
        endwhile
endfunction</pre>
<p class="tightenable bottom"><i>version 2</i></p>
<pre class="tightenable top">
function! 
            [19] => cached_wikilink Object
                (
                    [_page] => SuperRetab
                )

            [20] => (width) range
        let x = 0
        while x &lt; 10
                exe a:firstline . ',' . a:lastline . 's/^\([ ]*\)[ ]\{' . a:width . '}/\1\t\2/e'
                let x = x + 1
        endwhile
endfunction</pre>
<p class="tightenable bottom"><i>version 3</i></p>
<pre class="tightenable top">
function! 
            [21] => cached_wikilink Object
                (
                    [_page] => SuperRetab
                )

            [22] => (width) range
        let @&quot; = ''
        redir @&quot;
        while @&quot; !~ 'E486:'
                silent! exe a:firstline . ',' . a:lastline . 'g/^\([ ]*\)[ ]\{' . a:width . '}/s//\1\t\2/'
        endwhile
endfunction</pre>
<p class="tightenable bottom">
            [23] => cached_wikilink Object
                (
                    [_page] => Tofer
                )

            [24] => 's Attempt</p>
<pre class="tightenable top">
fun! F(len)
    let re = '^\(\( \{a:len}\)*\) \{a:len}'
    let n = 1
    while n &lt;= line(&quot;$&quot;)
       let l = getline(n)
       while l = re
          let l = substitute(l,re,&quot;\\1\\t&quot;,&quot;&quot;)
       endwhile
       call setline(n,l)
       let n = n + 1
    endwhile
endfunc</pre>
<p class="tightenable bottom">
            [25] => cached_userlink Object
                (
                    [_page] => MetaCosm
                )

            [26] => 's Attempt (mine doesn't take a range and is put to shame by those below it, only reason it is left here is for history.)</p>
<pre class="tightenable top bottom">
function! 
            [27] => cached_wikilink Object
                (
                    [_page] => SuperRetab
                )

            [28] => (width)
        let n = 1
        while n &lt;= line(&quot;$&quot;)
                &quot;echo &quot;Outer Loop:&quot;.n
                let i = 30 &quot; hardcoded max of 30 deep indent
                while i &gt;= 1
                        let numberOfSpaces = a:width * i
                        &quot;echo &quot;    Inner Loop&quot;.i.&quot; :: &quot;.numberOfSpaces

                        let j = 1
                        let spaces = &quot;^ &quot;
                        while j &lt; numberOfSpaces
                                let spaces = spaces . &quot; &quot;
                                let j = j + 1
                        endwhile

                        let k = 1
                        let tabs = &quot;&quot;
                        while k &lt; numberOfSpaces
                                let tabs = tabs . &quot;\t&quot;
                                let k = k + a:width
                        endwhile

                        &quot;echo &quot;s/&quot; . spaces . &quot;/&quot; . tabs . &quot;/&quot;

                        let l = substitute(getline(n), spaces, tabs, &quot;&quot;)
                        call setline(n, l)
                        let i = i - 1
                endwhile
                let n = n + 1
        endwhile
endfunction</pre>
</div>

        )

    [_description] => The challenge is to write a function that redoes the tabbing only along the left side of the text.  It is a ranged function that takes a single parameter which is the # of spaces used to represent a single indent in the file.
)
 hits  4430
get_versiondata('SuperRetab',33)
 %content  ---- !!The Challenge The challenge is to ...
 author  216.47.158.208
 author_id  216.47.158.208
 is_minor_edit  1
 markup  2
 mtime  1195238647
 pagetype  wikitext
 summary  reverted spam away
get_versiondata('SuperRetab',32)
 %content  ---- !!The Challenge The challenge is to ...
 _supplanted  1195238647
 author  WikiWord
 author_id  WikiWord
 is_minor_edit   
 markup  2
 mtime  1186719048
 pagetype  wikitext
get_versiondata('SuperRetab',31)
 %content  ---- !!The Challenge The challenge is to ...
 _supplanted  1186719048
 author  WikiWord
 author_id  WikiWord
 is_minor_edit   
 markup  2
 mtime  1186711921
 pagetype  wikitext
get_versiondata('SuperRetab',30)
 %content  ---- !!The Challenge The challenge is to ...
 _supplanted  1186711921
 author  194.94.79.49
 author_id  194.94.79.49
 is_minor_edit  1
 markup  2
 mtime  1184343480
 pagetype  wikitext
get_versiondata('SuperRetab',26)
 %content  ---- !!The Challenge The challenge is to ...
 _supplanted  1183061277
 author  65.242.74.195
 author_id  65.242.74.195
 is_minor_edit  1
 markup  2
 mtime  1084217648
 pagetype  wikitext

Copyright © 2007 RobertMelton.com