On 20/06/09 23:52 +0200, Geir Isene wrote:
> With reference to my HP-41 filetype plugin (script id=1361).
> 
> Renumbering is awfully sloooow. Unusable in fact when renumbering more
> than 50 lines and increasing rapidly beyond that :-(
> 
> I have the following type of list that I want to renumber quite often:
> 
> 001 *LBL "DATA"
> 002  SF 27
> 003  CF 00
> 004  CF 01
> 005  SF 02
> 006  SF 25
> 007  0
> 008  SEEKPTA
> 009  FC?C 25
> 
> (it's the start of an HP-41 FOCAL program)
> 
> So the format of the numbering to be renumbered every once in a while is:
> 
> "^\d\d\d "
> 
> The code for renumbering:
> 
> if !exists("*s:Renumber")
>     function Renumber()
>       let s:linenumber = line(".")
>         let s:colnumber = col(".")
>       call cursor(1,1)
>       normal 0cw001
>       while search("^\d\d\d ", "W") > 0
>           execute "normal 3cl\<c-y>\<c-y>\<c-y>\<esc>\<c-a>"
>       endwhile
>       call cursor(s:linenumber,s:colnumber)
>     endfunction
> endif
> 

I have no idea of HP-41 FOCAL format, I think here is a big deal:
        while search("^\d\d\d ", "W") > 0
            execute "normal 3cl\<c-y>\<c-y>\<c-y>\<esc>\<c-a>"
        endwhile
First, I don't think "^\d\d\d" will work for normal cases, do you mean
'^\d\d\d' (single quote)?
Then, for the performance, a simple substitute would be more effective
than the 'while' loop, e.g.: 

function! Renumber()
    let s:linenumber = line(".")
    let s:colnumber = col(".")
    call cursor(1,1)

    " mess up a register
    let @r = 1
    exe "normal 0cw".printf("%03d", @r)
    2,$s#^\d\d\d #\=printf("%03d ", @r + setreg('r', @r+1))#

    call cursor(s:linenumber,s:colnumber)
endfunction


-- 
Dasn


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to