Skip to content

Commit

Permalink
Merge branch 'master' into selectbullet
Browse files Browse the repository at this point in the history
  • Loading branch information
kaymmm authored Oct 8, 2022
2 parents 617a248 + bb2b9f3 commit 8acb181
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 8 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ group :test do
gem 'pry-byebug'
gem 'rake', '~> 12.3.3'
gem 'rspec'
gem 'rspec-retry'
gem 'vimrunner'
end
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ GEM
rspec-mocks (3.8.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-retry (0.6.2)
rspec-core (> 3.3)
rspec-support (3.8.0)
vimrunner (0.3.4)

Expand All @@ -35,6 +37,7 @@ DEPENDENCIES
pry-byebug
rake (~> 12.3.3)
rspec
rspec-retry
vimrunner

BUNDLED WITH
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@ let g:bullets_pad_right = 0
" ^ no extra space between bullet and text
```

Indent new bullets when the previous bullet ends with a colon:

```vim
let g:bullets_auto_indent_after_colon = 1 " default = 1
" a. text
" b. text:
" i. text
```

Maximum number of alphabetic characters to use for bullets:

```vim
Expand Down
41 changes: 33 additions & 8 deletions plugin/bullets.vim
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ if !exists('g:bullets_checkbox_partials_toggle')
let g:bullets_checkbox_partials_toggle = 1
endif

if !exists('g:bullets_auto_indent_after_colon')
" Should a line ending in a colon result in the next line being indented (1)?
let g:bullets_auto_indent_after_colon = 1
endif

" ------------------------------------------------------ }}}

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

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

" insert next bullet
call append(l:curr_line_num, l:next_bullet_list)
" got to next line after the new bullet


" go to next line after the new bullet
let l:col = strlen(getline(l:next_line_num)) + 1
if g:bullets_renumber_on_change
call setpos('.', [0, l:next_line_num, l:col])

" indent if previous line ended in a colon
if l:indent_next
" demote the new bullet
call s:change_bullet_level_and_renumber(-1)
" reset cursor position after indenting
let l:col = strlen(getline(l:next_line_num)) + 1
call setpos('.', [0, l:next_line_num, l:col])
elseif g:bullets_renumber_on_change
call s:renumber_whole_list()
endif
call setpos('.', [0, l:next_line_num, l:col])

let l:send_return = 0
endif
endif
Expand All @@ -514,6 +531,14 @@ fun! s:is_at_eol()
endfun

command! InsertNewBullet call <SID>insert_new_bullet()

" Helper for Colon Indent
" returns 1 if current line ends in a colon, else 0
fun! s:line_ends_in_colon(lnum)
return getline(a:lnum)[strlen(getline(a:lnum))-1:] ==# ':'
endfun
" --------------------------------------------------------- }}}

" --------------------------------------------------------- }}}

" Checkboxes ---------------------------------------------- {{{
Expand Down Expand Up @@ -945,11 +970,11 @@ fun! s:change_bullet_level(direction)
endfun

fun! s:change_bullet_level_and_renumber(direction)
" Calls change_bullet_level and then renumber_whole_list if required
call s:change_bullet_level(a:direction)
if g:bullets_renumber_on_change
call s:renumber_whole_list()
endif
" Calls change_bullet_level and then renumber_whole_list if required
call s:change_bullet_level(a:direction)
if g:bullets_renumber_on_change
call s:renumber_whole_list()
endif
endfun

fun! s:visual_change_bullet_level(direction)
Expand Down
29 changes: 29 additions & 0 deletions spec/nested_bullets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -565,5 +565,34 @@
TEXT
end

it 'indents after a line ending in a colon' do
filename = "#{SecureRandom.hex(6)}.txt"
write_file(filename, <<-TEXT)
# Hello there
a. this is the first bullet
TEXT

vim.command 'let g:bullets_auto_indent_after_colon = 1'
vim.edit filename
vim.type 'GA'
vim.feedkeys '\<cr>'
vim.type 'this is the second bullet:'
vim.feedkeys '\<cr>'
vim.type 'this bullet is indented'
vim.feedkeys '\<cr>'
vim.type 'this bullet is also indented'
vim.write

file_contents = IO.read(filename)

expect(file_contents.strip).to eq normalize_string_indent(<<-TEXT)
# Hello there
a. this is the first bullet
b. this is the second bullet:
\ti. this bullet is indented
\tii. this bullet is also indented
TEXT
end
end
end
16 changes: 16 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'vimrunner'
require 'vimrunner/rspec'
require 'securerandom'
require 'rspec/retry'

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

RSpec.configure do |config|

# RSpec Retry
# ===========
# show retry status in spec process
config.verbose_retry = true

# show exception that triggers a retry if verbose_retry is set to true
config.display_try_failure_messages = true

# retry each spec 3 times
config.around :each do |ex|
ex.run_with_retry retry: 3
end
# ============

config.around do |example|
Dir.mktmpdir do |dir|
Dir.chdir(dir) do
Expand Down

0 comments on commit 8acb181

Please sign in to comment.