David Blume commited on 2021-04-06 17:46:15
Showing 2 changed files, with 21 additions and 15 deletions.
... | ... |
@@ -1,17 +1,17 @@ |
1 | 1 |
if exists("g:loaded_bbye") || &cp | finish | endif |
2 | 2 |
let g:loaded_bbye = 1 |
3 | 3 |
|
4 |
-function! s:bdelete(bang, buffer_name) |
|
4 |
+function! s:bdelete(action, bang, buffer_name) |
|
5 | 5 |
let buffer = s:str2bufnr(a:buffer_name) |
6 | 6 |
let w:bbye_back = 1 |
7 | 7 |
|
8 | 8 |
if buffer < 0 |
9 |
- return s:warn("E516: No buffers were deleted. No match for ".a:buffer_name) |
|
9 |
+ return s:error("E516: No buffers were deleted. No match for ".a:buffer_name) |
|
10 | 10 |
endif |
11 | 11 |
|
12 | 12 |
if getbufvar(buffer, "&modified") && empty(a:bang) |
13 | 13 |
let error = "E89: No write since last change for buffer " |
14 |
- return s:warn(error . buffer . " (add ! to override)") |
|
14 |
+ return s:error(error . buffer . " (add ! to override)") |
|
15 | 15 |
endif |
16 | 16 |
|
17 | 17 |
" If the buffer is set to delete and it contains changes, we can't switch |
... | ... |
@@ -45,15 +45,18 @@ function! s:bdelete(bang, buffer_name) |
45 | 45 |
|
46 | 46 |
" If it hasn't been already deleted by &bufhidden, end its pains now. |
47 | 47 |
" Unless it previously was an unnamed buffer and :enew returned it again. |
48 |
- if bufexists(buffer) && buffer != bufnr("%") |
|
49 |
- exe "bdelete" . a:bang . " " . buffer |
|
48 |
+ " |
|
49 |
+ " Using buflisted() over bufexists() because bufhidden=delete causes the |
|
50 |
+ " buffer to still _exist_ even though it won't be :bdelete-able. |
|
51 |
+ if buflisted(buffer) && buffer != bufnr("%") |
|
52 |
+ exe a:action . a:bang . " " . buffer |
|
50 | 53 |
endif |
51 | 54 |
endfunction |
52 | 55 |
|
53 | 56 |
function! s:str2bufnr(buffer) |
54 | 57 |
if empty(a:buffer) |
55 | 58 |
return bufnr("%") |
56 |
- elseif a:buffer =~ '^\d\+$' |
|
59 |
+ elseif a:buffer =~# '^\d\+$' |
|
57 | 60 |
return bufnr(str2nr(a:buffer)) |
58 | 61 |
else |
59 | 62 |
return bufnr(a:buffer) |
... | ... |
@@ -74,11 +77,15 @@ function! s:new(bang) |
74 | 77 |
endfunction |
75 | 78 |
|
76 | 79 |
" Using the built-in :echoerr prints a stacktrace, which isn't that nice. |
77 |
-function! s:warn(msg) |
|
80 |
+function! s:error(msg) |
|
78 | 81 |
echohl ErrorMsg |
79 | 82 |
echomsg a:msg |
80 | 83 |
echohl NONE |
84 |
+ let v:errmsg = a:msg |
|
81 | 85 |
endfunction |
82 | 86 |
|
83 | 87 |
command! -bang -complete=buffer -nargs=? Bdelete |
84 |
- \ :call s:bdelete(<q-bang>, <q-args>) |
|
88 |
+ \ :call s:bdelete("bdelete", <q-bang>, <q-args>) |
|
89 |
+ |
|
90 |
+command! -bang -complete=buffer -nargs=? Bwipeout |
|
91 |
+ \ :call s:bdelete("bwipeout", <q-bang>, <q-args>) |
... | ... |
@@ -121,21 +121,20 @@ nmap <leader>p :set invpaste paste?<cr> |
121 | 121 |
" Control+p to paste onto next line |
122 | 122 |
nmap <C-p> :pu<cr> |
123 | 123 |
|
124 |
-" Make netrw's Lexplore behave like NERDTreeToggle |
|
124 |
+" Make netrw's Explore behave a little like NERDTreeToggle |
|
125 |
+" http://vimcasts.org/blog/2013/01/oil-and-vinegar-split-windows-and-project-drawer/ |
|
125 | 126 |
let g:NetrwIsOpen=0 |
126 | 127 |
function! ToggleNetrw() |
127 | 128 |
if g:NetrwIsOpen |
128 |
- let i = bufnr("$") |
|
129 |
- while (i >= 1) |
|
129 |
+ for i in range(1, bufnr("$")) |
|
130 | 130 |
if (getbufvar(i, "&filetype") == "netrw") |
131 |
- silent exe "bwipeout " . i |
|
131 |
+ silent exe "Bwipeout " . i |
|
132 | 132 |
endif |
133 |
- let i-=1 |
|
134 |
- endwhile |
|
133 |
+ endfor |
|
135 | 134 |
let g:NetrwIsOpen=0 |
136 | 135 |
else |
137 | 136 |
let g:NetrwIsOpen=1 |
138 |
- silent Lexplore %:p:h |
|
137 |
+ silent Explore %:p:h |
|
139 | 138 |
endif |
140 | 139 |
endfunction |
141 | 140 |
nmap <leader>e :call ToggleNetrw()<cr> |
142 | 141 |