From a42cd58636f4ddb82d6d2e50ad3f3d808c70834d Mon Sep 17 00:00:00 2001 From: Rane Brown Date: Wed, 16 Oct 2019 22:27:26 -0600 Subject: [PATCH] Don't insert marker character with o or O within a code block. Previously if a code block was part of a list and o or O was used a new list marker would be inserted. Also moved the is_codeblock check function to utils file for use elsewhere. --- autoload/vimwiki/lst.vim | 31 +++++++++++++------------------ autoload/vimwiki/u.vim | 10 ++++++++++ 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/autoload/vimwiki/lst.vim b/autoload/vimwiki/lst.vim index 26966bc..c22a00e 100644 --- a/autoload/vimwiki/lst.vim +++ b/autoload/vimwiki/lst.vim @@ -1471,10 +1471,12 @@ function! vimwiki#lst#kbd_o() "inserting and deleting the x is necessary "because otherwise the indent is lost exe 'normal!' "ox\" - if parent.type != 0 - call s:clone_marker_from_to(parent.lnum, cur_item.lnum+1) - else - call s:indent_multiline(cur_item, cur_item.lnum+1) + if !vimwiki#u#is_codeblock(lnum) + if parent.type != 0 + call s:clone_marker_from_to(parent.lnum, cur_item.lnum+1) + else + call s:indent_multiline(cur_item, cur_item.lnum+1) + endif endif startinsert! endfunction @@ -1483,10 +1485,12 @@ endfunction function! vimwiki#lst#kbd_O() exe 'normal!' "Ox\" let cur_ln = line('.') - if getline(cur_ln+1) !~# '^\s*$' - call s:clone_marker_from_to(cur_ln+1, cur_ln) - else - call s:clone_marker_from_to(cur_ln-1, cur_ln) + if !vimwiki#u#is_codeblock(cur_ln) + if getline(cur_ln+1) !~# '^\s*$' + call s:clone_marker_from_to(cur_ln+1, cur_ln) + else + call s:clone_marker_from_to(cur_ln-1, cur_ln) + endif endif startinsert! endfunction @@ -1548,15 +1552,6 @@ function! s:cr_on_empty_list_item(lnum, behavior) endif endfunction -function! s:is_codeblock(lnum) - let syn_g = synIDattr(synID(a:lnum,1,1),'name') - if syn_g =~# 'textSnip*' || syn_g =~# 'VimwikiPre*' - return 1 - else - return 0 - endif -endfunction - function! s:cr_on_empty_line(lnum, behavior) let lst = s:get_corresponding_item(a:lnum) @@ -1565,7 +1560,7 @@ function! s:cr_on_empty_line(lnum, behavior) exe 'normal!' "gi\x\\" if a:behavior == 2 || a:behavior == 3 - if lst.type == 0 || s:is_codeblock(a:lnum) + if lst.type == 0 || vimwiki#u#is_codeblock(a:lnum) " don't insert new bullet if not part of a list return else diff --git a/autoload/vimwiki/u.vim b/autoload/vimwiki/u.vim index a51d13c..3c29549 100644 --- a/autoload/vimwiki/u.vim +++ b/autoload/vimwiki/u.vim @@ -93,3 +93,13 @@ function vimwiki#u#map_key(mode, key, plug, ...) endif endif endfunction + + +function! vimwiki#u#is_codeblock(lnum) + let syn_g = synIDattr(synID(a:lnum,1,1),'name') + if syn_g =~# 'textSnip.*' || syn_g =~# 'VimwikiPre.*' || syn_g =~# '.*Comment' + return 1 + else + return 0 + endif +endfunction