@@ -27,21 +27,6 @@ export def ZipLists(l1: list<any>, l2: list<any>): list<list<any>>
2727 return map (range (min_len), $ ' [{l1}[v:val], {l2}[v:val]]' )
2828enddef
2929
30- export def RegexList2RegexOR (regex_list: list <string> ,
31- very_magic: bool = false): string
32- # Convert a list of regex into an atom where each regex is separated by a OR
33- # condition
34-
35- var result = ' '
36- if very_magic
37- result = regex_list- >map ((_, val) = > substitute (val, ' ^\(\\v\)' , ' ' , ' ' ))
38- - >join (' |' )- >printf (' \v(%s)' )
39- else
40- result = regex_list- >join (' \|' )- >printf (' \(%s\)' )
41- endif
42- return result
43- enddef
44-
4530export def GetTextObject (textobject: string ): dict <any>
4631 # You pass a text object like ' iw' and it returns the text
4732 # associated to it along with the start and end positions
@@ -113,7 +98,6 @@ export def RemoveSurrounding(
11398 # Remove right delimiter
11499 var lB = interval[1 ][1 ]
115100 var cB = interval[1 ][2 ]
116- # echom " cB: " .. cB
117101 # The value of cB may no longer be valid since we shortened the line
118102 if lA == lB
119103 cB = cB - len (keys (open_delimiter_dict)[0 ])
@@ -123,7 +107,6 @@ export def RemoveSurrounding(
123107 strcharpart (getline (lB), 0 , cB)
124108 .. strcharpart (getline (lB), cB + len (keys (close_delimiter_dict)[0 ]))
125109 setline (lB, newline)
126- # echom " lB: " .. newline
127110 endif
128111enddef
129112
@@ -146,7 +129,6 @@ export def SurroundSimple(open_delimiter: string,
146129 if ! empty (text_object)
147130 # GetTextObject is called for setting ' [ and ' ] marks through a yank .
148131 var text_object_dict = GetTextObject (text_object)
149- echom text_object
150132 A = text_object_dict.start
151133 B = text_object_dict.end
152134 endif
@@ -204,7 +186,6 @@ export def SurroundSmart(open_delimiter: string,
204186 if ! empty (text_object)
205187 # GetTextObject is called for setting ' [ and ' ] marks through a yank .
206188 var text_object_dict = GetTextObject (text_object)
207- echom text_object
208189 A = text_object_dict.start
209190 B = text_object_dict.end
210191 endif
@@ -323,32 +304,43 @@ export def SurroundSmart(open_delimiter: string,
323304 # Next , we have to adjust the text between A and B, by removing all the
324305 # possible delimiters left between them.
325306
326- var all_delimiters_regex =
327- RegexList2RegexOR (values (open_delimiters_dict), true)
328-
329307 # If on the same line
330308 if lA == lB
331309 # Overwrite everything that is in the middle
332310 var A_to_B = ' '
333311
334312 A_to_B = strcharpart (getline (lA), cA - 1 , cB - cA + 1 )
335- - >substitute (all_delimiters_regex, ' ' , ' g' )
313+ for regex in values (open_delimiters_dict)
314+ A_to_B = A_to_B- >substitute (regex, ' ' , ' g' )
315+ endfor
336316
337317 setline (lA, toA .. A_to_B .. fromB)
338318
339319 else
340- var lineA = toA .. strcharpart (getline (lA), cA - 1 )
341- - >substitute (all_delimiters_regex, ' ' , ' g' )
342- echom " lineA: " .. lineA
320+ # Set line A
321+ var afterA = strcharpart (getline (lA), cA - 1 )
322+ for regex in values (open_delimiters_dict)
323+ afterA = afterA- >substitute (regex, ' ' , ' g' )
324+ endfor
325+ var lineA = toA .. afterA
343326 setline (lA, lineA)
344- var lineB = strcharpart (getline (lB), 0 , cB - 1 )
345- - >substitute (all_delimiters_regex, ' ' , ' g' ) .. fromB
346- echom " lineB: " .. lineB
327+
328+ # Set line B
329+ var beforeB = strcharpart (getline (lB), 0 , cB - 1 )
330+ for regex in values (open_delimiters_dict)
331+ beforeB = beforeB- >substitute (regex, ' ' , ' g' )
332+ endfor
333+ var lineB = beforeB .. fromB
347334 setline (lB, lineB)
348- var l = 1
335+
349336 # Fix intermediate lines
337+ var l = 1
350338 while lA + l < lB
351- setline (lA + l , getline (lA + l )- >substitute (all_delimiters_regex, ' ' , ' g' ) )
339+ var middleline = getline (lA + l )
340+ for regex in values (open_delimiters_dict)
341+ middleline = middleline- > substitute (regex, ' ' , ' g' )
342+ endfor
343+ setline (lA + l , middleline)
352344 l += 1
353345 endwhile
354346 endif
@@ -579,10 +571,6 @@ export def IsInRange(
579571 setcharpos (" 'a" , range [0 ])
580572 setcharpos (" 'b" , range [1 ])
581573 if IsBetweenMarks (" 'a" , " 'b" )
582- # echom " cur_pos: " .. string (getcharpos (' .' ))
583- # echom " range[0]: " .. string (range [0 ])
584- # echom " range[1]: " .. string (range [1 ])
585- echom IsBetweenMarks (" 'a" , " 'b" )
586574 interval = [range [0 ], range [1 ]]
587575 break
588576 endif
0 commit comments