Skip to content

Commit 6c8b529

Browse files
committed
Added syntax on to the dummy file
1 parent 507d64e commit 6c8b529

File tree

6 files changed

+71
-40
lines changed

6 files changed

+71
-40
lines changed

lib/constants.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export const STRIKE_CLOSE_DICT = {[TEXT_STYLES_DICT.markdownStrike.close_delim]:
110110
export const LINK_OPEN_DICT = {[TEXT_STYLES_DICT.markdownLinkText.open_delim]:
111111
TEXT_STYLES_DICT.markdownLinkText.open_regex}
112112
export const LINK_CLOSE_DICT = {[TEXT_STYLES_DICT.markdownLinkText.close_delim]:
113-
TEXT_STYLES_DICT.markdownStrike.close_regex}
113+
TEXT_STYLES_DICT.markdownLinkText.close_regex}
114114

115115
# TODO on the delimiter synIDattr(synID(line("."), col("."), 1), "name")
116116
# return markdownCodeDelimiter instead of

lib/utils.vim

Lines changed: 56 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ vim9script
22

33
import autoload "./constants.vim"
44

5-
65
export def Echoerr(msg: string)
76
echohl ErrorMsg | echom $'[markdown_extras] {msg}' | echohl None
87
enddef
@@ -11,7 +10,6 @@ export def Echowarn(msg: string)
1110
echohl WarningMsg | echom $'[markdown_extras] {msg}' | echohl None
1211
enddef
1312

14-
1513
export def FormatWithoutMoving(a: number = 0, b: number = 0)
1614
# To be used for formatting through autocmds
1715
var view = winsaveview()
@@ -238,12 +236,11 @@ export def SurroundSmart(style: string, type: string = '')
238236
if style != 'markdownCode'
239237
A_to_B = A_to_B->substitute($'\V{join(delimiters_to_remove, '\|')}', '', 'g')
240238
endif
241-
# echom "A_to_B: " .. A_to_B
242239

243-
echom $'toA: ' .. toA
244-
echom $'fromB: ' .. fromB
245-
echom $'A_to_B:' .. A_to_B
246-
echom '----------\n'
240+
# echom $'toA: ' .. toA
241+
# echom $'fromB: ' .. fromB
242+
# echom $'A_to_B:' .. A_to_B
243+
# echom '----------\n'
247244

248245
# Set the whole line
249246
setline(lA, toA .. A_to_B .. fromB)
@@ -381,7 +378,6 @@ export def IsBetweenMarks(A: string, B: string): bool
381378
return result
382379
enddef
383380

384-
385381
export def IsInRange(): dict<list<list<number>>>
386382
# Return a dict like {'markdownCode': [[21, 19], [22, 21]]}.
387383
# The returned intervals are open.
@@ -414,38 +410,69 @@ export def IsInRange(): dict<list<list<number>>>
414410
enddef
415411

416412
# Main function start here
417-
const text_style =
418-
synIDattr(synID(line("."), col("."), 1), "name") == 'markdownItalic'
419-
|| synIDattr(synID(line("."), col("."), 1), "name") == 'markdownBold'
413+
# text_style comes from vim-markdown
414+
const text_style = synIDattr(synID(line("."), col("."), 1), "name")
415+
const text_style_adjusted =
416+
text_style == 'markdownItalic' || text_style == 'markdownBold'
420417
? StarOrUnderscore(synIDattr(synID(line("."), col("."), 1), "name"))
421418
: synIDattr(synID(line("."), col("."), 1), "name")
422419
var return_val = {}
423420

424-
if !empty(text_style)
425-
&& index(keys(constants.TEXT_STYLES_DICT), text_style) != -1
421+
if !empty(text_style_adjusted)
422+
&& index(keys(constants.TEXT_STYLES_DICT), text_style_adjusted) != -1
423+
424+
const saved_curpos = getcursorcharpos()
426425

427426
# Search start delimiter
428427
const open_delim =
429-
eval($'constants.TEXT_STYLES_DICT.{text_style}.open_delim')
430-
const open_regex =
431-
eval($'constants.TEXT_STYLES_DICT.{text_style}.open_regex')
432-
var start_delim = searchpos(open_regex, 'nbW')
433-
start_delim[1] += len(open_delim)
428+
eval($'constants.TEXT_STYLES_DICT.{text_style_adjusted}.open_delim')
429+
430+
var open_delim_pos = searchpos($'\V{open_delim}', 'bW')
431+
var current_style = synIDattr(synID(line("."), col("."), 1), "name")
432+
while current_style != $'{text_style}Delimiter'
433+
open_delim_pos = searchpos($'\V{open_delim}', 'bW')
434+
current_style = synIDattr(synID(line("."), col("."), 1), "name")
435+
endwhile
436+
open_delim_pos[1] += len(open_delim)
434437

