Monday, May 31, 2010

delete lines from while loop

Hello,

I'm trying to add new features to the po.vim plugin[1], first one being
the removal of the previous msgid in fuzzy strings:

#, fuzzy
#| msgid ""
#| "The following disk access storage devices (DASD) are available. Please "
#| "select each device you want to use one at a time."
msgid ""
"The following direct access storage devices (DASD) are available. Please "
"select each device you want to use one at a time."
msgstr ""
"Următoarele Dispozitive de stocare cu acces la disc (DASD) sunt disponibile. "
"Vă rugăm să alegeți pe rând fiecare dispozitiv pe care doriți să-l folosiți."

So far I have:

" Remove previous msgid and fuzzy description from the translation.
if !hasmapto('<Plug>RemoveFuzzy')
if gui
imap <buffer> <unique> <S-F8> <Plug>RemoveFuzzy
nmap <buffer> <unique> <S-F8> <Plug>RemoveFuzzy
else
imap <buffer> <unique> <LocalLeader>r <Plug>RemoveFuzzy
nmap <buffer> <unique> <LocalLeader>r <Plug>RemoveFuzzy
endif
endif
inoremap <buffer> <unique> <Plug>RemoveFuzzy <ESC>{vap:call <SID>RemoveFuzzy()<CR>gv<ESC>}i
nnoremap <buffer> <unique> <Plug>RemoveFuzzy {vap:call <SID>RemoveFuzzy()<CR>gv<ESC>}

fu! <SID>RemoveFuzzy() range
for linenum in range(a:firstline, a:lastline)
let line = getline(linenum)
if line =~ '^#,.*fuzzy'
exe "normal! dd"
"call setline(linenum, substitute(line, '^.*$','',''))
elseif line =~ '^#|\smsgid\s".*"$'
exe "normal! dd"
"call setline(linenum, substitute(line, '^.*$','',''))
elseif line =~ '^#|\s".*"$'
exe "normal! dd"
"call setline(linenum, substitute(line, '^.*$','',''))
endif
endfor
endf

but it doesn't work and I don't understand why. As it is now it only
deletes the empty line separating this "paragraph" from the previous
one. I'm guessing the problem is with the "exe" command, because
replacing it with the commented out "call" the lines are emptied as
expected.

I also tried other variations, like

exe ":delete"
exe "1d"

There must be a detail I'm missing, but I read the docs and searched the
web and couldn't find the answer. Any hints?

[1] http://www.vim.org/scripts/script.php?script_id=695

Regards,
Andrei
--
Offtopic discussions among Debian users and developers:
http://lists.alioth.debian.org/mailman/listinfo/d-community-offtopic

No comments: