From f8e92066922197582a525f3442b699fd25a9c091 Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Sun, 8 Mar 2020 02:49:27 +0200 Subject: [PATCH] [nvim] check for URLs in FormatOnSave --- nvim/plugin/files.vim | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/nvim/plugin/files.vim b/nvim/plugin/files.vim index dc66d1b..7464f88 100644 --- a/nvim/plugin/files.vim +++ b/nvim/plugin/files.vim @@ -110,13 +110,16 @@ nnoremap &buftype is# '' ? ":writewall\" : "\" " on save (BufWritePre) {{{ + function s:IsUrl(str) + return a:str =~# '\v^\w+://' + endfunction + " create directory {{{ " Creates the parent directory of the file if it doesn't exist function s:CreateDirOnSave() - " is the filename of the buffer where the autocommand is executed let l:file = expand('') " check if this is a regular file and its path is not a URL - if empty(&buftype) && l:file !~# '\v^\w+://' + if empty(&buftype) && !s:IsUrl(l:file) let l:dir = fnamemodify(l:file, ':h') if !isdirectory(l:dir) | call mkdir(l:dir, 'p') | endif endif @@ -137,7 +140,8 @@ nnoremap &buftype is# '' ? ":writewall\" : "\" " auto-format with Coc.nvim {{{ let g:coc_format_on_save_ignore = [] function s:FormatOnSave() - if IsCocEnabled() && index(g:coc_format_on_save_ignore, &filetype) < 0 + let l:file = expand('') + if IsCocEnabled() && !s:IsUrl(l:file) && index(g:coc_format_on_save_ignore, &filetype) < 0 silent CocFormat endif endfunction