1
1
" Vim plugin for automated bulleted lists
2
- " Last Change: Mon 9 Apr 2018
2
+ " Last Change: 10 Apr 2018
3
3
" Maintainer: Dorian Karter
4
4
" License: MIT
5
5
" FileTypes: markdown, text, gitcommit
@@ -42,7 +42,7 @@ if !exists('g:bullets_line_spacing')
42
42
end
43
43
" ------------------------------------------------------ }}}
44
44
45
- " Helper methods ---------------------------------------- {{{
45
+ " Bullet type detection ---------------------------------------- {{{
46
46
fun ! s: match_numeric_list_item (input_text)
47
47
let l: num_bullet_regex = ' \v^((\s*)(\d+)(\.|\))(\s+))(.*)'
48
48
let l: matches = matchlist (a: input_text , l: num_bullet_regex )
@@ -88,25 +88,42 @@ fun! s:match_roman_list_item(input_text)
88
88
\ }
89
89
endfun
90
90
91
+ fun ! s: match_checkbox_bullet_item (input_text)
92
+ let l: checkbox_bullet_regex = ' \v(^(\s*)- \[[x ]?\] )(.*)'
93
+ let l: matches = matchlist (a: input_text , l: checkbox_bullet_regex )
94
+
95
+ if empty (l: matches )
96
+ return {}
97
+ endif
98
+
99
+ let l: leading_space = l: matches [2 ]
100
+ let l: text_after_bullet = l: matches [3 ]
101
+
102
+ return {
103
+ \ ' leading_space' : l: leading_space ,
104
+ \ ' text_after_bullet' : l: text_after_bullet
105
+ \ }
106
+ endfun
107
+
91
108
fun ! s: match_bullet_list_item (input_text)
92
- let l: std_bullet_regex = ' \v(^\s*(-|\*+|#\.|\\item)( \[[x ]?\])? )(.*)'
109
+ let l: std_bullet_regex = ' \v(^\s*(-|\*+|#\.|\\item) )(.*)'
93
110
let l: matches = matchlist (a: input_text , l: std_bullet_regex )
94
111
95
112
if empty (l: matches )
96
113
return {}
97
114
endif
98
115
99
116
let l: whole_bullet = l: matches [1 ]
100
- let l: bullet = l: matches [2 ]
101
- let l: text_after_bullet = l: matches [4 ]
117
+ let l: text_after_bullet = l: matches [3 ]
102
118
103
119
return {
104
120
\ ' whole_bullet' : l: whole_bullet ,
105
- \ ' bullet' : l: bullet ,
106
121
\ ' text_after_bullet' : l: text_after_bullet
107
122
\ }
108
123
endfun
124
+ " ------------------------------------------------------- }}}
109
125
126
+ " Helper methods ---------------------------------------- {{{
110
127
fun ! s: get_visual_selection_lines ()
111
128
let [l: lnum1 , l: col1 ] = getpos (" '<" )[1 :2 ]
112
129
let [l: lnum2 , l: col2 ] = getpos (" '>" )[1 :2 ]
@@ -131,6 +148,8 @@ fun! s:next_bullet_str(bullet_type, line_data)
131
148
elseif a: bullet_type == # ' num'
132
149
let l: next_num = a: line_data .bullet + 1
133
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 . ' - [ ] '
134
153
else
135
154
return a: line_data .whole_bullet
136
155
endif
@@ -147,6 +166,7 @@ fun! s:insert_new_bullet()
147
166
let l: next_line_num = l: curr_line_num + g: bullets_line_spacing
148
167
let l: curr_line = getline (l: curr_line_num )
149
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 )
150
170
let l: num_bullet_matches = s: match_numeric_list_item (l: curr_line )
151
171
let l: rom_bullet_matches = s: match_roman_list_item (l: curr_line )
152
172
let l: bullet_type = ' '
@@ -156,7 +176,10 @@ fun! s:insert_new_bullet()
156
176
let l: send_return = 1
157
177
let l: normal_mode = mode () == # ' n'
158
178
159
- if ! empty (l: std_bullet_matches )
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 )
160
183
let l: bullet_type = ' std'
161
184
let l: bullet = l: std_bullet_matches
162
185
elseif ! empty (l: num_bullet_matches )
0 commit comments