for older Vims, the wordcount extension falls back to `g<c-g>` and
parses the messaage that is generated.
When doing so, it expects the English locale, which might not be true.
Therefore, try to regex parse the result without using the english words
(assuming the output is still in the same order as in English).
Compatibility:
- Don't use a script-local function to update the format strings
- Protect against `:normal!' moving the cursor on on the wordcount check
Bugfix:
- Let to_string() try to return something for all values
- Now returns correctly when passed both 0 and '0'
Upkeep:
- Simplify check again no valid key from winwidth()
- Old wordcount check: use matchstr() - more expressive and fewer steps
- Improve documentation style/clarity/detail
v:t_list is an internal variable describing the type of a list.
Unfortunately, this is not available in older vims. So let's fall back
to using `type([])`
see #1795
This prevents a warning message, when the function is tried to add
several times. Also while at it, add a '!' so that no error is thrown if
the file is sourced a second times.
commit bcd37fc115 changed the detection of modes slightly in that it
allowed not only single letters but also several letters.
While in theory, it might be okay to have extra modes displayed like
Insert Completion or Normal Insert, or Operator Pending, let's for now
just revert it to the default. We can always enhance it later if
requested.
Checking for wordcount changes now uses a b:changedtick comparison in
the statusline funcref. The autocommand strategy that used to do this is
removed, simplifying the code.
- Formatter is now only called when the wordcount changes
- ...#apply() now only compares against the filetype list when necessary
- Old format() function is no longer called for (unsupported) counting
of visual words
- Misc code quality improvements
Various improvements:
- Seperate out visual mode detection.
- Use TextChanged rather than CursorMoved where supported.
- Let users specify the filetypes for which wordcounting is enabled
with a list rather than a pattern.
- Move the filetype check to when airline is refreshed, as opposed to
on every update; autocommands are not created if wordcounting is
disabled
Currently the formatter, and not the wordcount plugin, is responsible
for providing the wordcount as well as formatting it. The default
formatter allows visual mode word counting, although this is not
documented.
The new interface - a transform() function, allows the main wordcount
plugin to internalise this logic. Providing the wordcount simplifies
formatter implementations:
- All formatters can display the visual wordcount.
- Formatters do not have to worry about compatibility with different
vim versions.
The old format() function can now be deprecated, although the wordcount
plugin retains compatibility with formatters using it. The default
formatter will also be used as a fallback if no suitable function is
found.
The default formatter is rewritten to use the new interface.