Skip to content

Commit e044d5e

Browse files
authored
fix: don't error on files containing special chars (#75)
* fix: don't error on files containing special chars fixes: #66 * fix: escape the filenames in read/write commands
1 parent 2f5fc67 commit e044d5e

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

autoload/suda.vim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function! suda#read(expr, ...) abort range
8080
\ '%sread %s %s',
8181
\ options.range,
8282
\ options.cmdarg,
83-
\ path,
83+
\ fnameescape(path),
8484
\)), '^\r\?\n', '', '')
8585
endif
8686

@@ -99,7 +99,7 @@ function! suda#read(expr, ...) abort range
9999
\ '%sread %s %s',
100100
\ options.range,
101101
\ options.cmdarg,
102-
\ tempfile,
102+
\ fnameescape(tempfile),
103103
\))
104104
" Rewrite message with a correct file name
105105
let echo_message = substitute(
@@ -133,7 +133,7 @@ function! suda#write(expr, ...) abort range
133133
\ options.range,
134134
\ options.cmdbang ? '!' : '',
135135
\ options.cmdarg,
136-
\ tempfile,
136+
\ fnameescape(tempfile),
137137
\))
138138
if has('win32')
139139
" In MS Windows, tee.exe has been placed at $VIMRUNTIME and $VIMRUNTIME
@@ -274,7 +274,7 @@ function! suda#BufEnter() abort
274274
let bufnr = str2nr(expand('<abuf>'))
275275
execute printf(
276276
\ 'keepalt keepjumps edit suda://%s',
277-
\ fnamemodify(bufname, ':p'),
277+
\ fnameescape(fnamemodify(bufname, ':p')),
278278
\)
279279
execute printf('silent! %dbwipeout', bufnr)
280280
endfunction

plugin/suda.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ augroup END
2020

2121
function! s:read(args) abort
2222
let args = empty(a:args) ? expand('%:p') : a:args
23-
execute printf('edit suda://%s', args)
23+
execute printf('edit suda://%s', fnameescape(args))
2424
endfunction
2525
command! -nargs=? -complete=file SudaRead call s:read(<q-args>)
2626

2727
function! s:write(args) abort
2828
let args = empty(a:args) ? expand('%:p') : a:args
29-
execute printf('write suda://%s', args)
29+
execute printf('write suda://%s', fnameescape(args))
3030
endfunction
3131
command! -nargs=? -complete=file SudaWrite call s:write(<q-args>)

0 commit comments

Comments
 (0)