├── README.md ├── autoload └── usa_election_2024.vim └── misc └── screenshot.png /README.md: -------------------------------------------------------------------------------- 1 | # vim-usa-election-2024 2 | 3 | Indicate USA election 2024 in Vim 4 | 5 | ![vim-usa-election-2024](https://github.com/mattn/vim-usa-election-2024/blob/main/misc/screenshot.png?raw=true) 6 | 7 | ## Usage 8 | 9 | Set `usa_election_2024#status()` into you `statusline` like below. 10 | 11 | ```vim 12 | set statusline=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\[%{usa_election_2024#status()}\]\ %P 13 | ``` 14 | 15 | For lightline 16 | 17 | ```vim 18 | let g:lightline = { 19 | \ ... 20 | \ 'component_function': { 21 | \ 'usa_election_2024': 'usa_election_2024#status', 22 | \ }, 23 | \ } 24 | ``` 25 | 26 | ## License 27 | 28 | MIT 29 | 30 | ## Author 31 | 32 | Yasuhiro Matsumoto (a.k.a. mattn) 33 | -------------------------------------------------------------------------------- /autoload/usa_election_2024.vim: -------------------------------------------------------------------------------- 1 | let s:status = '' 2 | let s:res = [] 3 | 4 | function! usa_election_2024#status() 5 | return s:status 6 | endfunction 7 | 8 | function! s:job_callback(ch, data) abort 9 | call add(s:res, a:data) 10 | if ch_status(a:ch) !=# 'closed' 11 | return 12 | endif 13 | try 14 | let l:res = json_decode(join(s:res, '')).candidates 15 | let l:harris = filter(copy(l:res), {_, x->x['last_name'] == 'Harris'})[0].electoral_votes_total 16 | let l:trump = filter(copy(l:res), {_, x->x['last_name'] == 'Trump'})[0].electoral_votes_total 17 | let s:status = printf('Harris(%d) vs Trump(%d)', l:harris, l:trump) 18 | catch 19 | echomsg v:exception 20 | finally 21 | let s:res = [] 22 | endtry 23 | call timer_start(60000, {x->usa_election_2024#update()}) 24 | endfunction 25 | 26 | function! usa_election_2024#update() 27 | call job_start(['curl', '-s', 'https://data.ddhq.io/electoral_college/2024'], {'callback': function('s:job_callback')}) 28 | endfunction 29 | 30 | call usa_election_2024#update() 31 | -------------------------------------------------------------------------------- /misc/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattn/vim-usa-election-2024/64d0286f40fa38adf745dfa9ec3f9f2db422a6fa/misc/screenshot.png --------------------------------------------------------------------------------