Monday, August 27, 2012

vimL errors, inconsistent result, etc

I have a function (poorly implemented, I'm learning ...):

714 command! Log2Asciidoc :call Log2Asciidoc()<CR>

715 function! Log2Asciidoc()

716 "remove some special CH, like ^M

717 :%s#\r\|\s\=\(^G\|^M\)##

718 "turn ^H into delete

719 :g/^H/while getline('.') =~ '[^^H]^H' | s/[^^H]^H//g | endwhile

720 "add asciidoc markup == and <<top>> for every command

721 :%s/^\(\S\S\+.\{0,40}\S#\s*[^:^H^G]\+\|slot
\d\d\=->\S\+.*\|->.*\|\*-\*-\*-\*-\*-\)$/\r== \1\r\r<<top>>\r\r/
722 ":set foldmethod=expr


723 "skip the 1st comand

724 :execute "normal! gg" . '/^\(\S\S\+.\{0,40}\S#\s*[^:]\+\|slot
\d\d\=->\S\+.*\|->.*\|\*-\*-\*-\*-\*-\)' . "\<cr>" ."j"
725 "indent between <<top>> and next command

726 :g/<<top>>/+1,/^== \(\S\S\+.\{0,40}\S#\s*[^:^H^G]\+\|slot
\d\d\=->\S\+\|->.\+\|\*-\*-\*-\*-\*-\)/-1 >
727 "add ---- below <<top>>

728 :%s@\(<<top>>\)@\1\r----\r@

729 "skip first command

730 :execute "normal! gg" .
'/^\(\S\S\+.\{0,40}\S#\s*[^:^H^G]\+\|slot
\d\d\=->\S\+.*\|->.*\|\*-\*-\*-\*-\*-\)' . "\<cr>" ."j"
731 "start from 2nd command, add ---- before command

732 :.,$s@^\(\S\S\+.\{0,40}\S#\s*[^:^H^G]\+\|slot
\d\d\=->\S\+.*\|->.*\|\*-\*-\*-\*-\*-\)$@\r----\r\1\r@
733 "add one more last asciidoc delimitor to end of file

734 :execute "normal! Go----" . "\<cr>\<esc>"

735

736 endfunc


I got errors:

<snipped a lot>
......
25 lines >ed 1 time
Error detected while processing function Log2Asciidoc:
line 11:
E385: search hit BOTTOM without match for: ^==
\(\S\S\+.\{0,40}\S#\s*[^:^H^G]\+\|slot
\d\d\=->\S\+\|->.\+\|\*-\*-\*-\*-\*-\)
/^\(\S\S\+.\{0,40}\S#\s*[^^G]\+\|slot
\d\d\=->\S\+.*\|->.*\|\*-\*-\*-\*-\*-\)

E488: Trailing characters


which one is line 11?
I guess it started counting from the "function()" line and skipping the
comments?
and, which line contains trailing CH?
got crazy for the whole afternoon on this ... I kind of started to hate
vimL now...
how you guys normally debug a function ?
and, I know this "simply put Ex cmds together" way is not good to write
a script, any experts points me how to improve it?
and, regardless of the script errors, sometime it does what I wanted,
but sometime doesn't, same code...is it all because of the :g magic?

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment