Skip to content

Commit 9ccd590

Browse files
committed
Resolve a part of test cases
1 parent 801c685 commit 9ccd590

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

autoload/scratch_buffer.vim

+24-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
scriptencoding utf-8
2-
scriptversion 3
3-
41
" Params:
52
" - (first argument) {string | undefined} (Optional)
63
" - File extension without '.', e.g., 'md', 'ts', or 'sh'
@@ -24,11 +21,35 @@ function! scratch_buffer#open_file(opening_next_fresh_buffer, ...) abort
2421
\ })
2522
endfunction
2623

24+
" Initialize augroup in case options were updated
25+
function! scratch_buffer#initialize_augroup() abort
26+
augroup VimScratchBuffer
27+
autocmd!
28+
execute
29+
\ 'autocmd'
30+
\ 'TextChanged'
31+
\ substitute(g:scratch_buffer_file_pattern.when_file_buffer, '%d', '*', '')
32+
\ 'call scratch_buffer#autocmd#save_file_buffer_if_enabled()'
33+
execute
34+
\ 'autocmd'
35+
\ 'WinLeave'
36+
\ substitute(g:scratch_buffer_file_pattern.when_tmp_buffer, '%d', '*', '')
37+
\ 'call scratch_buffer#autocmd#hide_buffer_if_enabled()'
38+
execute
39+
\ 'autocmd'
40+
\ 'WinLeave'
41+
\ substitute(g:scratch_buffer_file_pattern.when_file_buffer, '%d', '*', '')
42+
\ 'call scratch_buffer#autocmd#hide_buffer_if_enabled()'
43+
augroup END
44+
endfunction
45+
2746
function! s:open_buffer(options) abort
2847
const args = a:options.args
2948
const opening_as_tmp_buffer = a:options.opening_as_tmp_buffer
3049
const opening_next_fresh_buffer = a:options.opening_next_fresh_buffer
3150

51+
call scratch_buffer#initialize_augroup()
52+
3253
const file_ext = get(args, 0, g:scratch_buffer_default_file_ext)
3354
const file_pattern = s:get_file_pattern(opening_as_tmp_buffer, file_ext)
3455

autoload/scratch_buffer/autocmd.vim

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
scriptencoding utf-8
2-
scriptversion 3
3-
41
function! scratch_buffer#autocmd#save_file_buffer_if_enabled() abort
52
if g:scratch_buffer_auto_save_file_buffer && (&buftype !=# 'nofile')
6-
silent! write
3+
silent write
74
endif
85
endfunction
96

plugin/scratch_buffer.vim

+1-15
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,7 @@ let g:scratch_buffer_auto_hide_buffer = get(g:, 'scratch_buffer_auto_hide_buffer
5757
let g:scratch_buffer_auto_hide_buffer.when_tmp_buffer = get(g:scratch_buffer_auto_hide_buffer, 'when_tmp_buffer', v:false)
5858
let g:scratch_buffer_auto_hide_buffer.when_file_buffer = get(g:scratch_buffer_auto_hide_buffer, 'when_file_buffer', v:false)
5959

60-
augroup VimScratchBuffer
61-
autocmd!
62-
63-
execute
64-
\ 'autocmd'
65-
\ 'TextChanged'
66-
\ substitute(g:scratch_buffer_file_pattern.when_file_buffer, '%d', '*', '')
67-
\ 'call scratch_buffer#autocmd#save_file_buffer_if_enabled()'
68-
69-
execute
70-
\ 'autocmd'
71-
\ 'WinLeave'
72-
\ substitute(g:scratch_buffer_file_pattern.when_tmp_buffer, '%d', '*', '')
73-
\ 'call scratch_buffer#autocmd#hide_buffer_if_enabled()'
74-
augroup END
60+
call scratch_buffer#initialize_augroup()
7561

7662
if g:scratch_buffer_use_default_keymappings
7763
nnoremap <silent> <leader>b <Cmd>ScratchBufferOpen<CR>

0 commit comments

Comments
 (0)