mirror of
https://github.com/keanuplayz/dotfiles.git
synced 2024-08-15 02:33:12 +00:00
[nvim] check for URLs in FormatOnSave
This commit is contained in:
parent
b8ba43a562
commit
f8e9206692
1 changed files with 7 additions and 3 deletions
|
@ -110,13 +110,16 @@ nnoremap <silent><expr> <CR> &buftype is# '' ? ":write<bar>wall\<CR>" : "\<CR>"
|
|||
|
||||
" 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()
|
||||
" <afile> is the filename of the buffer where the autocommand is executed
|
||||
let l:file = expand('<afile>')
|
||||
" 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 <silent><expr> <CR> &buftype is# '' ? ":write<bar>wall\<CR>" : "\<CR>"
|
|||
" 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('<afile>')
|
||||
if IsCocEnabled() && !s:IsUrl(l:file) && index(g:coc_format_on_save_ignore, &filetype) < 0
|
||||
silent CocFormat
|
||||
endif
|
||||
endfunction
|
||||
|
|
Loading…
Reference in a new issue