From bc35da5217ab13a21609d2f770cccb4aabddbeba Mon Sep 17 00:00:00 2001 From: Enno Date: Sat, 16 Jun 2018 15:06:30 -0300 Subject: [PATCH] automatically escape file path's if necessary --- ftplugin/mail/CheckAttach.vim | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ftplugin/mail/CheckAttach.vim b/ftplugin/mail/CheckAttach.vim index aa0046d..baed946 100644 --- a/ftplugin/mail/CheckAttach.vim +++ b/ftplugin/mail/CheckAttach.vim @@ -90,6 +90,7 @@ fu! AutoCmd() "{{{2 if !empty("s:load_autocmd") && s:load_autocmd augroup CheckAttach au! BufWriteCmd :call CheckAttach() + au! BufWriteCmd :call CheckFilePath() augroup END else silent! au! CheckAttach BufWriteCmd @@ -286,6 +287,22 @@ fu! CheckNewLastLine() "{{{2 endif endif endfu +fun CheckFilePath() "{{{2 + let line_number = 1 + let last_line_number = line('$') + while line_number < last_line_number + let line = getline(line_number) + if empty(line) | break | endif + let file = matchstr(line, '^\vAttach:\s*\zs(.*)$') + if filereadable(file) + call system('test -r ' . file) + if v:shell_error + call setline(line_number, 'Attach: ' . fnameescape(file)) + endif + endif + let line_number = line_number + 1 + endwhile +endf " Define Commands: "{{{1 " Define commands that will disable and enable the plugin. command! -buffer EnableCheckAttach :call TriggerAuCmd(1)