patch 7.4.1042
Problem:    g-CTRL-G shows the word count, but there is no way to get the word
            count in a script.
Solution:   Add the wordcount() function. (Christian Brabandt)
diff --git a/src/testdir/Make_all.mak b/src/testdir/Make_all.mak
index c5796bd..a67619f 100644
--- a/src/testdir/Make_all.mak
+++ b/src/testdir/Make_all.mak
@@ -120,6 +120,7 @@
 	test_tagcase.out \
 	test_textobjects.out \
 	test_utf8.out \
+	test_wordcount.out \
 	test_writefile.out
 
 
diff --git a/src/testdir/test_wordcount.in b/src/testdir/test_wordcount.in
new file mode 100644
index 0000000..b2db505
--- /dev/null
+++ b/src/testdir/test_wordcount.in
@@ -0,0 +1,125 @@
+Test for wordcount() function
+
+STARTTEST
+:so small.vim
+:so mbyte.vim
+:set enc=utf8
+:new
+:fu DoRecordWin(...)
+:	wincmd k
+:       if exists("a:1")
+:           call cursor(a:1)
+:       endif
+:       let result=[]
+:       call add(result, g:test)
+:       call add(result, getline(1, '$'))
+:       call add(result, wordcount())
+:	wincmd j
+:       return result
+:endfu
+:fu PutInWindow(args)
+:       wincmd k
+:       %d _
+:       call append(1, a:args)
+:	wincmd j
+:endfu
+:fu Log()
+:   $put ='----'
+:   $put =remove(g:log,0)
+:   $put =string(g:log)
+:endfu
+:fu! STL()
+:    if mode() =~? 'V'
+:       let g:visual_stat=wordcount()
+:    endif
+:    return string(wordcount())
+:endfu
+:let g:test="Test 1: empty window"
+:let log=DoRecordWin()
+:call Log()
+:"
+:let g:test="Test 2: some words, cursor at start"
+:call PutInWindow('one two three')
+:let log=DoRecordWin([1,1,0])
+:call Log()
+:"
+:let g:test="Test 3: some words, cursor at end"
+:call PutInWindow('one two three')
+:let log=DoRecordWin([2,99,0])
+:call Log()
+:"
+:let g:test="Test 4: some words, cursor at end, ve=all"
+:set ve=all
+:call PutInWindow('one two three')
+:let log=DoRecordWin([2,99,0])
+:call Log()
+:set ve=
+:"
+:let g:test="Test 5: several lines with words"
+:call PutInWindow(['one two three', 'one two three', 'one two three'])
+:let log=DoRecordWin([4,99,0])
+:call Log()
+:"
+:let g:test="Test 6: one line with BOM set"
+:call PutInWindow('one two three')
+:wincmd k
+:set bomb
+:w! Xtest
+:wincmd j
+:let log=DoRecordWin([2,99,0])
+:call Log()
+:wincmd k
+:set nobomb
+:w!
+:wincmd j
+:"
+:let g:test="Test 7: one line with multibyte words"
+:call PutInWindow(['Äne M¤ne Müh'])
+:let log=DoRecordWin([2,99,0])
+:call Log()
+:"
+:let g:test="Test 8: several lines with multibyte words"
+:call PutInWindow(['Äne M¤ne Müh', 'und raus bist dü!'])
+:let log=DoRecordWin([3,99,0])
+:call Log()
+:"
+:let g:test="Test 9: visual mode, complete buffer"
+:call PutInWindow(['Äne M¤ne Müh', 'und raus bist dü!'])
+:wincmd k
+:set ls=2 stl=%{STL()}
+:" start visual mode quickly and select complete buffer
+:0
+V2jy
+:set stl= ls=1
+:let log=DoRecordWin([3,99,0])
+:let log[2]=g:visual_stat
+:call Log()
+:"
+:let g:test="Test 10: visual mode (empty)"
+:call PutInWindow(['Äne M¤ne Müh', 'und raus bist dü!'])
+:wincmd k
+:set ls=2 stl=%{STL()}
+:" start visual mode quickly and select complete buffer
+:0
+v$y
+:set stl= ls=1
+:let log=DoRecordWin([3,99,0])
+:let log[2]=g:visual_stat
+:call Log()
+:"
+:let g:test="Test 11: visual mode, single line"
+:call PutInWindow(['Äne M¤ne Müh', 'und raus bist dü!'])
+:wincmd k
+:set ls=2 stl=%{STL()}
+:" start visual mode quickly and select complete buffer
+:2
+0v$y
+:set stl= ls=1
+:let log=DoRecordWin([3,99,0])
+:let log[2]=g:visual_stat
+:call Log()
+:"
+:/^RESULT test/,$w! test.out
+:qa!
+ENDTEST
+RESULT test:
diff --git a/src/testdir/test_wordcount.ok b/src/testdir/test_wordcount.ok
new file mode 100644
index 0000000..4bc8a93
--- /dev/null
+++ b/src/testdir/test_wordcount.ok
@@ -0,0 +1,34 @@
+RESULT test:
+----
+Test 1: empty window
+[[''], {'chars': 0, 'cursor_chars': 0, 'words': 0, 'cursor_words': 0, 'bytes': 0, 'cursor_bytes': 0}]
+----
+Test 2: some words, cursor at start
+[['', 'one two three'], {'chars': 15, 'cursor_chars': 1, 'words': 3, 'cursor_words': 0, 'bytes': 15, 'cursor_bytes': 1}]
+----
+Test 3: some words, cursor at end
+[['', 'one two three'], {'chars': 15, 'cursor_chars': 14, 'words': 3, 'cursor_words': 3, 'bytes': 15, 'cursor_bytes': 14}]
+----
+Test 4: some words, cursor at end, ve=all
+[['', 'one two three'], {'chars': 15, 'cursor_chars': 15, 'words': 3, 'cursor_words': 3, 'bytes': 15, 'cursor_bytes': 15}]
+----
+Test 5: several lines with words
+[['', 'one two three', 'one two three', 'one two three'], {'chars': 43, 'cursor_chars': 42, 'words': 9, 'cursor_words': 9, 'bytes': 43, 'cursor_bytes': 42}]
+----
+Test 6: one line with BOM set
+[['', 'one two three'], {'chars': 15, 'cursor_chars': 14, 'words': 3, 'cursor_words': 3, 'bytes': 18, 'cursor_bytes': 14}]
+----
+Test 7: one line with multibyte words
+[['', 'Äne M¤ne Müh'], {'chars': 14, 'cursor_chars': 13, 'words': 3, 'cursor_words': 3, 'bytes': 17, 'cursor_bytes': 16}]
+----
+Test 8: several lines with multibyte words
+[['', 'Äne M¤ne Müh', 'und raus bist dü!'], {'chars': 32, 'cursor_chars': 31, 'words': 7, 'cursor_words': 7, 'bytes': 36, 'cursor_bytes': 35}]
+----
+Test 9: visual mode, complete buffer
+[['', 'Äne M¤ne Müh', 'und raus bist dü!'], {'chars': 32, 'words': 7, 'bytes': 36, 'visual_chars': 32, 'visual_words': 7, 'visual_bytes': 36}]
+----
+Test 10: visual mode (empty)
+[['', 'Äne M¤ne Müh', 'und raus bist dü!'], {'chars': 32, 'words': 7, 'bytes': 36, 'visual_chars': 1, 'visual_words': 0, 'visual_bytes': 1}]
+----
+Test 11: visual mode, single line
+[['', 'Äne M¤ne Müh', 'und raus bist dü!'], {'chars': 32, 'words': 7, 'bytes': 36, 'visual_chars': 13, 'visual_words': 3, 'visual_bytes': 16}]