435-
# Search end delimiter
438+
# Search end delimiter. The end delimiter may be a blank line, hence
439+
# things become a bit cumbersome.
440+
setcursorcharpos(saved_curpos[1 : 2])
436441
const close_delim =
437-
eval($'constants.TEXT_STYLES_DICT.{text_style}.close_delim')
438-
const close_regex =
439-
eval($'constants.TEXT_STYLES_DICT.{text_style}.close_regex')
440-
var end_delim = searchpos(close_regex, 'ncW')
441-
442-
# TODO: Very ugly hack due to the LINK_CLOSE_REGEX ending up on ]
443-
if synIDattr(synID(end_delim[0], end_delim[1], 1), "name")
444-
== 'markdownLinkTextDelimiter'
445-
end_delim[1] -= 1
442+
eval($'constants.TEXT_STYLES_DICT.{text_style_adjusted}.close_delim')
443+
var close_delim_pos = searchpos($'\V{close_delim}', 'nW')
444+
var blank_line_pos = searchpos($'^$', 'nW')
445+
var first_met = [0, 0]
446+
current_style = synIDattr(synID(line("."), col("."), 1), "name")
447+
448+
while current_style != $'{text_style}Delimiter'
449+
&& getline(line('.')) !~ '^$'
450+
close_delim_pos = searchpos($'\V{close_delim}', 'nW')
451+
blank_line_pos = searchpos($'^$', 'nW')
452+
if close_delim_pos == [0, 0]
453+
first_met = blank_line_pos
454+
elseif blank_line_pos == [0, 0]
455+
first_met = close_delim_pos
456+
else
457+
first_met = IsLess(close_delim_pos, blank_line_pos)
458+
? close_delim_pos
459+
: blank_line_pos
460+
endif
461+
setcursorcharpos(first_met)
462+
current_style = synIDattr(synID(line("."), col("."), 1), "name")
463+
endwhile
464+
465+
# If we hit a blank line, then we take the previous line and last column,
466+
# to keep consistency in returning open-intervals
467+
if getline(line('.')) =~ '^$'
468+
first_met[0] = first_met[0] - 1
469+
first_met[1] = len(getline(first_met[0]))
470+
else
471+
first_met[1] -= 1
446472
endif
447473

448-
return_val = {[text_style]: [start_delim, end_delim]}
474+
setcursorcharpos(saved_curpos[1 : 2])
475+
return_val = {[text_style_adjusted]: [open_delim_pos, first_met]}
449476
endif
450477

451478
return return_val

test/run_tests.cmd

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ REM
1616
echo set runtimepath+=..
1717
echo set runtimepath+=../after
1818
echo filetype plugin indent on
19+
echo syntax on
1920
) >> "%VIMRC%"
2021

21-
SET "VIM_CMD=%VIMPRG% --clean -u %VIMRC% -i NONE --not-a-term"
22+
REM SET "VIM_CMD=%VIMPRG% --clean -u %VIMRC% -i NONE --not-a-term"
23+
SET "VIM_CMD=%VIMPRG% --clean -u %VIMRC% -i NONE"
2224

2325
REM Check if the vimrc file was created successfully
2426
if NOT EXIST "%VIMRC%" (
@@ -33,7 +35,8 @@ type "%VIMRC%"
3335
echo/
3436

3537
REM Run Vim with the specified configuration and additional commands
36-
SET "TEST_FILES=['test_markdown_extras.vim', 'test_utils.vim', 'test_regex.vim']"
38+
REM SET "TEST_FILES=['test_markdown_extras.vim', 'test_utils.vim', 'test_regex.vim']"
39+
SET "TEST_FILES=['test_utils.vim']"
3740
%VIM_CMD% -c "vim9cmd g:TestFiles = %TEST_FILES%" -S "runner.vim"
3841
REM If things go wrong uncomment the following line and see e.g. if the
3942
REM vimrc_for_test is valid, check :messages and so on.

test/run_tests.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ echo "vim9script" > "$VIMRC"
2727
echo "">> "$VIMRC"
2828
echo "set runtimepath+=.." >> "$VIMRC"
2929
echo "set runtimepath+=../after" >> "$VIMRC"
30-
echo "filetype plugin on" >> "$VIMRC"
30+
echo "filetype indent plugin on" >> "$VIMRC"
31+
echo "syntax on" >> "$VIMRC"
3132

3233
# Display vimrc content
3334
echo "----- vimrc content ---------"

test/test_regex.vim

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,15 +301,16 @@ def g:Test_links_regex()
301301
for ii in range(len(curpos))
302302
cursor(curpos[ii])
303303
actual_pos = searchpos(LINK_OPEN_REGEX, 'bW')
304-
echom actual_pos
305304
echom assert_equal(expected_pos_open[ii], actual_pos)
306305

307306
# Close
308307
cursor(curpos[ii])
309308
actual_pos = searchpos(LINK_CLOSE_REGEX, 'cW')
309+
echom LINK_CLOSE_REGEX
310+
echom actual_pos
310311
echom assert_equal(expected_pos_close[ii], actual_pos)
311312
endfor
312313

313-
:%bw!
314-
Cleanup_testfile(src_name_2)
314+
# :%bw!
315+
# Cleanup_testfile(src_name_2)
315316
enddef

test/test_utils.vim

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ def g:Test_ListComparison()
157157
assert_false(utils.IsGreater(A, B))
158158
assert_false(utils.IsLess(A, B))
159159
assert_true(utils.IsEqual(A, B))
160-
161160
enddef
162161

163162
def g:Test_IsInRange()
@@ -201,7 +200,7 @@ def g:Test_IsInRange()
201200

202201
# End of paragraph with no delimiter
203202
cursor(21, 43)
204-
expected_value = {'markdownStrike': [[21, 39], [23, 1]]}
203+
expected_value = {'markdownStrike': [[21, 39], [22, 26]]}
205204
range = utils.IsInRange()
206205
echom assert_equal(expected_value, range)
207206

@@ -388,8 +387,8 @@ def g:Test_SurroundSmart_one_line_1()
388387
actual_value = getline(18, 20)
389388
echom assert_equal(expected_value, actual_value)
390389

391-
:%bw!
392-
Cleanup_testfile(src_name_2)
390+
# :%bw!
391+
# Cleanup_testfile(src_name_2)
393392
enddef
394393

395394
def g:Test_RemoveSurrounding_one_line()

0 commit comments

Comments
 (0)