@@ -58,6 +58,7 @@ fun! s:match_numeric_list_item(input_text)
58
58
let l: text_after_bullet = l: matches [6 ]
59
59
60
60
return {
61
+ \ ' bullet_type' : ' num' ,
61
62
\ ' leading_space' : l: leading_space ,
62
63
\ ' trailing_space' : l: trailing_space ,
63
64
\ ' bullet' : l: num ,
@@ -80,6 +81,7 @@ fun! s:match_roman_list_item(input_text)
80
81
let l: text_after_bullet = l: matches [6 ]
81
82
82
83
return {
84
+ \ ' bullet_type' : ' rom' ,
83
85
\ ' leading_space' : l: leading_space ,
84
86
\ ' trailing_space' : l: trailing_space ,
85
87
\ ' bullet' : l: rom ,
@@ -100,6 +102,7 @@ fun! s:match_checkbox_bullet_item(input_text)
100
102
let l: text_after_bullet = l: matches [3 ]
101
103
102
104
return {
105
+ \ ' bullet_type' : ' chk' ,
103
106
\ ' leading_space' : l: leading_space ,
104
107
\ ' text_after_bullet' : l: text_after_bullet
105
108
\ }
@@ -117,10 +120,30 @@ fun! s:match_bullet_list_item(input_text)
117
120
let l: text_after_bullet = l: matches [3 ]
118
121
119
122
return {
123
+ \ ' bullet_type' : ' std' ,
120
124
\ ' whole_bullet' : l: whole_bullet ,
121
125
\ ' text_after_bullet' : l: text_after_bullet
122
126
\ }
123
127
endfun
128
+
129
+ fun ! s: parse_bullet (line_text)
130
+ let l: std_bullet_matches = s: match_bullet_list_item (a: line_text )
131
+ let l: chk_bullet_matches = s: match_checkbox_bullet_item (a: line_text )
132
+ let l: num_bullet_matches = s: match_numeric_list_item (a: line_text )
133
+ let l: rom_bullet_matches = s: match_roman_list_item (a: line_text )
134
+
135
+ if ! empty (l: chk_bullet_matches )
136
+ return l: chk_bullet_matches
137
+ elseif ! empty (l: std_bullet_matches )
138
+ return l: std_bullet_matches
139
+ elseif ! empty (l: num_bullet_matches )
140
+ return l: num_bullet_matches
141
+ elseif ! empty (l: rom_bullet_matches )
142
+ return l: rom_bullet_matches
143
+ else
144
+ return {}
145
+ endif
146
+ endfun
124
147
" ------------------------------------------------------- }}}
125
148
126
149
" Helper methods ---------------------------------------- {{{
@@ -141,17 +164,17 @@ endfun
141
164
" ------------------------------------------------------- }}}
142
165
143
166
" Generate bullets -------------------------------------- {{{
144
- fun ! s: next_bullet_str (bullet_type, line_data )
145
- if a: bullet_type == # ' rom'
146
- let l: next_num = s: arabic2roman (s: roman2arabic (a: line_data .bullet) + 1 )
147
- return a: line_data .leading_space . l: next_num . a: line_data .closure . ' '
148
- elseif a: bullet_type == # ' num'
149
- let l: next_num = a: line_data .bullet + 1
150
- return a: line_data .leading_space . l: next_num . a: line_data .closure . ' '
151
- elseif a: bullet_type == # ' chk'
152
- return a: line_data .leading_space . ' - [ ] '
167
+ fun ! s: next_bullet_str (bullet )
168
+ if a: bullet . bullet_type == # ' rom'
169
+ let l: next_num = s: arabic2roman (s: roman2arabic (a: bullet .bullet) + 1 )
170
+ return a: bullet .leading_space . l: next_num . a: bullet .closure . ' '
171
+ elseif a: bullet . bullet_type == # ' num'
172
+ let l: next_num = a: bullet .bullet + 1
173
+ return a: bullet .leading_space . l: next_num . a: bullet .closure . ' '
174
+ elseif a: bullet . bullet_type == # ' chk'
175
+ return a: bullet .leading_space . ' - [ ] '
153
176
else
154
- return a: line_data .whole_bullet
177
+ return a: bullet .whole_bullet
155
178
endif
156
179
endfun
157
180
@@ -165,42 +188,23 @@ fun! s:insert_new_bullet()
165
188
let l: curr_line_num = line (' .' )
166
189
let l: next_line_num = l: curr_line_num + g: bullets_line_spacing
167
190
let l: curr_line = getline (l: curr_line_num )
168
- let l: std_bullet_matches = s: match_bullet_list_item (l: curr_line )
169
- let l: chk_bullet_matches = s: match_checkbox_bullet_item (l: curr_line )
170
- let l: num_bullet_matches = s: match_numeric_list_item (l: curr_line )
171
- let l: rom_bullet_matches = s: match_roman_list_item (l: curr_line )
172
- let l: bullet_type = ' '
173
- let l: bullet = {}
191
+ let l: bullet = s: parse_bullet (l: curr_line )
174
192
let l: bullet_content = ' '
175
193
let l: text_after_bullet = ' '
176
194
let l: send_return = 1
177
195
let l: normal_mode = mode () == # ' n'
178
196
179
- if ! empty (l: chk_bullet_matches )
180
- let l: bullet_type = ' chk'
181
- let l: bullet = l: chk_bullet_matches
182
- elseif ! empty (l: std_bullet_matches )
183
- let l: bullet_type = ' std'
184
- let l: bullet = l: std_bullet_matches
185
- elseif ! empty (l: num_bullet_matches )
186
- let l: bullet_type = ' num'
187
- let l: bullet = l: num_bullet_matches
188
- elseif ! empty (l: rom_bullet_matches )
189
- let l: bullet_type = ' rom'
190
- let l: bullet = l: rom_bullet_matches
191
- endif
192
-
193
197
" check if current line is a bullet and we are at the end of the line (for
194
198
" insert mode only)
195
- if strlen ( l: bullet_type ) && (l: normal_mode || s: is_at_eol ())
199
+ if l: bullet != {} && (l: normal_mode || s: is_at_eol ())
196
200
" was any text entered after the bullet?
197
201
if l: bullet .text_after_bullet == # ' '
198
202
" We don't want to create a new bullet if the previous one was not used,
199
203
" instead we want to delete the empty bullet - like word processors do
200
204
call s: delete_empty_bullet (l: curr_line_num )
201
205
else
202
206
203
- let l: next_bullet_list = [s: next_bullet_str (l: bullet_type , l: bullet )]
207
+ let l: next_bullet_list = [s: next_bullet_str (l: bullet )]
204
208
205
209
" prepend blank lines if desired
206
210
if g: bullets_line_spacing > 1
0 commit comments