Monday, May 31, 2010

Re: delete lines from while loop

Hi Andrei!

On Mo, 31 Mai 2010, Andrei Popescu wrote:

> 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

I am not sure, I understand your problem. Anyway, your function has one
problem. You are deleting lines (including the end-of-line), so you
after the exe "normal! dd" command your file has actually one line less
then before. And the next time you run getline(linenum) you get actually
the wrong line. (which would now be equivalent to linenum+1 and each
time you do normal! dd you add another one)


regards,
Christian
--
Was ist der Unterschied zwischen Männern und Schweinen?
Schweine verwandeln sich nicht in Männer, wenn sie betrunken sind.

--
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