diff --git a/autoload/airline/extensions.vim b/autoload/airline/extensions.vim index 6cae187..6025767 100644 --- a/autoload/airline/extensions.vim +++ b/autoload/airline/extensions.vim @@ -284,6 +284,11 @@ function! airline#extensions#load() call add(loaded_ext, 'capslock') endif + if (get(g:, 'airline#extensions#xkblayout#enabled', 1) && exists('g:XkbSwitchLib')) + call airline#extensions#xkblayout#init(s:ext) + call add(loaded_ext, 'xkblayout') + endif + if (get(g:, 'airline#extensions#windowswap#enabled', 1) && get(g:, 'loaded_windowswap', 0)) call airline#extensions#windowswap#init(s:ext) call add(loaded_ext, 'windowswap') diff --git a/autoload/airline/extensions/xkblayout.vim b/autoload/airline/extensions/xkblayout.vim new file mode 100644 index 0000000..a9aef83 --- /dev/null +++ b/autoload/airline/extensions/xkblayout.vim @@ -0,0 +1,25 @@ +" MIT License. Copyright (c) 2017 YoungHoon Rhiu. +" vim: et ts=2 sts=2 sw=2 + +scriptencoding utf-8 + +if !exists('g:XkbSwitchLib') + finish +endif + +function! airline#extensions#xkblayout#status() + let keyboard_layout = libcall(g:XkbSwitchLib, 'Xkb_Switch_getXkbLayout', '') + let keyboard_layout = split(keyboard_layout, '\.')[-1] + let short_codes = {'2SetKorean': 'KR', 'Chinese': 'CN', 'Japanese': 'JP'} + + if has_key(short_codes, keyboard_layout) + let keyboard_layout = short_codes[keyboard_layout] + endif + + return keyboard_layout +endfunction + +function! airline#extensions#xkblayout#init(ext) + call airline#parts#define_function('xkblayout', 'airline#extensions#xkblayout#status') +endfunction + diff --git a/autoload/airline/init.vim b/autoload/airline/init.vim index 93cd113..9a68d13 100644 --- a/autoload/airline/init.vim +++ b/autoload/airline/init.vim @@ -104,6 +104,7 @@ function! airline#init#bootstrap() \ 'eclim', 'whitespace','windowswap', 'ycm_error_count', 'ycm_warning_count', \ 'neomake_error_count', 'neomake_warning_count', 'ale_error_count', 'ale_warning_count']) call airline#parts#define_text('capslock', '') + call airline#parts#define_text('xkblayout', '') unlet g:airline#init#bootstrapping endfunction @@ -117,7 +118,7 @@ endfunction function! airline#init#sections() let spc = g:airline_symbols.space if !exists('g:airline_section_a') - let g:airline_section_a = airline#section#create_left(['mode', 'crypt', 'paste', 'spell', 'capslock', 'iminsert']) + let g:airline_section_a = airline#section#create_left(['mode', 'crypt', 'paste', 'spell', 'capslock', 'xkblayout', 'iminsert']) endif if !exists('g:airline_section_b') let g:airline_section_b = airline#section#create(['hunks', 'branch']) diff --git a/doc/.airline.txt.swp b/doc/.airline.txt.swp new file mode 100644 index 0000000..1a6d327 Binary files /dev/null and b/doc/.airline.txt.swp differ diff --git a/doc/airline.txt b/doc/airline.txt index a098dd9..ae2e737 100644 --- a/doc/airline.txt +++ b/doc/airline.txt @@ -754,6 +754,18 @@ vim-capslock * enable/disable vim-capslock integration > let g:airline#extensions#capslock#enabled = 1 +------------------------------------- *airline-xkblayout* +vim-xkblayout + +* enable/disable vim-xkblayout extension > + let g:airline#extensions#xkblayout#enabled = 1 + +* define path to the backend switcher library + Linux (Install https://github.com/ierton/xkb-switch): + let g:XkbSwitchLib = '/usr/local/lib/libxkbswitch.so' + macOS (Install https://github.com/vovkasm/input-source-switcher): + let g:XkbSwitchLib = '/usr/local/lib/libInputSourceSwitcher.dylib' + ------------------------------------- *airline-windowswap* vim-windowswap