Files
Ingo Karkat a01208c353 FIX: Make ingo#cmdline#showmode#TemporaryNoShowMode() work again
The CursorMovedI event is triggered immediately after the abbreviation is expanded (in my IHint.vim plugin), and 'showmode' is directly restored. I dunno how this worked before (but I remember it did).
Exclude the current cursor position by setting and comparing a record. A difficulty here is that we need the record _after_ the typed character, so one to the right. Apparently, we cannot grab that character, because it's not there yet. Fortunately, abbreviation expansion is mostly triggered by whitespace and ASCII characters, so just add one to the column and it should be good in most cases.
2019-05-15 23:02:07 +02:00

66 lines
2.4 KiB
VimL

" ingo/cmdline/showmode.vim: Functions for the 'showmode' option.
"
" DEPENDENCIES:
"
" Copyright: (C) 2013-2019 Ingo Karkat
" The VIM LICENSE applies to this script; see ':help copyright'.
"
" Maintainer: Ingo Karkat <ingo@karkat.de>
"
" REVISION DATE REMARKS
" 1.025.003 26-Jan-2016 Add ingo#cmdline#showmode#TemporaryNoShowMode()
" variant of
" ingo#cmdline#showmode#OneLineTemporaryNoShowMode().
" 1.009.002 20-Jun-2013 Indicate activation with return code.
" 1.009.001 18-Jun-2013 file creation from SnippetComplete.vim
let s:record = []
function! ingo#cmdline#showmode#TemporaryNoShowMode()
"******************************************************************************
"* PURPOSE:
" An active 'showmode' setting may prevent the user from seeing the message in
" a command line. Thus, we temporarily disable the 'showmode' setting.
" Sometimes, this only happens in a single-line command line, but :echo'd text
" is visible when 'cmdline' is larger than 1. For that, use
" ingo#cmdline#showmode#OneLineTemporaryNoShowMode().
"* ASSUMPTIONS / PRECONDITIONS:
" None.
"* EFFECTS / POSTCONDITIONS:
" None.
"* INPUTS:
" None.
"* RETURN VALUES:
" Boolean flag whether the temporary mode has been activated.
"******************************************************************************
if ! &showmode || &cmdheight > 1
return 0
endif
set noshowmode
let s:record = ingo#record#Position(0)
let s:record[2] += 1
" Use a single-use autocmd to restore the 'showmode' setting when the cursor
" is moved or insert mode is left.
augroup IngoLibraryNoShowMode
autocmd!
" XXX: After a cursor move, the mode message doesn't instantly appear
" again. A jump with scrolling or another mode change has to happen.
" Neither :redraw nor :redrawstatus will do, but apparently :echo
" triggers an update.
autocmd CursorMovedI * if s:record != ingo#record#Position(0) | set showmode | echo '' | execute 'autocmd! IngoLibraryNoShowMode' | endif
autocmd InsertLeave * if s:record != ingo#record#Position(0) | set showmode | execute 'autocmd! IngoLibraryNoShowMode' | endif
augroup END
return 1
endfunction
function! ingo#cmdline#showmode#OneLineTemporaryNoShowMode()
if &cmdheight > 1
return 0
endif
return ingo#cmdline#showmode#TemporaryNoShowMode()
endfunction
" vim: set ts=8 sts=4 sw=4 noexpandtab ff=unix fdm=syntax :