Skip to content

Commit 4289d66

Browse files
committed
Import check.vim from Vim 8.0.0794
1 parent 7cb3dcc commit 4289d66

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/po/check.vim

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ let s:save_wrapscan = &wrapscan
3535
set nowrapscan
3636

3737
" Start at the first "msgid" line.
38+
let wsv = winsaveview()
3839
1
3940
/^msgid\>
4041

@@ -110,7 +111,41 @@ if search('msgid "\("\n"\)\?\([EW][0-9]\+:\).*\nmsgstr "\("\n"\)\?[^"]\@=\2\@!')
110111
endif
111112
endif
112113

114+
func! CountNl(first, last)
115+
let nl = 0
116+
for lnum in range(a:first, a:last)
117+
let nl += count(getline(lnum), "\n")
118+
endfor
119+
return nl
120+
endfunc
121+
122+
" Check that the \n at the end of the msgid line is also present in the msgstr
123+
" line. Skip over the header.
124+
/^"MIME-Version:
125+
while 1
126+
let lnum = search('^msgid\>')
127+
if lnum <= 0
128+
break
129+
endif
130+
let strlnum = search('^msgstr\>')
131+
let end = search('^$')
132+
if end <= 0
133+
let end = line('$') + 1
134+
endif
135+
let origcount = CountNl(lnum, strlnum - 1)
136+
let transcount = CountNl(strlnum, end - 1)
137+
" Allow for a few more or less line breaks when there are 2 or more
138+
if origcount != transcount && (origcount <= 2 || transcount <= 2)
139+
echomsg 'Mismatching "\n" in line ' . line('.')
140+
if error == 0
141+
let error = lnum
142+
endif
143+
endif
144+
endwhile
145+
113146
if error == 0
147+
" If all was OK restore the view.
148+
call winrestview(wsv)
114149
echomsg "OK"
115150
else
116151
exe error

0 commit comments

Comments
 (0)