Skip to content

Commit

Permalink
Disable auto updating in favor of auto checking
Browse files Browse the repository at this point in the history
Auto-updating is great. It makes sure users of this config are always on
the latest and greatest and it gives us a hook to pro-actively fix
issues everyone might hit (installing dependencies for go, for example).

But a lot of the times these commits are made in the middle of the day
and people might be working on something and just happened to restart
their editor. Or even in a meeting showing something off to someone
else. At those times having Vim pause and update everything can be a
super frustrating experience.

Moreover, with how slow installing all golang dependencies is these
days, having this happen automatically is quite the surprise if you're
not actually expeciting the update.

This commit embraces the commands `:ConfigUpdate` and `:ConfigUpdate`
and disables the automatic, forced update on boot.

Users will now get a notification to update their configs:

    There is a new version of the nvim config available. Run :ConfigUpdate to update to the latest!

And by default will be directed to use the less intrusive
`:ConfigUpdate` (no `!`) which is much much faster. I expect that lots
of people will end up having to run the `!` version every now and again,
but that can be delayed until they actually have an issue that requires
all dependencies to update.

This direction comes from a timer that runs once on boot and once again
every hour Vim is running and is shown in two ways:

* A warning with the notification above;
* A persistent smaller warning on the bottom right corner of the editor.

