Skip to content

Commit d776e2b

Browse files
committed
Big chage coming
1 parent 0c22a29 commit d776e2b

File tree

1 file changed

+40
-23
lines changed

1 file changed

+40
-23
lines changed

lib/funcs.vim

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,44 +29,61 @@ export def ContinueList()
2929
line('.')),
3030
'\n')
3131

32-
var tmp = ''
32+
# Check if the current line is an item or not and check if there is only a
33+
# bullet or a bullet + some text
3334
# There is only a buller with no text. Next <CR> shall remove the bullet
35+
var is_item = false
3436
var only_bullet = false
35-
36-
3737
# Check if you only have the bullet with no item
3838
for variant in [variant_1, variant_2, variant_3, variant_4]
3939
if current_line =~ $'^\s*{variant}\s*$'
40-
append(line('.'), '')
41-
deletebufline('%', line('.'))
40+
is_item = true
4241
only_bullet = true
4342
break
43+
elseif current_line =~ $'^\s*{variant}\s*'
44+
is_item = true
45+
break
46+
else
47+
is_item = false
4448
endif
4549
endfor
4650

51+
echom is_item
52+
4753
# Scan the current line through the less general regex (a regex can be
4854
# contained in another regex)
49-
if !only_bullet
50-
if current_line =~ $'^\s*{variant_1}'
51-
# If - [x], the next item should be - [ ] anyway.
52-
tmp = $"{current_line->matchstr($'^\s*{variant_1}')->substitute('x', ' ', 'g')}"
53-
elseif current_line =~ $'^\s*{variant_2}'
54-
tmp = $"{current_line->matchstr($'^\s*{variant_2}')}"
55-
elseif current_line =~ $'^\s*{variant_3}'
56-
tmp = $"{current_line->matchstr($'^\s*{variant_3}')}"
57-
elseif current_line =~ $'^\s*{variant_4}'
58-
# Get rid of the trailing '.' and convert to number
59-
var curr_nr = str2nr(
60-
$"{current_line->matchstr($'^\s*{variant_4}')->matchstr('\d\+')}"
61-
)
62-
tmp = $"{current_line->matchstr($'^\s*{variant_4}')
63-
\ ->substitute(string(curr_nr), string(curr_nr + 1), '')}"
64-
endif
55+
var this_line = is_item ? strcharpart(current_line, 0, col('.') - 1) : ''
56+
var next_line = is_item ? strcharpart(current_line, col('.') - 1) : ''
57+
var item_symbol = ''
58+
if is_item && !only_bullet
59+
if current_line =~ $'^\s*{variant_1}'
60+
# If - [x], the next item should be - [ ] anyway.
61+
item_symbol = $"{current_line->matchstr($'^\s*{variant_1}')
62+
\ ->substitute('x', ' ', 'g')}"
63+
elseif current_line =~ $'^\s*{variant_2}'
64+
item_symbol = $"{current_line->matchstr($'^\s*{variant_2}')}"
65+
elseif current_line =~ $'^\s*{variant_3}'
66+
item_symbol = $"{current_line->matchstr($'^\s*{variant_3}')}"
67+
elseif current_line =~ $'^\s*{variant_4}'
68+
# Get rid of the trailing '.' and convert to number
69+
var curr_nr = str2nr(
70+
$"{current_line->matchstr($'^\s*{variant_4}')->matchstr('\d\+')}"
71+
)
72+
item_symbol = $"{current_line->matchstr($'^\s*{variant_4}')
73+
\ ->substitute(string(curr_nr), string(curr_nr + 1), '')}"
74+
endif
75+
elseif is_item && only_bullet
76+
this_line = ''
77+
next_line = ''
78+
else
79+
this_line = getline('.')
80+
next_line = ''
6581
endif
6682

6783
# Add the correct newline
68-
append(line('.'), $"{tmp}")
69-
cursor(line('.') + 1, col('$') - 1)
84+
setline(line('.'), this_line)
85+
append(line('.'), item_symbol .. next_line)
86+
cursor(line('.') + 1, len(item_symbol) + 1)
7087
startinsert
7188

7289
enddef

0 commit comments

Comments
 (0)