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 \ })
2522endfunction
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+
2746function ! 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
0 commit comments