Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wordcount] Expose the default filetype list for modification #1887

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions autoload/airline/extensions/wordcount.vim
Expand Up @@ -82,13 +82,15 @@ endfunction

" airline functions {{{1
" default filetypes:
let s:filetypes = ['help', 'markdown', 'rst', 'org', 'text', 'asciidoc', 'tex', 'mail']
let g:airline#extensions#wordcount#filetypes =
\ ['help', 'markdown', 'rst', 'org', 'text', 'asciidoc', 'tex', 'mail']
let s:lastknownfiletypes = g:airline#extensions#wordcount#filetypes
function! airline#extensions#wordcount#apply(...)
let filetypes = get(g:, 'airline#extensions#wordcount#filetypes', s:filetypes)
let filetypes = g:airline#extensions#wordcount#filetypes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not something like let filetypes = uniq(sort(s:filetypes + get(g:, 'airline#extensions#wordcount#filetype', []))

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the global variable is now guaranteed to exist (well, not guaranteed, but if it doesn't we have a bigger problem), and s:filetypes is no longer a thing. This format allows both adding to and removing from the default set of filetypes without having to replicate it (and thus desync yourself from whatever vim-airline might do in the future).


" Check if filetype needs testing
if did_filetype() || filetypes isnot s:filetypes
let s:filetypes = filetypes
if did_filetype() || filetypes isnot s:lastknownfiletypes
let s:lastknownfiletypes = filetypes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is lastknownfiletypes?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to admit I'm not totally sure. I made this change ages ago in my private copy and completely forgot to PR it until I tried moving to a different computer and rediscovered it.


" Select test based on type of "filetypes": new=list, old=string
if type(filetypes) == get(v:, 't_list', type([]))
Expand Down