This repository was archived by the owner on Mar 14, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathnuake.vim
182 lines (155 loc) · 4.72 KB
/
nuake.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
" autoload/nuake.vim
" Window management {{{1
function! nuake#ToggleWindow() abort "{{{2
let l:nuake_win_nr = bufwinnr(s:NuakeBufNr())
if l:nuake_win_nr == winnr()
call s:CloseWindow()
elseif l:nuake_win_nr != -1
execute l:nuake_win_nr . "wincmd w"
else
call s:OpenWindow()
endif
endfunction
function! s:OpenWindow() abort "{{{2
let l:nuake_buf_nr = bufnr(s:NuakeBufNr())
execute 'silent keepalt ' . s:NuakeLook() . 'split'
if l:nuake_buf_nr != -1
execute 'buffer ' . l:nuake_buf_nr
else
let l:vim_options = has('terminal') ? '++curwin ++kill=kill' : ''
execute 'terminal' . l:vim_options
call s:InitWindow()
call s:NuakeBufNr()
endif
endfunction
function! s:InitWindow() abort "{{{2
" Buffer-local options
setlocal filetype=nuake
setlocal bufhidden=hide
setlocal noswapfile
setlocal nobuflisted
setlocal nomodified
" Window-local options
setlocal nolist
setlocal nowrap
setlocal winfixwidth
setlocal winfixheight
setlocal nospell
setlocal nonumber
setlocal norelativenumber
setlocal nofoldenable
setlocal foldcolumn=0
endfunction
function! s:CloseWindow() abort "{{{2
let l:nuake_win_nr = bufwinnr(s:NuakeBufNr())
if winnr() == l:nuake_win_nr
if winbufnr(2) != -1
close
endif
else
let l:current_buf_nr = bufnr('%')
execute l:nuake_win_nr . 'wincmd w'
close
let l:win_num = bufwinnr(l:current_buf_nr)
if winnr() != l:win_num
execute l:win_num . 'wincmd w'
endif
endif
endfunction
function! s:ResizeWindow() abort "{{{2
let l:nuake_win_nr = bufwinnr(s:NuakeBufNr())
execute l:nuake_win_nr . 'resize ' . s:NuakeLook()
endfunction
function! s:LastStandingWindow() abort "{{{2
if g:nuake_close_if_last_standing == 1
let l:nuake_win_nr = bufwinnr(s:NuakeBufNr())
if winnr('$') < 2 && l:nuake_win_nr != -1
if tabpagenr('$') < 2
bdelete!
quit
else
close
endif
endif
endif
endfunction
" Helpers {{{1
function! s:NuakeBufNr() abort "{{{2
if g:nuake_per_tab == 0
if !exists('s:nuake_buf_nr')
let s:nuake_buf_nr = -1
elseif &filetype == 'nuake' && s:nuake_buf_nr == -1
let s:nuake_buf_nr = bufnr('%')
endif
return s:nuake_buf_nr
else
if !exists('t:nuake_buf_nr')
let t:nuake_buf_nr = -1
elseif &filetype == 'nuake' && t:nuake_buf_nr == -1
let t:nuake_buf_nr = bufnr('%')
endif
return t:nuake_buf_nr
endif
endfunction
function! s:NuakeLook() abort "{{{2
let l:nuake_win_nr = bufwinnr(s:NuakeBufNr())
if g:nuake_position == 'bottom'
let l:mode = 'botright '
let l:size = float2nr(g:nuake_size * floor(&lines - 2))
elseif g:nuake_position == 'right'
let l:mode = l:nuake_win_nr != -1 ? '' : 'botright vertical '
let l:size = float2nr(g:nuake_size * floor(&columns))
elseif g:nuake_position == 'top'
let l:mode = 'topleft '
let l:size = float2nr(g:nuake_size * floor(&lines - 2))
elseif g:nuake_position == 'left'
let l:mode = l:nuake_win_nr != -1 ? '' : 'topleft vertical '
let l:size = float2nr(g:nuake_size * floor(&columns))
endif
let l:nuake_look = l:mode . l:size
return l:nuake_look
endfunction
function! s:NuakeCloseTab() abort "{{{2
if s:temp_nuake_buf_nr > -1
execute 'bdelete! ' . s:temp_nuake_buf_nr
unlet s:temp_nuake_buf_nr
endif
endfunction
"
" Autocomands {{{1
augroup nuake_start_insert
autocmd!
autocmd FileType,BufEnter *
\ if &filetype == 'nuake' && (g:nuake_start_insert == 1) |
\ execute 'silent! normal i' |
\ endif
augroup END
augroup nuake_last_standing_window
autocmd!
autocmd BufEnter * nested call s:LastStandingWindow()
augroup END
augroup nuake_tab_close
if g:nuake_per_tab == 1
autocmd!
autocmd TabLeave * let s:temp_nuake_buf_nr = bufnr(s:NuakeBufNr())
autocmd TabClosed * call s:NuakeCloseTab()
endif
augroup END
augroup nuake_term_killed
autocmd!
autocmd BufDelete *
\ if bufnr(s:NuakeBufNr()) == -1 |
\ let s:nuake_buf_nr = -1 |
\ let t:nuake_buf_nr = -1 |
\ endif
augroup END
augroup nuake_resize_window
autocmd!
autocmd VimResized *
\ if bufwinnr(s:NuakeBufNr()) != -1 |
\ call s:ResizeWindow() |
\ redraw |
\ endif
augroup END
" Modeline {{{1
" vim: ts=8 sw=4 sts=4 et foldenable foldmethod=marker