Changed DiffText and Constant highlight groups
[MacVim/jjgod.git] / src / po / check.vim
blob50ed9a40f12d3014f23dd21b5ceb57e8d36a62d7
1 " Vim script for checking .po files.
3 " Go through the file and verify that all %...s items in "msgid" are identical
4 " to the ones in "msgstr".
6 if 1    " Only execute this if the eval feature is available.
8 " Function to get a split line at the cursor.
9 " Used for both msgid and msgstr lines.
10 " Removes all text except % items and returns the result.
11 func! GetMline()
12   let idline = substitute(getline('.'), '"\(.*\)"$', '\1', '')
13   while line('.') < line('$')
14     +
15     let line = getline('.')
16     if line[0] != '"'
17       break
18     endif
19     let idline .= substitute(line, '"\(.*\)"$', '\1', '')
20   endwhile
22   " remove '%', not used for formatting.
23   let idline = substitute(idline, "'%'", '', 'g')
25   " remove everything but % items.
26   return substitute(idline, '[^%]*\(%[-+ #''.0-9*]*l\=[dsuxXpoc%]\)\=', '\1', 'g')
27 endfunc
29 " Start at the first "msgid" line.
31 /^msgid
32 let startline = line('.')
33 let error = 0
35 while 1
36   if getline(line('.') - 1) !~ "no-c-format"
37     let fromline = GetMline()
38     if getline('.') !~ '^msgstr'
39       echo 'Missing "msgstr" in line ' . line('.')
40       let error = 1
41     endif
42     let toline = GetMline()
43     if fromline != toline
44       echo 'Mismatching % in line ' . (line('.') - 1)
45       echo 'msgid: ' . fromline
46       echo 'msgstr: ' . toline
47       let error = 1
48     endif
49   endif
51   " Find next msgid.
52   " Wrap around at the end of the file, quit when back at the first one.
53   /^msgid
54   if line('.') == startline
55     break
56   endif
57 endwhile
59 if error == 0
60   echo "OK"
61 endif
63 endif