From: Josef Fortier Date: Sat, 23 Feb 2019 20:53:24 +0000 (-0600) Subject: Redid config X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/a8037bb8cc8b46d506e43005acebb1e96e090ae5 Redid config syntax loads too early to be easily controllable from user settings. Moving it to ftdetect allows testing user values at that point. Used a non auto loading syntax --- diff --git a/autoload/password_store.vim b/autoload/password_store.vim index 9e3c5b6..d8ebedc 100644 --- a/autoload/password_store.vim +++ b/autoload/password_store.vim @@ -19,4 +19,18 @@ function! password_store#replace() abort execute 's/\<.*\>/' . password_store#generate() . '/' endfunction +let s:default_settings = { + \ 'pw_length' : '12', + \ 'enable_syntax' : 'true', + \ } + +function! password_store#setting(key) + if exists('g:password_store_settings') && has_key(g:password_store_settings, a:key) + echo 'found key' + return g:password_store_settings[a:key] + else + return s:default_settings[a:key] + endif +endfunction + let &cpoptions = s:save_cpo diff --git a/ftdetect/pass.vim b/ftdetect/pass.vim index 6601555..e80d8b6 100644 --- a/ftdetect/pass.vim +++ b/ftdetect/pass.vim @@ -13,7 +13,8 @@ autocmd VimEnter \,/dev/shm/gopass-edit*/secret \,$TMPDIR/pass.?*/?*.txt \,/tmp/pass.?*/?*.txt - \ setlocal filetype=pass + \ setlocal filetype=pass | + \ if password_store#setting('enable_syntax') ==# 'true' | setlocal syntax=pass_delayed | endif " Cleanup at end let &cpoptions = s:save_cpo diff --git a/ftplugin/pass.vim b/ftplugin/pass.vim index 66b91c7..c6a2680 100644 --- a/ftplugin/pass.vim +++ b/ftplugin/pass.vim @@ -5,26 +5,6 @@ let g:did_pass = 'did_pass_ftplugin' let s:save_cpo = &cpoptions set compatible&vim - -let s:default_settings = { - \ 'pw_length' : '12', - \ 'enable_syntax' : 'true', - \ } - -if ! exists('g:password_store_settings') - let g:password_store_settings = {} -endif - -for s:setting in keys(s:default_settings) - if ! has_key( g:password_store_settings, s:setting ) - let g:password_store_settings[s:setting] = s:default_settings[s:setting] - endif -endfor - -if ! exists('g:password_store_pw_length') - let g:password_store_pw_length = 12 -endif - nmap rotate_password :call password_store#replace() if ! hasmapto( '\rotate_password', 'n') nmap rotate_password @@ -70,5 +50,9 @@ endfunction command! Conceal call conceal_pass() normal! GG +augroup password_settings_late_load + autocmd! + autocmd FileReadPost if &filetype == 'pass' | echom 'autocmd triggered' | let b:load_pass_syntax = 1 | source 'syntax/pass.vim' | endif +augroup end " Cleanup at end let &cpoptions = s:save_cpo diff --git a/syntax/pass.vim b/syntax/pass_delayed.vim similarity index 94% rename from syntax/pass.vim rename to syntax/pass_delayed.vim index 2613069..b925920 100644 --- a/syntax/pass.vim +++ b/syntax/pass_delayed.vim @@ -1,5 +1,4 @@ if exists('b:current_syntax') | finish| endif -if g:password_store_settings.enable_syntax != 'true' | finish | endif " set redacted colors from colorscheme let s:error_highlight_str = execute( 'highlight Error' ) diff --git a/t/settings.vader b/t/settings.vader new file mode 100644 index 0000000..90a1a6a --- /dev/null +++ b/t/settings.vader @@ -0,0 +1,21 @@ +Given pass (short password): + pass + +Execute (test short password syntax): + AssertEqual SyntaxAt(2), 'password_store_password_short' + +Given pass (longer password): + passwordlonger + +Execute (test longer password syntax): + AssertEqual SyntaxAt(2), 'password_store_password' + +Given pass (another password): + passwordlonger + +Before (disable syntax): + let g:password_store_settings = {} + let g:password_store_settings.enable_syntax = 'false' + +Execute (test disable syntax ): + AssertEqual SyntaxAt(2), ''