[Fixes luan#20]
  • Loading branch information
luan committed Jul 29, 2019
1 parent c0e808f commit 2ef454e
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 47 deletions.
27 changes: 12 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,18 @@ Plugins will be automatically downloaded and setup as necessary.

## Updating

The distribution auto-updates when starting up if there are new changed, if you
have trouble with auto-updating or want to disable it for other reason add the
following to you `user/before.vim`:
The distribution checks for updates on boot and every hour when it's running.
The check is non-disruptive and will only show messages passively when one of
the following is true:

```
let g:skip_autoupdate = 1
```
* An update is available (and you should run `:ConfigUpdate` or
`:ConfigUpdate!`).
* An error occurred fetching the remove version.
* You have local changes on your nvim config repo (you really shouldn't unless
you're preparing a PR).

This distribution uses [vim-plug](https://github.com/junegunn/vim-plug) to
manage plugins, it also uses vim-plug to manage itself. So you can run
`:PlugUpdate` anytime to update all plugins and the distribution itself.
Whenever updating, if anything has changed, it is recommended that you restart
all instances of Neovim to reload plugins and configurations.
`:ConfigUpdate` updates the local config and you can also `:ConfigUpdate!` to
update *and* force run the post-update hooks.

## Customizing

Expand Down Expand Up @@ -110,10 +109,8 @@ wrong with your setup.

Make sure language servers are installed for your language;
`:ConfigInstallLanguageServers` installs a few that aren't automatically managed
by other plugins.

Lastly, `:ConfigUpdate` runs the auto-update and you can also `:ConfigUpdate!`
to update *and* force run the post-update hooks.
by other plugins (this should have happened automatically but it is sometimes good
to make sure it runs successfully).

Sometimes plugin authors make backwards incompatible changes or push changes in
ways that confuse [vim-plug](https://github.com/junegunn/vim-plug). A simple way
Expand Down
12 changes: 10 additions & 2 deletions include/lightline.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,39 @@ scriptencoding utf-8
let g:lightline = {
\ 'active': {
\ 'left': [['mode', 'paste'], ['cocstatus', 'fugitive', 'filename']],
\ 'right': [['lineinfo'], ['percent'], ['linter_checking', 'linter_errors', 'linter_warnings', 'linter_ok']]
\ 'right': [
\ ['lineinfo'],
\ ['percent'],
\ ['linter_checking', 'linter_errors', 'linter_warnings', 'linter_ok'],
\ ['config_outdated'],
\ ]
\ },
\ 'component': {
\ 'lineinfo': ' %3l:%-2v',
\ },
\ 'component_function': {
\ 'fugitive': 'LightlineFugitive',
\ 'cocstatus': 'coc#status',
\ 'filename': 'LightlineFilename'
\ 'filename': 'LightlineFilename',
\ },
\ 'component_expand': {
\ 'linter_checking': 'lightline#ale#checking',
\ 'linter_warnings': 'lightline#ale#warnings',
\ 'linter_errors': 'lightline#ale#errors',
\ 'linter_ok': 'lightline#ale#ok',
\ 'config_outdated': 'update#status',
\ },
\ 'component_type': {
\ 'linter_checking': 'left',
\ 'linter_warnings': 'warning',
\ 'linter_errors': 'error',
\ 'linter_ok': 'left',
\ 'config_outdated': 'warning',
\ },
\ 'separator': { 'left': '', 'right': '' },
\ 'subseparator': { 'left': '', 'right': '' }
\ }

function! LightlineModified()
return &filetype =~# 'help\|vimfiler' ? '' : &modified ? '+' : &modifiable ? '' : '-'
endfunction
Expand Down
13 changes: 5 additions & 8 deletions include/startify.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,22 @@ scriptencoding utf-8
let g:startify_change_to_dir = 0
let g:startify_change_to_vcs_root = 0
let g:startify_lists = [
\ { 'type': 'dir', 'header': [ 'MRU '. getcwd()] },
\ { 'type': 'files', 'header': [ 'MRU'] },
\ { 'type': 'sessions', 'header': [ 'Sessions'] },
\ { 'type': 'bookmarks', 'header': [ 'Bookmarks'] },
\ { 'type': 'commands', 'header': [ 'Commands'] },
\ { 'type': 'dir', 'header': [ 'MRU ' . getcwd()] },
\ { 'type': 'files', 'header': [ 'MRU'] },
\ { 'type': 'sessions', 'header': [ 'Sessions'] },
\ { 'type': 'bookmarks', 'header': [ 'Bookmarks'] },
\ { 'type': 'commands', 'header': [ 'Commands'] },
\ ]

let g:startify_bookmarks = [ {'c': '~/.vimrc'}, '~/.zshrc' ]

let s:version = split(execute('version'), '\n')[0]
let s:configversion = strpart(update#localVersion(), 0, 7)
let s:configupdate = 'auto-update: ' . (update#autoUpdateEnabled() ? 'enabled' : 'disabled')

let g:startify_custom_header = [
\ ' █▀▀▄ █▀▀ █▀▀█ ▀█░█▀ ░▀░ █▀▄▀█',
\ ' █░░█ █▀▀ █░░█ ░█▄█░ ▀█▀ █░▀░█',
\ ' ▀░░▀ ▀▀▀ ▀▀▀▀ ░░▀░░ ▀▀▀ ▀░░░▀',
\ ' config by Luan Santos <https://github.com/luan>',
\ printf(' Neovim Version: %-15s %35s', s:version, '(run :version for more details)'),
\ printf(' Config Version: %-15s %35s', s:configversion, printf('(%s)', s:configupdate)),
\ ]

62 changes: 40 additions & 22 deletions update.vim
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ function! s:system(cmd)
endtry
endfunction

function! update#status()
if update#localVersion() != update#remoteVersion()
return " update available!"
endif

return ""
endfunction

function! update#localVersion()
return s:system('git rev-parse @')
endfunction
Expand All @@ -55,10 +63,6 @@ function! update#remoteVersion()
return s:system('git rev-parse "@{u}"')
endfunction

function! update#autoUpdateEnabled()
return !exists('g:skip_autoupdate') || g:skip_autoupdate != 1
endfunction

function! update#installLanguageServers()
echo 'Installing language servers...'
if executable('gem')
Expand Down Expand Up @@ -116,40 +120,54 @@ function! s:remote_updated(id, status, type)
let l:remote = update#remoteVersion()
let l:base = s:system('git merge-base @ "@{u}"')

if s:force ==# 1
call s:update_hook()
if l:has_local_changes
echohl WarningMsg | echomsg 'Local changes detected. If these are user preferences, consider'
\ 'moving them to your user settings.' | echohl None
elseif l:local == l:remote
return
elseif l:local == l:base
echohl WarningMsg | echomsg 'There is a new version of the nvim config available. Run :ConfigUpdate to update to the latest!' | echohl None
elseif l:remote == l:base
echohl WarningMsg | echomsg 'Local commits detected. You may want to push / send a PR / move your'
\ 'changes to user settings?' | echohl None
endif
endfunction

function! s:update(force)
call s:system('git update-index -q --refresh')
call s:system('git diff-index --quiet HEAD --')

let l:has_local_changes = v:shell_error
let l:local = update#localVersion()
let l:remote = update#remoteVersion()
let l:base = s:system('git merge-base @ "@{u}"')

if l:has_local_changes
echohl ErrorMsg | echomsg 'Local changes detected. If these are user preferences, consider'
\ 'moving them to your user settings.' | echohl None
echohl ErrorMsg | echomsg 'Local changes detected. Update aborted!' | echohl None
return
elseif l:local == l:remote
return
elseif l:local == l:base
call s:system('git merge ' . l:remote)
call s:update_hook()
elseif l:remote == l:base
echohl ErrorMsg | echomsg 'Local commits detected. You may want to push / send a PR / move your'
\ 'changes to user settings?' | echohl None
echohl ErrorMsg | echomsg 'Local commits detected. Update aborted!' | echohl None
return
endif
endfunction

let s:force = 0
if a:force ==# 1
call s:update_hook()
endif
endfunction

function! s:update(force)
let s:force = a:force
function! s:checkupdates(timerid)
let l:update_job = s:jobstart('git remote update', {
\ 'on_exit': function('s:remote_updated')
\ })
endfunction

command ConfigInstallLanguageServers call update#installLanguageServers()
command -bang ConfigUpdate call s:update(<bang>0)

if s:is_win || !update#autoUpdateEnabled()
finish
endif
command! ConfigInstallLanguageServers call update#installLanguageServers()
command! -bang ConfigUpdate call s:update(<bang>0)

autocmd VimEnter * :ConfigUpdate
" every hour, check for updates
let s:timer = timer_start(3600 * 1000, funcref("<sid>checkupdates"), { 'repeat': -1 })
autocmd VimEnter * :call s:checkupdates(0) " check once on load

0 comments on commit 2ef454e

Please sign in to comment.