diff --git a/doc/bullets.txt b/doc/bullets.txt index 14453d6..e70ec7e 100644 --- a/doc/bullets.txt +++ b/doc/bullets.txt @@ -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 @@ -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 @@ -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 diff --git a/plugin/bullets.vim b/plugin/bullets.vim index 93ca133..49bdba0 100644 --- a/plugin/bullets.vim +++ b/plugin/bullets.vim @@ -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 @@ -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), diff --git a/spec/alphabetic_bullets_spec.rb b/spec/alphabetic_bullets_spec.rb new file mode 100644 index 0000000..e7c227f --- /dev/null +++ b/spec/alphabetic_bullets_spec.rb @@ -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 '\' + vim.type 'second bullet' + vim.feedkeys '\' + vim.type 'third bullet' + vim.feedkeys '\' + vim.type 'fourth bullet' + vim.feedkeys '\' + 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 '\' + vim.type 'second bullet' + vim.feedkeys '\' + vim.type 'third bullet' + vim.feedkeys '\' + vim.type 'fourth bullet' + vim.feedkeys '\' + 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 '\' + vim.type 'second bullet' + vim.feedkeys '\' + vim.type 'third bullet' + vim.feedkeys '\' + vim.feedkeys '\' + vim.type 'AY. fourth bullet' + vim.feedkeys '\' + vim.type 'fifth bullet' + vim.feedkeys '\' + 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 '\' + vim.type 'second bullet' + vim.feedkeys '\' + 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 '\' + 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 diff --git a/spec/bullets_spec.rb b/spec/bullets_spec.rb index e9b2c1f..84b79db 100644 --- a/spec/bullets_spec.rb +++ b/spec/bullets_spec.rb @@ -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 '\' - vim.type 'second bullet' - vim.feedkeys '\' - vim.type 'third bullet' - vim.feedkeys '\' - vim.type 'fourth bullet' - vim.feedkeys '\' - 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 '\' - vim.type 'second bullet' - vim.feedkeys '\' - vim.type 'third bullet' - vim.feedkeys '\' - vim.type 'fourth bullet' - vim.feedkeys '\' - 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 '\' - vim.type 'second bullet' - vim.feedkeys '\' - vim.type 'third bullet' - vim.feedkeys '\' - vim.feedkeys '\' - vim.type 'AY. fourth bullet' - vim.feedkeys '\' - vim.type 'fifth bullet' - vim.feedkeys '\' - 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 '\' - vim.type 'second bullet' - vim.feedkeys '\' - 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)