diff --git a/README.md b/README.md index 6645ad5..cd464c0 100644 --- a/README.md +++ b/README.md @@ -107,10 +107,34 @@ let g:bullets_custom_mappings = [ \ ] ``` -Enable/disable deleting the last empty bullet when hitting `` (insert mode) or `o` (normal mode): +Enable/disable deleting or promoting the last empty bullet when hitting `` (insert mode) or `o` (normal mode): ```vim -let g:bullets_delete_last_bullet_if_empty = 0 " default = 1 +" Example (| is cursor): +" - text +" - text +" - | + +let g:bullets_delete_last_bullet_if_empty = 1 " default = 1 +" - text +" - text +" | + +let g:bullets_delete_last_bullet_if_empty = 0 +" - text +" - text +" - +" | + +let g:bullets_delete_last_bullet_if_empty = 2 +" - text +" - text +" - | +" +" again: +" - text +" - text +" | ``` Line spacing between bullets (1 = no blank lines, 2 = one blank line, etc.): diff --git a/doc/bullets.txt b/doc/bullets.txt index c0b560f..3d7a1bc 100644 --- a/doc/bullets.txt +++ b/doc/bullets.txt @@ -148,7 +148,7 @@ To add a leader key to all mappings set the following: This will set the key as leader to all default mappings. -Disabling empty bullet deletion +Empty bullet deletion ------------------------------- By default bullets.vim will delete trailing empty bullets when the return key is pressed, just like modern word processors. @@ -157,6 +157,10 @@ If you would like to turn this feature off add the following to your .vimrc `let g:bullets_delete_last_bullet_if_empty = 0` +If you would like to promote bullet instead of deleting it, add the following to your .vimrc + + `let g:bullets_delete_last_bullet_if_empty = 2` + Maintain right padding on bullets --------------------------------- diff --git a/plugin/bullets.vim b/plugin/bullets.vim index 75a63f3..513d194 100644 --- a/plugin/bullets.vim +++ b/plugin/bullets.vim @@ -574,7 +574,11 @@ fun! s:insert_new_bullet() " We don't want to create a new bullet if the previous one was not used, " instead we want to delete the empty bullet - like word processors do if g:bullets_delete_last_bullet_if_empty - call setline(l:curr_line_num, '') + if g:bullets_delete_last_bullet_if_empty == 1 + call setline(l:curr_line_num, '') + elseif g:bullets_delete_last_bullet_if_empty == 2 + call change_bullet_level(1, 0) + endif let l:send_return = 0 endif elseif !(l:bullet.bullet_type ==# 'abc' && s:abc2dec(l:bullet.bullet) + 1 > s:abc_max) diff --git a/spec/bullets_spec.rb b/spec/bullets_spec.rb index 9d91c12..cf370f0 100644 --- a/spec/bullets_spec.rb +++ b/spec/bullets_spec.rb @@ -271,6 +271,31 @@ TEXT end + it 'promote the last bullet when configured to' do + filename = "#{SecureRandom.hex(6)}.txt" + write_file(filename, <<-TEXT) + # Hello there + - this is the first bullet + - this is the second bullet + TEXT + + vim.command 'let g:bullets_delete_last_bullet_if_empty = 2' + vim.edit filename + vim.type 'GA' + vim.feedkeys '\' + vim.feedkeys '\' + vim.write + + file_contents = IO.read(filename) + + expect(file_contents.strip).to eq normalize_string_indent(<<-TEXT) + # Hello there + - this is the first bullet + - this is the second bullet + - + TEXT + end + it 'does not delete the last bullet when configured not to' do filename = "#{SecureRandom.hex(6)}.txt" write_file(filename, <<-TEXT)