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
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
\,/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
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 <buffer> <Plug>rotate_password :call password_store#replace()<Cr>
if ! hasmapto( '\<Plug>rotate_password', 'n')
nmap <C-X> <Plug>rotate_password
command! Conceal call <SID>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
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' )
--- /dev/null
+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), ''