spacevim/bundle/calendar.vim/autoload/calendar/autocmd.vim
JIe 2bb7059579
Some checks failed
Detach Plugins / check (FlyGrep.vim) (push) Has been cancelled
Detach Plugins / check (GitHub.vim) (push) Has been cancelled
Detach Plugins / check (JavaUnit.vim) (push) Has been cancelled
Detach Plugins / check (SourceCounter.vim) (push) Has been cancelled
Detach Plugins / check (cpicker.nvim) (push) Has been cancelled
Detach Plugins / check (dein-ui.vim) (push) Has been cancelled
Detach Plugins / check (git.vim) (push) Has been cancelled
Detach Plugins / check (iedit.vim) (push) Has been cancelled
Detach Plugins / check (scrollbar.vim) (push) Has been cancelled
Detach Plugins / check (vim-chat) (push) Has been cancelled
Detach Plugins / check (vim-cheat) (push) Has been cancelled
Detach Plugins / check (vim-todo) (push) Has been cancelled
Detach Plugins / check (xmake.vim) (push) Has been cancelled
test / Linux (nvim, nightly) (push) Has been cancelled
test / Linux (nvim, v0.3.8) (push) Has been cancelled
test / Linux (nvim, v0.4.0) (push) Has been cancelled
test / Linux (nvim, v0.4.2) (push) Has been cancelled
test / Linux (nvim, v0.4.3) (push) Has been cancelled
test / Linux (nvim, v0.4.4) (push) Has been cancelled
test / Linux (nvim, v0.5.0) (push) Has been cancelled
test / Linux (nvim, v0.5.1) (push) Has been cancelled
test / Linux (nvim, v0.6.0) (push) Has been cancelled
test / Linux (nvim, v0.6.1) (push) Has been cancelled
test / Linux (nvim, v0.7.0) (push) Has been cancelled
test / Linux (nvim, v0.7.2) (push) Has been cancelled
test / Linux (nvim, v0.8.0) (push) Has been cancelled
test / Linux (nvim, v0.8.1) (push) Has been cancelled
test / Linux (nvim, v0.8.2) (push) Has been cancelled
test / Linux (nvim, v0.8.3) (push) Has been cancelled
test / Linux (nvim, v0.9.0) (push) Has been cancelled
test / Linux (nvim, v0.9.1) (push) Has been cancelled
test / Linux (true, vim, v7.4.052) (push) Has been cancelled
test / Linux (true, vim, v7.4.1689) (push) Has been cancelled
test / Linux (true, vim, v7.4.629) (push) Has been cancelled
test / Linux (true, vim, v8.0.0027) (push) Has been cancelled
test / Linux (true, vim, v8.0.0183) (push) Has been cancelled
test / Linux (vim, nightly) (push) Has been cancelled
test / Linux (vim, v8.0.0184) (push) Has been cancelled
test / Linux (vim, v8.0.1453) (push) Has been cancelled
test / Linux (vim, v8.1.2269) (push) Has been cancelled
test / Linux (vim, v8.2.2434) (push) Has been cancelled
test / Linux (vim, v8.2.3995) (push) Has been cancelled
test / Windows (nvim, nightly) (push) Has been cancelled
test / Windows (nvim, v0.3.8) (push) Has been cancelled
test / Windows (nvim, v0.4.2) (push) Has been cancelled
test / Windows (nvim, v0.4.3) (push) Has been cancelled
test / Windows (nvim, v0.4.4) (push) Has been cancelled
test / Windows (nvim, v0.5.0) (push) Has been cancelled
test / Windows (nvim, v0.5.1) (push) Has been cancelled
test / Windows (nvim, v0.6.0) (push) Has been cancelled
test / Windows (nvim, v0.6.1) (push) Has been cancelled
test / Windows (nvim, v0.7.0) (push) Has been cancelled
test / Windows (nvim, v0.7.2) (push) Has been cancelled
test / Windows (nvim, v0.8.0) (push) Has been cancelled
test / Windows (nvim, v0.8.1) (push) Has been cancelled
test / Windows (nvim, v0.8.2) (push) Has been cancelled
test / Windows (nvim, v0.8.3) (push) Has been cancelled
test / Windows (nvim, v0.9.0) (push) Has been cancelled
test / Windows (nvim, v0.9.1) (push) Has been cancelled
test / Windows (vim, nightly) (push) Has been cancelled
test / Windows (vim, v7.4.1185) (push) Has been cancelled
test / Windows (vim, v7.4.1689) (push) Has been cancelled
test / Windows (vim, v8.0.0027) (push) Has been cancelled
test / Windows (vim, v8.0.1453) (push) Has been cancelled
test / Windows (vim, v8.1.2269) (push) Has been cancelled
test / Windows (vim, v8.2.2434) (push) Has been cancelled
test / Windows (vim, v8.2.3995) (push) Has been cancelled
docker / docker (push) Has been cancelled
mirror / check (coding) (push) Has been cancelled
mirror / check (gitee) (push) Has been cancelled
mirror / check (gitlab) (push) Has been cancelled
init
2024-08-21 14:17:26 +08:00

