mirror of
https://github.com/lilydjwg/fcitx.vim.git
synced 2026-01-06 18:54:58 +08:00
Also support fcitx5-remote to toggle IME state
This commit is contained in:
parent
4042bbb29c
commit
bcdbcec7b1
2 changed files with 78 additions and 15 deletions
28
README.md
28
README.md
|
|
@ -2,12 +2,24 @@ Keep and restore fcitx state for each buffer separately when leaving/re-entering
|
||||||
|
|
||||||
D-Bus only works with the same user so this won't work with `sudo vim`. See the `fcitx5-server` branch for an experimental implementation that supports `sudo vim`.
|
D-Bus only works with the same user so this won't work with `sudo vim`. See the `fcitx5-server` branch for an experimental implementation that supports `sudo vim`.
|
||||||
|
|
||||||
Requires:
|
By default, it use python3 and D-Bus to toggle IME state.
|
||||||
|
If you set `g:fcitx5_remote` to the executable path of `fcitx5-remote` **BEFORE** loading the plugin, it will use `fcitx5-remote` instead of python and D-Bus. In this case, python3 support is optional.
|
||||||
|
|
||||||
|
Usually `fcitx5-remote` mode is way faster since python script need 400ms+ for the initial load.
|
||||||
|
|
||||||
|
Base requirements:
|
||||||
|
|
||||||
* fcitx 5
|
* fcitx 5
|
||||||
|
|
||||||
|
Requirements for Python mode (`g:fcitx5_remote` is not set):
|
||||||
|
|
||||||
* Vim with Python 3 compiled in
|
* Vim with Python 3 compiled in
|
||||||
* The python-dbus package
|
* The python-dbus package
|
||||||
|
|
||||||
|
Requirements for `fcitx5-remote` mode (`g:fcitx5_remote` is set):
|
||||||
|
|
||||||
|
* fcitx5-remote
|
||||||
|
|
||||||
Links:
|
Links:
|
||||||
|
|
||||||
* [git repo](https://github.com/lilydjwg/fcitx.vim)
|
* [git repo](https://github.com/lilydjwg/fcitx.vim)
|
||||||
|
|
@ -21,12 +33,24 @@ Warning:
|
||||||
|
|
||||||
D-Bus 只在同一用户时有效,所以使用 `sudo vim` 时本代码就失效了。在 `fcitx5-server` 分支有一个实验性的版本支持 `sudo vim` 的用法。
|
D-Bus 只在同一用户时有效,所以使用 `sudo vim` 时本代码就失效了。在 `fcitx5-server` 分支有一个实验性的版本支持 `sudo vim` 的用法。
|
||||||
|
|
||||||
要求:
|
本插件默认会使用 Python 3 并通过 D-Bus 来切换输入法状态。
|
||||||
|
但如果你在加载插件**之前**设置了 `g:fcitx5_remote` 为你已安装的 `fcitx5-remote` 可执行文件的路径,那么本插件会使用它来切换输入法状态;此模式下本插件并不需要 Python 。
|
||||||
|
|
||||||
|
通常 Python 模式首次加载很慢,需要 400ms+ ,而 `fcitx5-remote` 模式则不会拖慢启动时间。
|
||||||
|
|
||||||
|
基本要求:
|
||||||
|
|
||||||
* fcitx 5
|
* fcitx 5
|
||||||
|
|
||||||
|
使用 Python 模式的要求(未设置 `g:fcitx5_remote`):
|
||||||
|
|
||||||
* 带有 Python 3 支持的 Vim
|
* 带有 Python 3 支持的 Vim
|
||||||
* python-dbus 包
|
* python-dbus 包
|
||||||
|
|
||||||
|
使用 `fcitx5-remote` 模式的要求(需设置 `g:fcitx5_remote`):
|
||||||
|
|
||||||
|
* fcitx5-remote
|
||||||
|
|
||||||
链接:
|
链接:
|
||||||
|
|
||||||
* [git 仓库](https://github.com/lilydjwg/fcitx.vim)
|
* [git 仓库](https://github.com/lilydjwg/fcitx.vim)
|
||||||
|
|
|
||||||
|
|
@ -5,27 +5,66 @@ scriptencoding utf-8
|
||||||
" URL: https://www.vim.org/scripts/script.php?script_id=3764
|
" URL: https://www.vim.org/scripts/script.php?script_id=3764
|
||||||
" ---------------------------------------------------------------------
|
" ---------------------------------------------------------------------
|
||||||
" Load Once:
|
" Load Once:
|
||||||
if &cp || exists("g:loaded_fcitx") || !exists('$DISPLAY') || !has('python3')
|
if &cp || exists("g:loaded_fcitx") || !exists('$DISPLAY')
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
let s:keepcpo = &cpo
|
let s:keepcpo = &cpo
|
||||||
set cpo&vim
|
set cpo&vim
|
||||||
let g:loaded_fcitx = 1
|
|
||||||
|
|
||||||
try " abort on fail
|
" If g:fcitx5_remote is set (to the path to `fcitx5-remove`), use it to toggle IME state.
|
||||||
exe 'py3file' expand('<sfile>:r') . '.py'
|
if exists("g:fcitx5_remote")
|
||||||
if py3eval('fcitx_loaded')
|
function Fcitx2en()
|
||||||
if exists('##InsertLeavePre')
|
let inputstatus = system(g:fcitx5_remote)
|
||||||
au InsertLeavePre * py3 fcitx2en()
|
if inputstatus == 2
|
||||||
else
|
let b:inputtoggle = 1
|
||||||
au InsertLeave * py3 fcitx2en()
|
call system(g:fcitx5_remote . ' -c')
|
||||||
endif
|
endif
|
||||||
au InsertEnter * py3 fcitx2zh()
|
endfunction
|
||||||
au CmdlineEnter [/\?] py3 fcitx2zh()
|
function Fcitx2zh()
|
||||||
au CmdlineLeave [/\?] py3 fcitx2en()
|
try
|
||||||
|
if b:inputtoggle == 1
|
||||||
|
call system(g:fcitx5_remote . ' -o')
|
||||||
|
let b:inputtoggle = 0
|
||||||
|
endif
|
||||||
|
catch /inputtoggle/
|
||||||
|
let b:inputtoggle = 0
|
||||||
|
endtry
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
let g:loaded_fcitx = 1
|
||||||
|
|
||||||
|
" Otherwise, if python3 is available, use python and dbus to toggle IME state.
|
||||||
|
elseif has('python3')
|
||||||
|
try " abort on fail
|
||||||
|
exe 'py3file' expand('<sfile>:r') . '.py'
|
||||||
|
if py3eval('fcitx_loaded')
|
||||||
|
function Fcitx2en()
|
||||||
|
py3 fcitx2en()
|
||||||
|
endfunction
|
||||||
|
function Fcitx2zh()
|
||||||
|
py3 fcitx2zh()
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
let g:loaded_fcitx = 1
|
||||||
|
endif
|
||||||
|
endtry
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Register autocmd if successfully loaded.
|
||||||
|
if exists("g:loaded_fcitx")
|
||||||
|
if exists('##InsertLeavePre')
|
||||||
|
au InsertLeavePre * call Fcitx2en()
|
||||||
|
else
|
||||||
|
au InsertLeave * call Fcitx2en()
|
||||||
endif
|
endif
|
||||||
endtry
|
au InsertEnter * call Fcitx2zh()
|
||||||
|
au CmdlineEnter [/\?] call Fcitx2zh()
|
||||||
|
au CmdlineLeave [/\?] call Fcitx2en()
|
||||||
|
endif
|
||||||
|
|
||||||
" ---------------------------------------------------------------------
|
" ---------------------------------------------------------------------
|
||||||
" Restoration And Modelines:
|
" Restoration And Modelines:
|
||||||
let &cpo=s:keepcpo
|
let &cpo=s:keepcpo
|
||||||
unlet s:keepcpo
|
unlet s:keepcpo
|
||||||
|
|
||||||
|
" vim: sw=2 :
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue