Skip to content

Commit

Permalink
make changing plugin's behavior easier
Browse files Browse the repository at this point in the history
close @2
close #4
related #5
  • Loading branch information
h-youhei committed Jul 22, 2018
1 parent 2c452e8 commit dbf9bd2
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 38 deletions.
3 changes: 3 additions & 0 deletions BreakingChange.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2018-07-14
- remove g:fcitx#handle_insert_mode, use g:fcitx#insert_mode_behavior
- remove g:fcitx#handle_search_command, use g:fcitx#commandline_behavior
53 changes: 25 additions & 28 deletions doc/vim-fcitx.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,36 +57,33 @@ fcitx#restore_state() *fcitx#restore_state()*
==============================================================================
VARIABLES *vim-fcitx-variables*

g:fcitx#handle_insert_mode *g:fcitx#handle_insert_mode*
type: bool
default: |v:true|

Whether the plugin does setting for handling insert mode,
If you do setting yourself, set this variable to 0 or |v:false|.

g:fcitx#handle_search_command *g:fcitx#handle_search_command*
type: bool
default: |v:false|

Whether the plugin does setting for handling search mode.
For more information, see |vim-fcitx-search|.
g:fcitx#insert_mode_behavior *g:fcitx#insert_mode_behavior*
type: string
default: 'restore'
available: 'restore' 'off' 'nothing'

'restore'
turn off fcitx when you leave insert mode.
restore fcitx state when you re-enter insert mode.
'off'
turn off fcitx when you leave insert mode.
'nothing'
do nothing

g:fcitx#commandline_behavior *g:fcitx#commandline_behavior*
type: string
default: 'restore'
available: 'restore' 'off' 'nothing'

'restore'
turn off fcitx when you leave command line.
restore fcitx state when you search again.
'off'
turn off fcitx when you leave command line.
'nothing'
do nothing

==============================================================================
FAQ *vim-fcitx-faq*

*vim-fcitx-search*
Q: How can I handle fcitx state automatically when I enter/leave search command?

A:
>
let g:fcitx#handle_search_command = v:true
<
If you want to do setting more flexible, you can refer below code.
>
nnoremap <expr> / (fcitx#restore_state() . '/')
nnoremap <expr> ? (fcitx#restore_state() . '?')
cnoremap <expr> <CR> (fcitx#inactivate_with_state() . '<CR>')
cnoremap <expr> <Esc> (fcitx#inactivate_with_state() . '<C-u><BS>')
<

vim:tw=78:ts=8:sw=8:sts=0:ft=help:norl:noet:fen:fdl=0
38 changes: 28 additions & 10 deletions plugin/fcitx.vim
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,48 @@ let s:save_cpo = &cpo
set cpo&vim


if !exists('g:fcitx#handle_insert_mode')
let g:fcitx#handle_insert_mode = v:true
if !exists('g:fcitx#insert_mode_behavior')
let g:fcitx#insert_mode_behavior = 'restore'
endif
if !exists('g:fcitx#handle_search_command')
let g:fcitx#handle_search_command = v:false
if !exists('g:fcitx#commandline_behavior')
let g:fcitx#commandline_behavior = 'off'
endif

if exists('g:fcitx#handle_insert_mode')
echo 'g:fcitx#handle_insert_mode is removed.'
echo 'use g:fcitx#insert_mode_behavior instead.'
endif
if exists('g:fcitx#handle_search_command')
echo 'g:ibus#handle_search_command is removed.'
echo 'use g:fcitx#commandline_behavior instead.'
endif

augroup fcitx
autocmd!
au BufEnter,CmdwinEnter * let b:was_fcitx_on = v:false
augroup END

if g:fcitx#handle_insert_mode
if g:fcitx#insert_mode_behavior == 'restore'
augroup fcitx
au InsertLeave * call fcitx#inactivate_with_state()
au InsertEnter * call fcitx#restore_state()
augroup END
elseif g:fcitx#insert_mode_behavior == 'off'
augroup fcitx
au InsertLeave * call fcitx#inactivate()
augroup END
endif

if g:fcitx#handle_search_command
nnoremap <expr> / (fcitx#restore_state() . '/')
nnoremap <expr> ? (fcitx#restore_state() . '?')
cnoremap <expr> <CR> (fcitx#inactivate_with_state() . '<CR>')
cnoremap <expr> <Esc> (fcitx#inactivate_with_state() . '<C-u><BS>')
if g:fcitx#commandline_behavior == 'restore'
augroup fcitx
au CmdLineLeave [/\?] call fcitx#inactivate_with_state()
au CmdLineEnter [/\?] call fcitx#restore_state()
au CmdLineLeave : call fcitx#inactivate()
augroup END
elseif g:fcitx#commandline_behavior == 'off'
augroup fcitx
au CmdLineLeave * call fcitx#inactivate()
augroup END
endif

let g:loaded_vim_fcitx = v:true
Expand Down
2 changes: 2 additions & 0 deletions test/deprecate.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let g:fcitx#handle_insert_mode = v:true
let g:fcitx#handle_search_command = v:true
2 changes: 2 additions & 0 deletions test/none.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let g:fcitx#insert_mode_behavior = 'none'
let g:fcitx#commandline_behavior = 'none'
2 changes: 2 additions & 0 deletions test/off.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let g:fcitx#insert_mode_behavior = 'off'
let g:fcitx#commandline_behavior = 'off'
2 changes: 2 additions & 0 deletions test/restore.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let g:fcitx#insert_mode_behavior = 'restore'
let g:fcitx#commandline_behavior = 'restore'

0 comments on commit dbf9bd2

Please sign in to comment.