99 lines
3.1 KiB
VimL

" =============================================================================
" Filename: autoload/calendar/autocmd.vim
" Author: itchyny
" License: MIT License
" Last Change: 2016/09/20 22:09:40.
" =============================================================================
let s:save_cpo = &cpo
set cpo&vim
" Autocmd commands.
function! calendar#autocmd#new() abort
if &l:filetype ==# 'calendar'
return
endif
augroup CalendarAutoUpdate
autocmd!
" Update a visible calendar buffer.
autocmd BufEnter,BufWritePost,VimResized *
\ silent! call s:update_visible(expand('<abuf>'), 0)
autocmd ColorScheme *
\ silent! call s:update_visible(expand('<abuf>'), 1)
augroup END
augroup CalendarBuffer
" When colorscheme is changed, all the calendar syntax groups will be gone.
" So set the filetype forcibly and load the syntax file again.
autocmd ColorScheme <buffer>
\ silent! call calendar#setlocal#filetype_force() |
\ silent! call calendar#color#refresh_syntax()
" On entering the buffer, update the calendar.
autocmd BufEnter,WinEnter,ColorScheme <buffer>
\ silent! call calendar#revive() |
\ silent! call b:calendar.update()
" On entering the buffer, fire CursorHold to update the clock.
autocmd BufEnter,WinEnter <buffer>
\ silent! doautocmd CursorHold
" On resizing the Vim window, check the window size and update if it is changed.
autocmd VimResized,CursorHold <buffer>
\ silent! call b:calendar.update_if_resized()
" When the cursor is moved, update the cursor appropriately.
" In mapping.vim, 'gg' is mapped to '<Plug>(calendar_first_line)' on default.
" However, if we press 'g' and 'g' slowly, '<Plug>(calendar_first_line)' will
" not be triggered. Pressing 'g' and '$' slowly also causes the same situation.
" To avoid this, check the cursor position on CursorMoved and move the cursor
" to the proper position.
autocmd CursorMoved <buffer>
\ silent! call b:calendar.cursor_moved()
augroup END
endfunction
" Search the calendar buffer and updates.
function! s:update_visible(bufnr, is_colorscheme) abort
try
let nr = -1
let newnr = str2nr(a:bufnr)
if bufname(newnr) ==# '[Command Line]'
return
endif
for buf in tabpagebuflist()
if type(getbufvar(buf, 'calendar')) == type({}) && buf != newnr
let nr = buf
break
endif
endfor
if nr == -1 | return | endif
let winnr = bufwinnr(nr)
let newbuf = bufwinnr(str2nr(a:bufnr))
let currentbuf = bufwinnr(bufnr('%'))
noautocmd execute winnr 'wincmd w'
if a:is_colorscheme
silent! call calendar#setlocal#filetype_force()
silent! call calendar#color#refresh_syntax()
endif
silent! call b:calendar.update_force()
if winnr != newbuf && newbuf != -1
call cursor(1, 1)
noautocmd execute newbuf 'wincmd w'
elseif winnr != currentbuf && currentbuf != -1
call cursor(1, 1)
noautocmd execute currentbuf 'wincmd w'
endif
catch
endtry
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo