Skip to content

Commit

Permalink
Merge pull request #49 from dkarter/minor-changes-to-alphabetic-bullets
Browse files Browse the repository at this point in the history
Minor changes to alphabetic bullets
  • Loading branch information
dkarter committed Feb 23, 2020
2 parents 5454d92 + afbe9d8 commit e0b1f8f
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 125 deletions.
16 changes: 15 additions & 1 deletion doc/bullets.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ types:
- [ ] GFM markdown checkbox lists
1. Numeric lists
2) or this style of numeric lists
a. alphabetic lists
B) or this style of alphabetic
\item latex item lists
**** Org mode headers

Expand All @@ -38,7 +40,6 @@ It also provides support for wrapped text in a bullet, allowing you to use the

Future versions aim to support the following:

a. Alphabetic lists
]] User defined bullets


Expand Down Expand Up @@ -151,6 +152,19 @@ This tends to be fine even if you don't use it, but it can be disabled with:
`let g:bullets_pad_right = 0`


Alphabetic Bullet Max Size
--------------------------
To avoid falsely detecting a word as an alphabetic bullet we have limited the
max size of an alphabetic bullets to `2` characters using the following setting:

`let g:bullets_max_alpha_characters = 2`

You can change this setting in certain file types if you are not worried about
that using auto commands.

When changed to `0` this will disable alphabetic bullets altogether.


INSERTING BULLETS *bullets-insert-new-bullet*

When a supported file type is opened (see |bullets-configuration|) you can start
Expand Down
6 changes: 5 additions & 1 deletion plugin/bullets.vim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
" Vim plugin for automated bulleted lists
" Last Change: February 03, 2020
" Last Change: February 23, 2020
" Maintainer: Dorian Karter
" License: MIT
" FileTypes: markdown, text, gitcommit
Expand Down Expand Up @@ -122,6 +122,10 @@ fun! s:match_roman_list_item(input_text)
endfun

fun! s:match_alphabetical_list_item(input_text)
if g:bullets_max_alpha_characters == 0
return {}
endif

let l:abc_bullet_regex = join([
\ '\v^((\s*)(\u{1,',
\ string(g:bullets_max_alpha_characters),
Expand Down
155 changes: 155 additions & 0 deletions spec/alphabetic_bullets_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Bullets.vim' do
describe 'alphabetic bullets' do
it 'adds a new upper case bullet' do
filename = "#{SecureRandom.hex(6)}.txt"
write_file(filename, <<-TEXT)
# Hello there
A. this is the first bullet
TEXT

vim.edit filename
vim.type 'GA'
vim.feedkeys '\<cr>'
vim.type 'second bullet'
vim.feedkeys '\<cr>'
vim.type 'third bullet'
vim.feedkeys '\<cr>'
vim.type 'fourth bullet'
vim.feedkeys '\<cr>'
vim.type 'fifth bullet'
vim.write

file_contents = IO.read(filename)

expect(file_contents).to eq normalize_string_indent(<<-TEXT)
# Hello there
A. this is the first bullet
B. second bullet
C. third bullet
D. fourth bullet
E. fifth bullet\n
TEXT
end

it 'adds a new lower case bullet' do
filename = "#{SecureRandom.hex(6)}.txt"
write_file(filename, <<-TEXT)
# Hello there
a. this is the first bullet
TEXT

vim.edit filename
vim.type 'GA'
vim.feedkeys '\<cr>'
vim.type 'second bullet'
vim.feedkeys '\<cr>'
vim.type 'third bullet'
vim.feedkeys '\<cr>'
vim.type 'fourth bullet'
vim.feedkeys '\<cr>'
vim.type 'fifth bullet'
vim.write

file_contents = IO.read(filename)

expect(file_contents).to eq normalize_string_indent(<<-TEXT)
# Hello there
a. this is the first bullet
b. second bullet
c. third bullet
d. fourth bullet
e. fifth bullet\n
TEXT
end

it 'adds a new bullet and loops at z' do
filename = "#{SecureRandom.hex(6)}.txt"
write_file(filename, <<-TEXT)
# Hello there
y. this is the first bullet
TEXT

vim.edit filename
vim.type 'GA'
vim.feedkeys '\<cr>'
vim.type 'second bullet'
vim.feedkeys '\<cr>'
vim.type 'third bullet'
vim.feedkeys '\<cr>'
vim.feedkeys '\<cr>'
vim.type 'AY. fourth bullet'
vim.feedkeys '\<cr>'
vim.type 'fifth bullet'
vim.feedkeys '\<cr>'
vim.type 'sixth bullet'
vim.write

file_contents = IO.read(filename)

expect(file_contents).to eq normalize_string_indent(<<-TEXT)
# Hello there
y. this is the first bullet
z. second bullet
aa. third bullet
AY. fourth bullet
AZ. fifth bullet
BA. sixth bullet\n
TEXT
end

describe 'g:bullets_max_alpha_characters' do
it 'stops adding items after configured max (default 2)' do
filename = "#{SecureRandom.hex(6)}.txt"
write_file(filename, <<-TEXT)
# Hello there
zy. this is the first bullet
TEXT

vim.edit filename
vim.type 'GA'
vim.feedkeys '\<cr>'
vim.type 'second bullet'
vim.feedkeys '\<cr>'
vim.type 'not a bullet'
vim.write

file_contents = IO.read(filename)

expect(file_contents).to eq normalize_string_indent(<<-TEXT)
# Hello there
zy. this is the first bullet
zz. second bullet
not a bullet\n
TEXT
end

it 'does not bullets if configured as 0' do
filename = "#{SecureRandom.hex(6)}.txt"
write_file(filename, <<-TEXT)
# Hello there
a. this is the first bullet
TEXT

vim.command 'let g:bullets_max_alpha_characters = 0'
vim.edit filename
vim.type 'GA'
vim.feedkeys '\<cr>'
vim.type 'not a bullet'
vim.write

file_contents = IO.read(filename)

expect(file_contents).to eq normalize_string_indent(<<-TEXT)
# Hello there
a. this is the first bullet
not a bullet\n
TEXT
end
end
end
end
123 changes: 0 additions & 123 deletions spec/bullets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -249,129 +249,6 @@
TEXT
end

it 'adds a new alphabetical list bullet' do
filename = "#{SecureRandom.hex(6)}.txt"
write_file(filename, <<-TEXT)
# Hello there
A. this is the first bullet
TEXT

vim.edit filename
vim.type 'GA'
vim.feedkeys '\<cr>'
vim.type 'second bullet'
vim.feedkeys '\<cr>'
vim.type 'third bullet'
vim.feedkeys '\<cr>'
vim.type 'fourth bullet'
vim.feedkeys '\<cr>'
vim.type 'fifth bullet'
vim.write

file_contents = IO.read(filename)

expect(file_contents).to eq normalize_string_indent(<<-TEXT)
# Hello there
A. this is the first bullet
B. second bullet
C. third bullet
D. fourth bullet
E. fifth bullet\n
TEXT
end

it 'adds a new lower case alphabetical list bullet' do
filename = "#{SecureRandom.hex(6)}.txt"
write_file(filename, <<-TEXT)
# Hello there
a. this is the first bullet
TEXT

vim.edit filename
vim.type 'GA'
vim.feedkeys '\<cr>'
vim.type 'second bullet'
vim.feedkeys '\<cr>'
vim.type 'third bullet'
vim.feedkeys '\<cr>'
vim.type 'fourth bullet'
vim.feedkeys '\<cr>'
vim.type 'fifth bullet'
vim.write

file_contents = IO.read(filename)

expect(file_contents).to eq normalize_string_indent(<<-TEXT)
# Hello there
a. this is the first bullet
b. second bullet
c. third bullet
d. fourth bullet
e. fifth bullet\n
TEXT
end

it 'adds a new alphabetical list bullet and loops at z' do
filename = "#{SecureRandom.hex(6)}.txt"
write_file(filename, <<-TEXT)
# Hello there
y. this is the first bullet
TEXT

vim.edit filename
vim.type 'GA'
vim.feedkeys '\<cr>'
vim.type 'second bullet'
vim.feedkeys '\<cr>'
vim.type 'third bullet'
vim.feedkeys '\<cr>'
vim.feedkeys '\<cr>'
vim.type 'AY. fourth bullet'
vim.feedkeys '\<cr>'
vim.type 'fifth bullet'
vim.feedkeys '\<cr>'
vim.type 'sixth bullet'
vim.write

file_contents = IO.read(filename)

expect(file_contents).to eq normalize_string_indent(<<-TEXT)
# Hello there
y. this is the first bullet
z. second bullet
aa. third bullet
AY. fourth bullet
AZ. fifth bullet
BA. sixth bullet\n
TEXT
end

it 'stops adding more alphabetical items after g:bullets_max_alpha_characters (2)' do
filename = "#{SecureRandom.hex(6)}.txt"
write_file(filename, <<-TEXT)
# Hello there
zy. this is the first bullet
TEXT

vim.edit filename
vim.type 'GA'
vim.feedkeys '\<cr>'
vim.type 'second bullet'
vim.feedkeys '\<cr>'
vim.type 'not a bullet'
vim.write

file_contents = IO.read(filename)

expect(file_contents).to eq normalize_string_indent(<<-TEXT)
# Hello there
zy. this is the first bullet
zz. second bullet
not a bullet\n
TEXT
end

it 'deletes the last bullet if it is empty' do
filename = "#{SecureRandom.hex(6)}.txt"
write_file(filename, <<-TEXT)
Expand Down

0 comments on commit e0b1f8f

Please sign in to comment.