Skip to content

Commit 65b61df

Browse files
committed
CR hacked tested, docs updated
1 parent 3a8ace9 commit 65b61df

File tree

4 files changed

+41
-7
lines changed

4 files changed

+41
-7
lines changed

after/ftplugin/markdown.vim

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ setreg("o", "- [ ] ")
128128

129129
# Redefinition of <cr>. Unmap if user does not want it.
130130
inoremap <buffer> <silent> <CR> <ScriptCmd>funcs.CR_Hacked()<CR>
131-
# if !exists('g:markdown_extras_config')
132-
# && has_key(g:markdown_extras_config, 'hack_CR')
133-
# && !g:markdown_extras_config['hack_CR']
134-
# iunmap <buffer> <cr>
135-
# endif
131+
if exists('g:markdown_extras_config')
132+
&& has_key(g:markdown_extras_config, 'hack_CR')
133+
&& !g:markdown_extras_config['hack_CR']
134+
iunmap <buffer> <cr>
135+
endif
136136

137137
nnoremap <buffer> <expr> <CR> empty(links.IsLink())
138138
\ ? '<ScriptCmd>SetLinkOpFunc()<CR>g@iw'

doc/markdown_extras.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ filling it with he various keys.
182182
greater than 0.
183183
"fuzzy_search" Fuzzy or exact search in the links popup.
184184
Default: |true|.
185+
"hack_CR" Set to |false| for the standard behavior of <CR>.
186+
Default: |true|.
185187

186188

187189
*g:markdown_extras_indices*

lib/funcs.vim

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ export def CR_Hacked()
6868
)
6969
item_symbol = $"{current_line->matchstr($'^\s*{variant_4}')
7070
\ ->substitute(string(curr_nr), string(curr_nr + 1), '')}"
71-
# elseif current_line =~ $'^\s\+'
72-
# item_symbol = $"{current_line->matchstr($'^\s\+')}"
7371
endif
7472
return item_symbol
7573
enddef
@@ -106,6 +104,12 @@ export def CR_Hacked()
106104
endwhile
107105
endif
108106

107+
# if item_symbol = '' it may still mean that we are not in an item list but
108+
# yet we have an indendent line, hence, we must preserve the leading spaces
109+
if empty(item_symbol)
110+
item_symbol = $"{getline('.')->matchstr($'^\s\+')}"
111+
endif
112+
109113
# The following is in case the cursor is on the lhs of the item_symbol
110114
if col('.') < len(item_symbol)
111115
if current_line =~ $'^\s*{variant_4}'

test/test_markdown_extras.vim

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,31 @@ def g:Test_CR_hacked_wrapped_lines()
251251
:%bw!
252252
Cleanup_testfile(src_name_1)
253253
enddef
254+
255+
256+
def g:Test_CR_hacked_preserve_indent()
257+
# OBS! normal shall be without ! because we are testing <CR> which is
258+
# hacked!
259+
Generate_testfile(lines_1, src_name_1)
260+
vnew
261+
exe $"edit {src_name_1}"
262+
setlocal spell spelllang=la
263+
264+
const test_string = "\<space>\<space>\<space>\<space>\<space>today\<space>is"
265+
.. "\<space>a\<cr>beautiful\<space>day"
266+
267+
const expected_lines_35_39 = [
268+
'',
269+
' today is a',
270+
' beautiful day',
271+
'',
272+
'ciao',
273+
]
274+
275+
execute $"silent norm Go\<cr>{test_string}\<cr>\<cr>ciao"
276+
277+
echom assert_equal(expected_lines_35_39, getline(35, 39))
278+
279+
:%bw!
280+
Cleanup_testfile(src_name_1)
281+
enddef

0 commit comments

Comments
 (0)