Skip to content

Commit 8acb181

Browse files
authored
Merge branch 'master' into selectbullet
2 parents 617a248 + bb2b9f3 commit 8acb181

6 files changed

Lines changed: 91 additions & 8 deletions

File tree

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ group :test do
77
gem 'pry-byebug'
88
gem 'rake', '~> 12.3.3'
99
gem 'rspec'
10+
gem 'rspec-retry'
1011
gem 'vimrunner'
1112
end

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ GEM
2424
rspec-mocks (3.8.0)
2525
diff-lcs (>= 1.2.0, < 2.0)
2626
rspec-support (~> 3.8.0)
27+
rspec-retry (0.6.2)
28+
rspec-core (> 3.3)
2729
rspec-support (3.8.0)
2830
vimrunner (0.3.4)
2931

@@ -35,6 +37,7 @@ DEPENDENCIES
3537
pry-byebug
3638
rake (~> 12.3.3)
3739
rspec
40+
rspec-retry
3841
vimrunner
3942

4043
BUNDLED WITH

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,15 @@ let g:bullets_pad_right = 0
140140
" ^ no extra space between bullet and text
141141
```
142142

143+
Indent new bullets when the previous bullet ends with a colon:
144+
145+
```vim
146+
let g:bullets_auto_indent_after_colon = 1 " default = 1
147+
" a. text
148+
" b. text:
149+
" i. text
150+
```
151+
143152
Maximum number of alphabetic characters to use for bullets:
144153

145154
```vim

plugin/bullets.vim

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ if !exists('g:bullets_checkbox_partials_toggle')
108108
let g:bullets_checkbox_partials_toggle = 1
109109
endif
110110

111+
if !exists('g:bullets_auto_indent_after_colon')
112+
" Should a line ending in a colon result in the next line being indented (1)?
113+
let g:bullets_auto_indent_after_colon = 1
114+
endif
115+
111116
" ------------------------------------------------------ }}}
112117

113118
" Parse Bullet Type ------------------------------------------- {{{
@@ -456,6 +461,7 @@ fun! s:insert_new_bullet()
456461
" searching up from there
457462
let l:send_return = 1
458463
let l:normal_mode = mode() ==# 'n'
464+
let l:indent_next = s:line_ends_in_colon(l:curr_line_num) && g:bullets_auto_indent_after_colon
459465

460466
" check if current line is a bullet and we are at the end of the line (for
461467
" insert mode only)
@@ -485,12 +491,23 @@ fun! s:insert_new_bullet()
485491

486492
" insert next bullet
487493
call append(l:curr_line_num, l:next_bullet_list)
488-
" got to next line after the new bullet
494+
495+
496+
" go to next line after the new bullet
489497
let l:col = strlen(getline(l:next_line_num)) + 1
490-
if g:bullets_renumber_on_change
498+
call setpos('.', [0, l:next_line_num, l:col])
499+
500+
" indent if previous line ended in a colon
501+
if l:indent_next
502+
" demote the new bullet
503+
call s:change_bullet_level_and_renumber(-1)
504+
" reset cursor position after indenting
505+
let l:col = strlen(getline(l:next_line_num)) + 1
506+
call setpos('.', [0, l:next_line_num, l:col])
507+
elseif g:bullets_renumber_on_change
491508
call s:renumber_whole_list()
492509
endif
493-
call setpos('.', [0, l:next_line_num, l:col])
510+
494511
let l:send_return = 0
495512
endif
496513
endif
@@ -514,6 +531,14 @@ fun! s:is_at_eol()
514531
endfun
515532

516533
command! InsertNewBullet call <SID>insert_new_bullet()
534+
535+
" Helper for Colon Indent
536+
" returns 1 if current line ends in a colon, else 0
537+
fun! s:line_ends_in_colon(lnum)
538+
return getline(a:lnum)[strlen(getline(a:lnum))-1:] ==# ':'
539+
endfun
540+
" --------------------------------------------------------- }}}
541+
517542
" --------------------------------------------------------- }}}
518543

519544
" Checkboxes ---------------------------------------------- {{{
@@ -945,11 +970,11 @@ fun! s:change_bullet_level(direction)
945970
endfun
946971

947972
fun! s:change_bullet_level_and_renumber(direction)
948-
" Calls change_bullet_level and then renumber_whole_list if required
949-
call s:change_bullet_level(a:direction)
950-
if g:bullets_renumber_on_change
951-
call s:renumber_whole_list()
952-
endif
973+
" Calls change_bullet_level and then renumber_whole_list if required
974+
call s:change_bullet_level(a:direction)
975+
if g:bullets_renumber_on_change
976+
call s:renumber_whole_list()
977+
endif
953978
endfun
954979

955980
fun! s:visual_change_bullet_level(direction)

spec/nested_bullets_spec.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,5 +565,34 @@
565565
566566
TEXT
567567
end
568+
569+
it 'indents after a line ending in a colon' do
570+
filename = "#{SecureRandom.hex(6)}.txt"
571+
write_file(filename, <<-TEXT)
572+
# Hello there
573+
a. this is the first bullet
574+
TEXT
575+
576+
vim.command 'let g:bullets_auto_indent_after_colon = 1'
577+
vim.edit filename
578+
vim.type 'GA'
579+
vim.feedkeys '\<cr>'
580+
vim.type 'this is the second bullet:'
581+
vim.feedkeys '\<cr>'
582+
vim.type 'this bullet is indented'
583+
vim.feedkeys '\<cr>'
584+
vim.type 'this bullet is also indented'
585+
vim.write
586+
587+
file_contents = IO.read(filename)
588+
589+
expect(file_contents.strip).to eq normalize_string_indent(<<-TEXT)
590+
# Hello there
591+
a. this is the first bullet
592+
b. this is the second bullet:
593+
\ti. this bullet is indented
594+
\tii. this bullet is also indented
595+
TEXT
596+
end
568597
end
569598
end

spec/spec_helper.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require 'vimrunner'
44
require 'vimrunner/rspec'
55
require 'securerandom'
6+
require 'rspec/retry'
67

78
Vimrunner::RSpec.configure do |config|
89
# Use a single Vim instance for the test suite. Set to false to use an
@@ -27,6 +28,21 @@
2728
end
2829

2930
RSpec.configure do |config|
31+
32+
# RSpec Retry
33+
# ===========
34+
# show retry status in spec process
35+
config.verbose_retry = true
36+
37+
# show exception that triggers a retry if verbose_retry is set to true
38+
config.display_try_failure_messages = true
39+
40+
# retry each spec 3 times
41+
config.around :each do |ex|
42+
ex.run_with_retry retry: 3
43+
end
44+
# ============
45+
3046
config.around do |example|
3147
Dir.mktmpdir do |dir|
3248
Dir.chdir(dir) do

0 commit comments

Comments
 (0)