]> git.madduck.net Git - etc/vim.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Redid config
authorJosef Fortier <fortier@augsburg.edu>
Sat, 23 Feb 2019 20:53:24 +0000 (14:53 -0600)
committerJosef Fortier <fortier@augsburg.edu>
Sat, 23 Feb 2019 20:53:24 +0000 (14:53 -0600)
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

autoload/password_store.vim
ftdetect/pass.vim
ftplugin/pass.vim
syntax/pass_delayed.vim [moved from syntax/pass.vim with 94% similarity]
t/settings.vader [new file with mode: 0644]

index 9e3c5b6ce806b815c940eb0410ae5bec38007124..d8ebedcaedf144bbd19f0d3299bef71faee5d2b2 100644 (file)
@@ -19,4 +19,18 @@ function! password_store#replace() abort
     execute 's/\<.*\>/' . password_store#generate() . '/'
 endfunction
 
     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
 let &cpoptions = s:save_cpo
index 6601555c736fb9ce32cb96c47af020b8140045c4..e80d8b648f5854dbc102e8485905583f7be6d3d6 100644 (file)
@@ -13,7 +13,8 @@ autocmd VimEnter
             \,/dev/shm/gopass-edit*/secret
             \,$TMPDIR/pass.?*/?*.txt
             \,/tmp/pass.?*/?*.txt
             \,/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
 
 " Cleanup at end
 let &cpoptions = s:save_cpo
index 66b91c7c5f43eb177195e27a9196cf03bee78e2a..c6a2680a8bdb36ae3bc40d0da9d6e8ef535d2a0b 100644 (file)
@@ -5,26 +5,6 @@ let g:did_pass = 'did_pass_ftplugin'
 let s:save_cpo = &cpoptions
 set compatible&vim
 
 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
 nmap <buffer> <Plug>rotate_password :call password_store#replace()<Cr>
 if ! hasmapto( '\<Plug>rotate_password', 'n')
     nmap <C-X> <Plug>rotate_password
@@ -70,5 +50,9 @@ endfunction
 command! Conceal call <SID>conceal_pass()
 normal! GG
 
 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
 " Cleanup at end
 let &cpoptions = s:save_cpo
similarity index 94%
rename from syntax/pass.vim
rename to syntax/pass_delayed.vim
index 261306905bcb1c128addc9cfa14a48761659aeff..b925920211cffc0338be30c02d09eea07affb9ff 100644 (file)
@@ -1,5 +1,4 @@
 if exists('b:current_syntax') | finish|  endif
 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' )
 
 " 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 (file)
index 0000000..90a1a6a
--- /dev/null
@@ -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), ''