diff --git a/README.md b/README.md index 4d95843..6ce27b8 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,8 @@ Requirements for `fcitx5-remote` mode (`g:fcitx5_remote` is set): If you are using `fcitx5-rime` (which has its own state), `let g:fcitx5_rime = 1` in your `.vimrc`. +The `FcitxCurrentIM()` function can be used to get current IM's name. + Links: * [git repo](https://github.com/lilydjwg/fcitx.vim) @@ -57,6 +59,8 @@ D-Bus 只在同一用户时有效,所以使用 `sudo vim` 时本代码就失 如果使用 `fcitx5-rime`(它自己有输入状态),在 `.vimrc` 中设置 `let g:fcitx5_rime = 1`。 +`FcitxCurrentIM()` 函数可以用于获取当前输入法的名字。 + 链接: * [git 仓库](https://github.com/lilydjwg/fcitx.vim) diff --git a/plugin/fcitx.py b/plugin/fcitx.py index fd04a68..b6f3083 100644 --- a/plugin/fcitx.py +++ b/plugin/fcitx.py @@ -18,6 +18,9 @@ class FcitxComm(): def deactivate(self): self.fcitx.Deactivate() + def current(self): + return self.fcitx.CurrentInputMethod() + class FcitxRimeComm(): def __init__(self): bus = dbus.SessionBus() @@ -33,6 +36,9 @@ class FcitxRimeComm(): def deactivate(self): self.fcitx.SetAsciiMode(True) + def current(self): + return self.fcitx.GetCurrentSchema() + try: if vim.eval('get(g:, "fcitx5_rime")') == '1': FcitxComm = FcitxRimeComm @@ -69,3 +75,7 @@ def fcitx2zh(): vim.command('let b:inputtoggle = 0') else: vim.command('let b:inputtoggle = 0') + +@may_reconnect +def fcitx_current_im(): + return Fcitx.current() diff --git a/plugin/fcitx.vim b/plugin/fcitx.vim index 992217d..b326c85 100644 --- a/plugin/fcitx.vim +++ b/plugin/fcitx.vim @@ -44,6 +44,9 @@ elseif has('python3') function Fcitx2zh() py3 fcitx2zh() endfunction + function FcitxCurrentIM() + return py3eval('fcitx_current_im()') + endfunction let g:loaded_fcitx = 1 endif