Skip to content

Commit 94e4bb0

Browse files
authored
Merge branch 'master' into renovate/configure
2 parents 14b449f + 2253f97 commit 94e4bb0

3 files changed

Lines changed: 120 additions & 20 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
397397
<tr>
398398
<td align="center"><a href="https://github.com/mykoza"><img src="https://avatars1.githubusercontent.com/u/48719773?v=4?s=100" width="100px;" alt=""/><br /><sub><b>mykoza</b></sub></a><br /><a href="https://github.com/bullets-vim/bullets.vim/commits?author=mykoza" title="Code">💻</a> <a href="#ideas-mykoza" title="Ideas, Planning, & Feedback">🤔</a></td>
399399
<td align="center"><a href="https://github.com/noodlor"><img src="https://avatars3.githubusercontent.com/u/49209345?v=4?s=100" width="100px;" alt=""/><br /><sub><b>noodlor</b></sub></a><br /><a href="https://github.com/bullets-vim/bullets.vim/commits?author=noodlor" title="Code">💻</a></td>
400-
<td align="center"><a href="https://github.com/harshad1"><img src="https://avatars0.githubusercontent.com/u/1940940?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Harshad Srinivasan</b></sub></a><br /><a href="https://github.com/bullets-vim/bullets.vim/commits?author=harshad1" title="Code">💻</a> <a href="https://github.com/bullets-vim/bullets.vim/issues?q=author%3Aharshad1" title="Bug reports">🐛</a></td>
400+
<td align="center"><a href="https://github.com/harshad1"><img src="https://avatars0.githubusercontent.com/u/1940940?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Harshad Vedartham</b></sub></a><br /><a href="https://github.com/bullets-vim/bullets.vim/commits?author=harshad1" title="Code">💻</a> <a href="https://github.com/bullets-vim/bullets.vim/issues?q=author%3Aharshad1" title="Bug reports">🐛</a></td>
401401
<td align="center"><a href="https://erickchacon.github.io/"><img src="https://avatars2.githubusercontent.com/u/7862458?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Erick A. Chacón Montalván</b></sub></a><br /><a href="#ideas-ErickChacon" title="Ideas, Planning, & Feedback">🤔</a></td>
402402
<td align="center"><a href="https://samgriesemer.com"><img src="https://avatars.githubusercontent.com/u/19940657?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Sam Griesemer</b></sub></a><br /><a href="https://github.com/bullets-vim/bullets.vim/commits?author=samgriesemer" title="Code">💻</a> <a href="https://github.com/bullets-vim/bullets.vim/issues?q=author%3Asamgriesemer" title="Bug reports">🐛</a></td>
403403
<td align="center"><a href="https://codeberg.org/cpence"><img src="https://avatars.githubusercontent.com/u/297075?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Charles Pence</b></sub></a><br /><a href="https://github.com/bullets-vim/bullets.vim/commits?author=cpence" title="Code">💻</a></td>

plugin/bullets.vim

Lines changed: 84 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ end
6161
if !exists('g:bullets_max_alpha_characters')
6262
let g:bullets_max_alpha_characters = 2
6363
end
64+
65+
if !exists('g:bullets_enable_roman_list')
66+
let g:bullets_enable_roman_list = 1
67+
end
68+
6469
" calculate the decimal equivalent to the last alphabetical list item
6570
let s:power = g:bullets_max_alpha_characters
6671
let s:abc_max = -1
@@ -85,6 +90,10 @@ if !exists('g:bullets_nested_checkboxes')
8590
let g:bullets_nested_checkboxes = 1
8691
endif
8792

93+
if !exists('g:bullets_enable_wrapped_lines')
94+
let g:bullets_enable_wrapped_lines = 1
95+
end
96+
8897
if !exists('g:bullets_checkbox_markers')
8998
" The ordered series of markers to use in checkboxes
9099
" If only two markers are listed, they represent 'off' and 'on'
@@ -116,7 +125,48 @@ endif
116125
" ------------------------------------------------------ }}}
117126

