1
- scriptencoding utf- 8
2
- scriptversion 3
3
-
4
1
" Params:
5
2
" - (first argument) {string | undefined} (Optional)
6
3
" - File extension without '.', e.g., 'md', 'ts', or 'sh'
@@ -24,11 +21,35 @@ function! scratch_buffer#open_file(opening_next_fresh_buffer, ...) abort
24
21
\ })
25
22
endfunction
26
23
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
+
27
46
function ! s: open_buffer (options ) abort
28
47
const args = a: options .args
29
48
const opening_as_tmp_buffer = a: options .opening_as_tmp_buffer
30
49
const opening_next_fresh_buffer = a: options .opening_next_fresh_buffer
31
50
51
+ call scratch_buffer#initialize_augroup ()
52
+
32
53
const file_ext = get (args , 0 , g: scratch_buffer_default_file_ext )
33
54
const file_pattern = s: get_file_pattern (opening_as_tmp_buffer, file_ext)
34
55
0 commit comments