Add plugin bbye
dblume

dblume commited on 2024-03-07 14:58:45
Showing 5 changed files, with 227 additions and 0 deletions.

... ...
@@ -0,0 +1,16 @@
1
+## 1.0.1 (Jul 23, 2013)
2
+- Fixes `:Bdelete`ing via buffer number. Finally, perfect!
3
+
4
+## 1.0.0 (Jul 23, 2013)
5
+- Hides the empty buffer from buffer explorers and tabbars.
6
+- Handles `:Bdelete!`ing buffers which are set to auto-delete via `&bufhidden`.
7
+- Wipes empty buffers after hiding to reduce the amount of unlisted buffers after using Bbye for a while.
8
+- Handles buffer explorers and tabbars better that remove or add windows mid-flight.
9
+- Improves an edge-case where the empty buffer might get listed and show up in buffer explorers.
10
+- Perfect for v1.0.0.
11
+
12
+## 0.9.1 (Jul 21, 2013)
13
+- Removes an innocent but forgotten debugging line. Now even more perfect.
14
+
15
+## 0.9.0 (Jul 21, 2013)
16
+- First release. It's perfect.
... ...
@@ -0,0 +1,20 @@
1
+Bbye
2
+Copyright (C) 2013 Andri Möll
3
+
4
+This program is free software: you can redistribute it and/or modify it under
5
+the terms of the GNU Affero General Public License as published by the Free
6
+Software Foundation, either version 3 of the License, or any later version.
7
+
8
+Additional permission under the GNU Affero GPL version 3 section 7:
9
+If you modify this Program, or any covered work, by linking or
10
+combining it with other code, such other code is not for that reason
11
+alone subject to any of the requirements of the GNU Affero GPL version 3.
12
+
13
+In summary:
14
+- You can use this program for no cost.
15
+- You can use this program for both personal and commercial reasons.
16
+- You do not have to share your own program's code which uses this program.
17
+- You have to share modifications (e.g bug-fixes) you've made to this program.
18
+
19
+For the full copy of the GNU Affero General Public License see:
20
+http://www.gnu.org/licenses.
... ...
@@ -0,0 +1,15 @@
1
+VERSION := 1.0.1
2
+
3
+love:
4
+	@echo "Feel like makin' love."
5
+
6
+pack:
7
+	zip -r "vim-bbye-$(VERSION).zip" * --exclude Makefile --exclude "*.zip"
8
+
9
+publish:
10
+	open "http://www.vim.org/scripts/add_script_version.php?script_id=4664"
11
+
12
+tag:
13
+	git tag "v$(VERSION)"
14
+	
15
+.PHONY: love pack publish tag
... ...
@@ -0,0 +1,85 @@
1
+Bbye (Buffer Bye) for Vim
2
+==========================
3
+Bbye allows you to do delete buffers (close files) without closing your windows or messing up your layout.
4
+
5
+Vim by default closes all windows that have the buffer (file) open when you do `:bdelete`.  If you've just got your splits and columns perfectly tuned, having them messed up equals a punch in the face and that's no way to tango.
6
+
7
+Bbye gives you a `:Bdelete` command that behaves like a well designed citizen:
8
+
9
+- Closes and removes the buffer.
10
+- Shows another file in that window.
11
+- Shows an empty file if you've got no other files open.
12
+- Does not leave useless `[no file]` buffers if you decide to edit another file in that window.
13
+- Works even if a file's open in multiple windows.
14
+- Works a-okay with various buffer explorers and tabbars.
15
+
16
+Regain your throne as king of buffers!
17
+
18
+
19
+Installing
20
+----------
21
+The easiest and most modular way is to download Bbye to `~/.vim/bundle`:
22
+```
23
+mkdir -p ~/.vim/bundle/bbye
24
+```
25
+
26
+Using Git:
27
+```
28
+git clone https://github.com/moll/vim-bbye.git ~/.vim/bundle/bbye
29
+```
30
+
31
+Using Wget:
32
+```
33
+wget https://github.com/moll/vim-bbye/archive/master.tar.gz -O- | tar -xf- --strip-components 1 -C ~/.vim/bundle/bbye
34
+```
35
+
36
+Then prepend that directory to Vim's `&runtimepath` (or use [Pathogen](https://github.com/tpope/vim-pathogen)):
37
+```
38
+set runtimepath^=~/.vim/bundle/bbye
39
+```
40
+
41
+
42
+Using
43
+-----
44
+Instead of using `:bdelete`, use `:Bdelete`.
45
+Fortunately autocomplete helps by sorting `:Bdelete` before its lowercase brother.
46
+
47
+As it's likely you'll be using `:Bdelete` often, make a shortcut to `\q`, for example, to save time. Throw this to your `vimrc`:
48
+```
49
+:nnoremap <Leader>q :Bdelete<CR>
50
+```
51
+
52
+### Closing all open buffers and files
53
+
54
+Occasionally you'll want to close all open buffers and files while leaving your pristine window setup as is. That's easy. Just do:
55
+```
56
+:bufdo :Bdelete
57
+```
58
+
59
+### Aliasing to :Bclose
60
+
61
+If you've used any `Bclose.vim` scripts before and for some reason need the `:Bclose` command to exist, you may make an alias:
62
+```
63
+command! -bang -complete=buffer -nargs=? Bclose Bdelete<bang> <args>
64
+```
65
+
66
+
67
+License
68
+-------
69
+Bbye is released under a *Lesser GNU Affero General Public License*, which in summary means:
70
+
71
+- You **can** use this program for **no cost**.
72
+- You **can** use this program for **both personal and commercial reasons**.
73
+- You **do not have to share your own program's code** which uses this program.
74
+- You **have to share modifications** (e.g bug-fixes) you've made to this program.
75
+
76
+For more convoluted language, see the `LICENSE` file.
77
+
78
+
79
+About
80
+-----
81
+**[Andri Möll](http://themoll.com)** authored this in SublemacslipseMate++.  
82
+[Monday Calendar](https://mondayapp.com) supported the engineering work.  
83
+Inspired by [Bclose.vim](http://vim.wikia.com/wiki/VimTip165), but rewritten to be perfect.
84
+
85
+If you find Bbye needs improving or you've got a question, please don't hesitate to email me anytime at andri@dot.ee or [create an issue online](https://github.com/moll/vim-bbye/issues).
... ...
@@ -0,0 +1,91 @@
1
+if exists("g:loaded_bbye") || &cp | finish | endif
2
+let g:loaded_bbye = 1
3
+
4
+function! s:bdelete(action, bang, buffer_name)
5
+	let buffer = s:str2bufnr(a:buffer_name)
6
+	let w:bbye_back = 1
7
+
8
+	if buffer < 0
9
+		return s:error("E516: No buffers were deleted. No match for ".a:buffer_name)
10
+	endif
11
+
12
+	if getbufvar(buffer, "&modified") && empty(a:bang)
13
+		let error = "E89: No write since last change for buffer "
14
+		return s:error(error . buffer . " (add ! to override)")
15
+	endif
16
+
17
+	" If the buffer is set to delete and it contains changes, we can't switch
18
+	" away from it. Hide it before eventual deleting:
19
+	if getbufvar(buffer, "&modified") && !empty(a:bang)
20
+		call setbufvar(buffer, "&bufhidden", "hide")
21
+	endif
22
+
23
+	" For cases where adding buffers causes new windows to appear or hiding some
24
+	" causes windows to disappear and thereby decrement, loop backwards.
25
+	for window in reverse(range(1, winnr("$")))
26
+		" For invalid window numbers, winbufnr returns -1.
27
+		if winbufnr(window) != buffer | continue | endif
28
+		execute window . "wincmd w"
29
+
30
+		" Bprevious also wraps around the buffer list, if necessary:
31
+		try | exe bufnr("#") > 0 && buflisted(bufnr("#")) ? "buffer #" : "bprevious"
32
+		catch /^Vim([^)]*):E85:/ " E85: There is no listed buffer
33
+		endtry
34
+
35
+		" If found a new buffer for this window, mission accomplished:
36
+		if bufnr("%") != buffer | continue | endif
37
+
38
+		call s:new(a:bang)
39
+	endfor
40
+
41
+	" Because tabbars and other appearing/disappearing windows change
42
+	" the window numbers, find where we were manually:
43
+	let back = filter(range(1, winnr("$")), "getwinvar(v:val, 'bbye_back')")[0]
44
+	if back | exe back . "wincmd w" | unlet w:bbye_back | endif
45
+
46
+	" If it hasn't been already deleted by &bufhidden, end its pains now.
47
+	" Unless it previously was an unnamed buffer and :enew returned it again.
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
53
+	endif
54
+endfunction
55
+
56
+function! s:str2bufnr(buffer)
57
+	if empty(a:buffer)
58
+		return bufnr("%")
59
+	elseif a:buffer =~# '^\d\+$'
60
+		return bufnr(str2nr(a:buffer))
61
+	else
62
+		return bufnr(a:buffer)
63
+	endif
64
+endfunction
65
+
66
+function! s:new(bang)
67
+	exe "enew" . a:bang
68
+
69
+	setl noswapfile
70
+	" If empty and out of sight, delete it right away:
71
+	setl bufhidden=wipe
72
+	" Regular buftype warns people if they have unsaved text there.  Wouldn't
73
+	" want to lose someone's data:
74
+	setl buftype=
75
+	" Hide the buffer from buffer explorers and tabbars:
76
+	setl nobuflisted
77
+endfunction
78
+
79
+" Using the built-in :echoerr prints a stacktrace, which isn't that nice.
80
+function! s:error(msg)
81
+	echohl ErrorMsg
82
+	echomsg a:msg
83
+	echohl NONE
84
+	let v:errmsg = a:msg
85
+endfunction
86
+
87
+command! -bang -complete=buffer -nargs=? Bdelete
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>)
0 92