118127
" Parse Bullet Type ------------------------------------------- {{{
128+
129+
" A caching mechanism for bullet
130+
" We add a crude 'reference count' for the cache so we can nest calls
131+
let s:bullet_cache = v:null
132+
let s:bullet_cache_depth = 0
133+
134+
fun! s:enable_bullet_cache()
135+
if s:bullet_cache_depth == 0
136+
let s:bullet_cache = {}
137+
endif
138+
let s:bullet_cache_depth += 1
139+
endfun
140+
141+
fun! s:disable_bullet_cache()
142+
if s:bullet_cache_depth == 1
143+
let s:bullet_cache = v:null
144+
endif
145+
146+
if s:bullet_cache_depth > 0
147+
let s:bullet_cache_depth -= 1
148+
endif
149+
endfun
150+
119151
fun! s:parse_bullet(line_num, line_text)
152+
let l:kinds = s:parse_bullet_text(a:line_text)
153+
154+
for l:data in l:kinds
155+
let l:data.starting_at_line_num = a:line_num
156+
endfor
157+
158+
return l:kinds
159+
endfun
160+
161+
fun! s:parse_bullet_text(line_text)
162+
163+
if s:bullet_cache isnot v:null
164+
let l:cached = get(s:bullet_cache, a:line_text, v:null)
165+
if l:cached isnot v:null
166+
" Return a copy so as not to break the referene
167+
return copy(l:cached)
168+
endif
169+
endif
120170

121171
let l:bullet = s:match_bullet_list_item(a:line_text)
122172
" Must be a bullet to be a checkbox
@@ -129,13 +179,12 @@ fun! s:parse_bullet(line_num, line_text)
129179
let l:roman = empty(l:bullet) && empty(l:num) ? s:match_roman_list_item(a:line_text) : {}
130180

131181
let l:kinds = s:filter([l:bullet, l:check, l:num, l:alpha, l:roman], '!empty(v:val)')
132-
133-
for l:data in l:kinds
134-
let l:data.starting_at_line_num = a:line_num
135-
endfor
136-
182+
183+
if s:bullet_cache isnot v:null
184+
let s:bullet_cache[a:line_text] = l:kinds
185+
endif
186+
137187
return l:kinds
138-
139188
endfun
140189

141190
fun! s:match_numeric_list_item(input_text)
@@ -166,6 +215,10 @@ endfun
166215

167216

