From 1e491727b2834e4c057517a465f220ddbdfd4e17 Mon Sep 17 00:00:00 2001 From: Wu Zhenyu Date: Tue, 15 Nov 2022 17:09:02 +0800 Subject: [PATCH] Add support for fcitx.vim --- autoload/airline/extensions.vim | 2 +- autoload/airline/extensions/xkblayout.vim | 13 +++++++++---- doc/airline.txt | 11 +++++++++-- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/autoload/airline/extensions.vim b/autoload/airline/extensions.vim index 4f4240c3..e818ed26 100644 --- a/autoload/airline/extensions.vim +++ b/autoload/airline/extensions.vim @@ -429,7 +429,7 @@ function! airline#extensions#load() call add(s:loaded_ext, 'grepper') endif - if (get(g:, 'airline#extensions#xkblayout#enabled', 1) && exists('g:XkbSwitchLib')) + if get(g:, 'airline#extensions#xkblayout#enabled', 1) && (exists('g:XkbSwitchLib') || exists('*FcitxCurrentIM')) call airline#extensions#xkblayout#init(s:ext) call add(s:loaded_ext, 'xkblayout') endif diff --git a/autoload/airline/extensions/xkblayout.vim b/autoload/airline/extensions/xkblayout.vim index 5f5e326b..7e774a2e 100644 --- a/autoload/airline/extensions/xkblayout.vim +++ b/autoload/airline/extensions/xkblayout.vim @@ -3,15 +3,20 @@ scriptencoding utf-8 -if !exists('g:XkbSwitchLib') +if !exists('g:XkbSwitchLib') && !exists('*FcitxCurrentIM') finish endif function! airline#extensions#xkblayout#status() - let keyboard_layout = libcall(g:XkbSwitchLib, 'Xkb_Switch_getXkbLayout', '') - let keyboard_layout = get(split(keyboard_layout, '\.'), -1, '') - let short_codes = get(g:, 'airline#extensions#xkblayout#short_codes', {'2SetKorean': 'KR', 'Chinese': 'CN', 'Japanese': 'JP'}) + if exists('g:XkbSwitchLib') + let keyboard_layout = libcall(g:XkbSwitchLib, 'Xkb_Switch_getXkbLayout', '') + let keyboard_layout = get(split(keyboard_layout, '\.'), -1, '') + else + " substitute keyboard-us to us + let keyboard_layout = substitute(FcitxCurrentIM(), 'keyboard-', '', 'g') + endif + let short_codes = get(g:, 'airline#extensions#xkblayout#short_codes', {'2SetKorean': 'KR', 'Chinese': 'CN', 'Japanese': 'JP'}) if has_key(short_codes, keyboard_layout) let keyboard_layout = short_codes[keyboard_layout] endif diff --git a/doc/airline.txt b/doc/airline.txt index e03092a9..2045cabe 100644 --- a/doc/airline.txt +++ b/doc/airline.txt @@ -1693,7 +1693,8 @@ vim-windowswap ------------------------------------- *airline-xkblayout* The vim-xkblayout extension will only be enabled, if the global variable -`g:XkbSwitchLib` is set. It should be set to a C library that will be called +`g:XkbSwitchLib` is set or `FcitxCurrentIM()` exists. +`g:XkbSwitchLib` should be set to a C library that will be called using |libcall()| with the function name `Xkb_Switch_getXkbLayout`. For details on how to use it, see e.g. @@ -1712,11 +1713,17 @@ details on how to use it, see e.g. \ {'2SetKorean': 'KR', 'Chinese': 'CN', 'Japanese': 'JP'} * define path to the backend switcher library + Linux with gnome (Install https://github.com/lyokha/g3kb-switch): > + let g:XkbSwitchLib = '/usr/lib/libg3kbswitch.so' +< Linux (Install https://github.com/ierton/xkb-switch): > - let g:XkbSwitchLib = '/usr/local/lib/libxkbswitch.so' + let g:XkbSwitchLib = '/usr/lib/libxkbswitch.so' < macOS (Install https://github.com/vovkasm/input-source-switcher): > let g:XkbSwitchLib = '/usr/local/lib/libInputSourceSwitcher.dylib' +< + Linux with fcitx (Install https://github.com/fcitx/fcitx5): + Install https://github.com/lilydjwg/fcitx.vim) to get `FcitxCurrentIM()` ------------------------------------- *airline-xtabline* xtabline