@@ -10,9 +10,9 @@ set cpoptions&vim
1010" ------------------------------------------------------- }}}
1111
1212" Prevent execution if already loaded ------------------ {{{
13- if exists (' g:loaded_bullets_vim' )
14- finish
15- endif
13+ " if exists('g:loaded_bullets_vim')
14+ " finish
15+ " endif
1616let g: loaded_bullets_vim = 1
1717" Prevent execution if already loaded ------------------ }}}
1818
@@ -186,7 +186,7 @@ fun! s:match_alphabetical_list_item(input_text)
186186endfun
187187
188188fun ! s: match_checkbox_bullet_item (input_text)
189- let l: checkbox_bullet_regex = ' \v(^(\s*)- \[[x ]?\](\s+))(.*)'
189+ let l: checkbox_bullet_regex = ' \v(^(\s*)( - \[[x ]?\]) (\s+))(.*)'
190190 let l: matches = matchlist (a: input_text , l: checkbox_bullet_regex )
191191
192192 if empty (l: matches )
@@ -195,13 +195,16 @@ fun! s:match_checkbox_bullet_item(input_text)
195195
196196 let l: bullet_length = strlen (l: matches [1 ])
197197 let l: leading_space = l: matches [2 ]
198- let l: trailing_space = l: matches [3 ]
199- let l: text_after_bullet = l: matches [4 ]
198+ let l: bullet = l: matches [3 ]
199+ let l: trailing_space = l: matches [4 ]
200+ let l: text_after_bullet = l: matches [5 ]
200201
201202 return {
202203 \ ' bullet_type' : ' chk' ,
203204 \ ' bullet_length' : l: bullet_length ,
204205 \ ' leading_space' : l: leading_space ,
206+ \ ' bullet' : l: bullet ,
207+ \ ' closure' : ' ' ,
205208 \ ' trailing_space' : l: trailing_space ,
206209 \ ' text_after_bullet' : l: text_after_bullet
207210 \ }
@@ -421,6 +424,9 @@ fun! s:insert_new_bullet()
421424 call append (l: curr_line_num , l: next_bullet_list )
422425 " got to next line after the new bullet
423426 let l: col = strlen (getline (l: next_line_num )) + 1
427+ if g: bullets_renumber_on_change
428+ call s: renumber_whole_list ()
429+ endif
424430 call setpos (' .' , [0 , l: next_line_num , l: col ])
425431 let l: send_return = 0
426432 endif
@@ -575,6 +581,11 @@ fun! s:renumber_selection()
575581 let l: indent = indent (l: line .nr)
576582 let l: bullet = s: closest_bullet_types (l: line .nr, l: indent )
577583 let l: bullet = s: resolve_bullet_type (l: bullet )
584+ let l: curr_level = s: get_level (l: bullet )
585+ if l: curr_level > 1
586+ " then it's an AsciiDoc list and shouldn't be renumbered
587+ break
588+ endif
578589
579590 if ! empty (l: bullet ) && l: bullet .starting_at_line_num == l: line .nr
580591 " skip wrapped lines and lines that aren't bullets
@@ -619,9 +630,12 @@ fun! s:renumber_selection()
619630 let l: bullet_num = s: dec2abc (l: levels [l: indent ].index , l: levels [l: indent ].islower)
620631 elseif l: levels [l: indent ].type == # ' num'
621632 let l: bullet_num = l: levels [l: indent ].index
622- else
623- " standard or checkbox
633+ elseif l: levels [ l: indent ]. type == # ' std '
634+ " normalize standard bullets
624635 let l: bullet_num = l: levels [l: indent ].bullet
636+ else
637+ " checkboxes shouldn't change their checked status
638+ let l: bullet_num = l: bullet .bullet
625639 endif
626640
627641 let l: new_bullet =
@@ -921,6 +935,14 @@ fun! s:has_item(list, fn)
921935 return ! empty (s: find (a: list , a: fn ))
922936endfun
923937
938+ fun ! s: get_level (bullet)
939+ if a: bullet == {} || a: bullet .bullet_type !=# ' std'
940+ return 0
941+ else
942+ return len (a: bullet .bullet)
943+ endif
944+ endfun
945+
924946fun ! s: first_bullet_line ()
925947 " returns the line number of the first bullet in the list containing the
926948 " cursor, up to the first blank line
@@ -929,16 +951,20 @@ fun! s:first_bullet_line()
929951 let l: first_line = -1
930952 let l: curr_indent = indent (l: lnum )
931953 let l: bullet_kinds = s: closest_bullet_types (l: lnum , l: curr_indent )
954+ let l: blank_lines = 0
955+ let l: list_start = 0
932956
933- while l: lnum >= 1 && ( l: curr_indent != 0 || l: bullet_kinds != [])
957+ while l: lnum >= 1 && ! l: list_start
934958 if l: bullet_kinds != []
935959 let l: first_line = l: lnum
936- let l: lnum = l: lnum - g: bullets_line_spacing
960+ let l: blank_lines = 0
937961 else
938- let l: lnum = l: lnum - 1
962+ let l: blank_lines += 1
963+ let l: list_start = l: blank_lines >= g: bullets_line_spacing
939964 endif
940- let l: bullet_kinds = s: closest_bullet_types ( l: lnum , l: curr_indent )
965+ let l: lnum -= 1
941966 let l: curr_indent = indent (l: lnum )
967+ let l: bullet_kinds = s: closest_bullet_types (l: lnum , l: curr_indent )
942968 endwhile
943969 return l: first_line
944970endfun
@@ -952,16 +978,20 @@ fun! s:last_bullet_line()
952978 let l: last_line = -1
953979 let l: curr_indent = indent (l: lnum )
954980 let l: bullet_kinds = s: closest_bullet_types (l: lnum , l: curr_indent )
981+ let l: blank_lines = 0
982+ let l: list_end = 0
955983
956- while l: lnum <= l: buf_end && ( l: curr_indent != 0 || l: bullet_kinds != [])
984+ while l: lnum <= l: buf_end && ! l: list_end
957985 if l: bullet_kinds != []
958986 let l: last_line = l: lnum
959- let l: lnum = l: lnum + g: bullets_line_spacing
987+ let l: blank_lines = 0
960988 else
961- let l: lnum = l: lnum + 1
989+ let l: blank_lines += 1
990+ let l: list_end = l: blank_lines >= g: bullets_line_spacing
962991 endif
963- let l: bullet_kinds = s: closest_bullet_types ( l: lnum , l: curr_indent )
992+ let l: lnum += 1
964993 let l: curr_indent = indent (l: lnum )
994+ let l: bullet_kinds = s: closest_bullet_types (l: lnum , l: curr_indent )
965995 endwhile
966996 return l: last_line
967997endfun
0 commit comments