168217
fun! s:match_roman_list_item(input_text)
218+
if g:bullets_enable_roman_list == 0
219+
return {}
220+
endif
221+
169222
let l:rom_bullet_regex = join([
170223
\ '\v\C',
171224
\ '^(',
@@ -362,17 +415,19 @@ fun! s:closest_bullet_types(from_line_num, max_indent)
362415
" Support for wrapped text bullets, even if the wrapped line is not indented
363416
" It considers a blank line as the end of a bullet
364417
" DEMO: https://raw.githubusercontent.com/dkarter/bullets.vim/master/img/wrapped-bullets.gif
365-
while l:lnum > 1 && (l:curr_indent != 0 || l:bullet_kinds != [] || !(l:ltxt =~# '\v^(\s+$|$)'))
366-
\ && (a:max_indent < l:curr_indent || l:bullet_kinds == [])
367-
if l:bullet_kinds != []
368-
let l:lnum = l:lnum - g:bullets_line_spacing
369-
else
370-
let l:lnum = l:lnum - 1
371-
endif
372-
let l:ltxt = getline(l:lnum)
373-
let l:bullet_kinds = s:parse_bullet(l:lnum, l:ltxt)
374-
let l:curr_indent = indent(l:lnum)
375-
endwhile
418+
if g:bullets_enable_wrapped_lines
419+
while l:lnum > 1 && (l:curr_indent != 0 || l:bullet_kinds != [] || !(l:ltxt =~# '\v^(\s+$|$)'))
420+
\ && (a:max_indent < l:curr_indent || l:bullet_kinds == [])
421+
if l:bullet_kinds != []
422+
let l:lnum = l:lnum - g:bullets_line_spacing
423+
else
424+
let l:lnum = l:lnum - 1
425+
endif
426+
let l:ltxt = getline(l:lnum)
427+
let l:bullet_kinds = s:parse_bullet(l:lnum, l:ltxt)
428+
let l:curr_indent = indent(l:lnum)
429+
endwhile
430+
endif
376431

377432
return l:bullet_kinds
378433
endfun
@@ -585,8 +640,14 @@ command! InsertNewBullet call <SID>insert_new_bullet()
585640
" Helper for Colon Indent
586641
" returns 1 if current line ends in a colon, else 0
587642
fun! s:line_ends_in_colon(lnum)
588-
let l:last_char_nr = strgetchar(getline(a:lnum), strcharlen(getline(a:lnum))-1)
589-
return l:last_char_nr == 65306 || l:last_char_nr == 58
643+
let l:line = getline(a:lnum)
644+
if exists("*strcharlen") && exists("*strgetchar")
645+
let l:last_char_nr = strgetchar(l:line, strcharlen(l:line)-1)
646+
return l:last_char_nr == 65306 || l:last_char_nr == 58
647+
else
648+
" Older versions of vim do not support strchar*
649+
return l:line[strlen(l:line)-1:] ==# ':'
650+
endif
590651
endfun
591652
" --------------------------------------------------------- }}}
592653

@@ -804,6 +865,7 @@ fun! s:renumber_selection()
804865
endfun
805866

806867
fun! s:renumber_lines(start, end)
868+
call s:enable_bullet_cache()
807869
let l:prev_indent = -1
808870
let l:levels = {} " stores all the info about the current outline/list
809871

@@ -881,15 +943,18 @@ fun! s:renumber_lines(start, end)
881943
endif
882944
endif
883945
endfor
946+
call s:disable_bullet_cache()
884947
endfun
885948

886949
" Renumbers the whole list containing the cursor.
887950
fun! s:renumber_whole_list()
951+
call s:enable_bullet_cache()
888952
let l:first_line = s:first_bullet_line(line('.'))
889953
let l:last_line = s:last_bullet_line(line('.'))
890954
if l:first_line > 0 && l:last_line > 0
891955
call s:renumber_lines(l:first_line, l:last_line)
892956
endif
957+
call s:disable_bullet_cache()
893958
endfun
894959

895960
command! -range=% RenumberSelection call <SID>renumber_selection()

spec/bullets_spec.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,41 @@
293293
-
294294
TEXT
295295
end
296+
297+
it 'toggles roman numeral bullets with g:bullets_enable_roman_list' do
298+
filename = "#{SecureRandom.hex(6)}.txt"
299+
write_file(filename, <<-TEXT)
300+
# Hello there
301+
i. this is the first bullet
302+
TEXT
303+
304+
# Disable alpha lists to isolate test to roman numerals
305+
vim.command 'let g:bullets_max_alpha_characters = 0'
306+
vim.command 'let g:bullets_enable_roman_list = 1'
307+
vim.edit filename
308+
vim.type 'GA'
309+
vim.feedkeys '\<cr>'
310+
vim.type 'second bullet'
311+
vim.feedkeys '\<cr>'
312+
vim.type 'third bullet'
313+
vim.command 'let g:bullets_enable_roman_list = 0'
314+
vim.feedkeys '\<cr>'
315+
vim.type 'fourth bullet'
316+
vim.feedkeys '\<cr>'
317+
vim.type 'fifth bullet'
318+
vim.write
319+
320+
file_contents = IO.read(filename)
321+
322+
expect(file_contents).to eq normalize_string_indent(<<-TEXT)
323+
# Hello there
324+
i. this is the first bullet
325+
ii. second bullet
326+
iii. third bullet
327+
fourth bullet
328+
fifth bullet\n
329+
TEXT
330+
end
296331
end
297332
end
298333
end

0 commit comments

Comments
 (0)