Skip to content

Commit 40bafe6

Browse files
committed
feat: bullets_process_last_bullet_if_empty
Support promotion instead of deletion
1 parent 8f3259e commit 40bafe6

File tree

4 files changed

+56
-9
lines changed

4 files changed

+56
-9
lines changed

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,24 @@ let g:bullets_custom_mappings = [
107107
\ ]
108108
```
109109

110-
Enable/disable deleting the last empty bullet when hitting `<cr>` (insert mode) or `o` (normal mode):
110+
Enable/disable deleting or promoting the last empty bullet when hitting `<cr>` (insert mode) or `o` (normal mode):
111111

112112
```vim
113-
let g:bullets_delete_last_bullet_if_empty = 0 " default = 1
113+
let g:bullets_process_last_bullet_if_empty = 0 " default = 1
114+
" - text
115+
" - text
116+
" -
117+
" -
118+
119+
let g:bullets_process_last_bullet_if_empty = 1
120+
" - text
121+
" - text
122+
"
123+
124+
let g:bullets_process_last_bullet_if_empty = 2
125+
" - text
126+
" - text
127+
" -
114128
```
115129

116130
Line spacing between bullets (1 = no blank lines, 2 = one blank line, etc.):

doc/bullets.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,18 @@ To add a leader key to all mappings set the following:
148148
This will set the <space> key as leader to all default mappings.
149149

150150

151-
Disabling empty bullet deletion
151+
Empty bullet processing
152152
-------------------------------
153153
By default bullets.vim will delete trailing empty bullets when the return key
154154
is pressed, just like modern word processors.
155155

156156
If you would like to turn this feature off add the following to your .vimrc
157157

158-
`let g:bullets_delete_last_bullet_if_empty = 0`
158+
`let g:bullets_process_last_bullet_if_empty = 0`
159+
160+
If you would like to promote bullet instead of deleting it, add the following to your .vimrc
161+
162+
`let g:bullets_process_last_bullet_if_empty = 2`
159163

160164

161165
Maintain right padding on bullets

plugin/bullets.vim

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ if !exists('g:bullets_custom_mappings')
4444
let g:bullets_custom_mappings = []
4545
endif
4646

47-
if !exists('g:bullets_delete_last_bullet_if_empty')
48-
let g:bullets_delete_last_bullet_if_empty = 1
47+
if !exists('g:bullets_process_last_bullet_if_empty')
48+
let g:bullets_process_last_bullet_if_empty = 1
4949
end
5050

5151
if !exists('g:bullets_line_spacing')
@@ -573,8 +573,12 @@ fun! s:insert_new_bullet()
573573
if l:bullet.text_after_bullet ==# ''
574574
" We don't want to create a new bullet if the previous one was not used,
575575
" instead we want to delete the empty bullet - like word processors do
576-
if g:bullets_delete_last_bullet_if_empty
577-
call setline(l:curr_line_num, '')
576+
if g:bullets_process_last_bullet_if_empty
577+
if g:bullets_process_last_bullet_if_empty == 1
578+
call setline(l:curr_line_num, '')
579+
elseif g:bullets_process_last_bullet_if_empty == 2
580+
call <SID>change_bullet_level(1, 0)
581+
endif
578582
let l:send_return = 0
579583
endif
580584
elseif !(l:bullet.bullet_type ==# 'abc' && s:abc2dec(l:bullet.bullet) + 1 > s:abc_max)

spec/bullets_spec.rb

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,39 @@
271271
TEXT
272272
end
273273

274+
it 'promote the last bullet when configured to' do
275+
filename = "#{SecureRandom.hex(6)}.txt"
276+
write_file(filename, <<-TEXT)
277+
# Hello there
278+
- this is the first bullet
279+
- this is the second bullet
280+
TEXT
281+
282+
vim.command 'let g:bullets_process_last_bullet_if_empty = 2'
283+
vim.edit filename
284+
vim.type 'GA'
285+
vim.feedkeys '\<cr>'
286+
vim.feedkeys '\<cr>'
287+
vim.write
288+
289+
file_contents = IO.read(filename)
290+
291+
expect(file_contents.strip).to eq normalize_string_indent(<<-TEXT)
292+
# Hello there
293+
- this is the first bullet
294+
- this is the second bullet
295+
-
296+
TEXT
297+
end
298+
274299
it 'does not delete the last bullet when configured not to' do
275300
filename = "#{SecureRandom.hex(6)}.txt"
276301
write_file(filename, <<-TEXT)
277302
# Hello there
278303
- this is the first bullet
279304
TEXT
280305

281-
vim.command 'let g:bullets_delete_last_bullet_if_empty = 0'
306+
vim.command 'let g:bullets_process_last_bullet_if_empty = 0'
282307
vim.edit filename
283308
vim.type 'GA'
284309
vim.feedkeys '\<cr>'

0 commit comments

Comments
 (0)