@@ -100,7 +100,7 @@ endif
100100" Currently `(` and `)` are deleted by substitute().
101101" @see jsdoc#insert() for where these regexes are matched to the string
102102let s: regexs = {
103- \ ' function_declaration' : ' ^.\{-}\s*function\s*\*\?\s\+\([a-zA-Z_$][a-zA-Z0-9_$]*\)\s*\** (\s*\([^)]*\)\s*).*$' ,
103+ \ ' function_declaration' : ' ^.\{-}\s*function\s*\*\?\s\+\([a-zA-Z_$][a-zA-Z0-9_$]*\)\s*(\s*\([^)]*\)\s*).*$' ,
104104 \ ' function_expression' : ' ^.\{-}\s*\([a-zA-Z_$][a-zA-Z0-9_$]*\)\s*[:=]\s*function\s*\**\s*(\s*\([^)]*\)\s*).*$' ,
105105 \ ' anonymous_function' : ' ^.\{-}\s*function\s*\**\s*(\s*\([^)]*\)\s*).*$' ,
106106 \ ' class_extend' : ' ^.\{-}\s*class\s*\([a-zA-Z_$][a-zA-Z0-9_$]*\)*\s*extends\s*\(\([^{]*\)\).*$' ,
@@ -113,7 +113,7 @@ let s:regexs = {
113113 \ ' interface' : ' ^.\{-}\s*interface\s*\([a-zA-Z_$][a-zA-Z0-9_$]*\).*$' ,
114114 \ ' access' : ' ^\s*\(public\|protected\|private\)' ,
115115 \ ' implements' : ' ^.\{-}\s*implements\s*\(\([^{]*\)\).*$' ,
116- \ ' extends' : ' ^.\{-}\s*extends\s*\([^\s*]\)'
116+ \ ' extends' : ' ^.\{-}\s*extends\s*\([^\s*]\)' ,
117117 \ }
118118
119119function ! s: trim (value)
@@ -327,7 +327,16 @@ function! s:parse_keyword_arg(arg)
327327endfunction
328328
329329function ! jsdoc#insert () abort
330- let l: line = getline (' .' )
330+ let startpos = line (' .' )
331+ " Move cursor to the head.
332+ silent ! execute ' normal! ^'
333+ if match (getline (' .' ), ' \w$' ) != -1
334+ let l: line = getline (' .' )
335+ else
336+ let insertpos = search (' {\|)\s*{\|){\|=>\s*{' )
337+ let l: line = join (getline (startpos, insertpos))
338+ endif
339+
331340 let l: indentCharSpace = ' '
332341 let l: indentCharTab = ' '
333342 let l: autoexpandtab = &l: expandtab
@@ -338,13 +347,13 @@ function! jsdoc#insert() abort
338347 let l: indentChar = l: indentCharTab
339348 elseif l: autoexpandtab == 1 " expandtab
340349 " spaces
341- let l: indent = indent (' . ' )
350+ let l: indent = indent (startpos )
342351 let l: indentChar = l: indentCharSpace
343352 endif
344353
345354 let l: space = repeat (l: indentChar , l: indent )
346355
347- " Determine function defintion style
356+ " Determine function definition style
348357 let l: style = s: determine_style (l: line )
349358 let l: is_class = l: style [' is_class' ]
350359 let l: is_function = l: style [' is_function' ]
@@ -367,7 +376,6 @@ function! jsdoc#insert() abort
367376 let l: implements = ' '
368377 let l: return_type = ' '
369378 if l: is_function || l: is_class || l: is_interface
370-
371379 " Parse function definition
372380 " @FIXME: Does not work if function is split over several lines...
373381 " e.g.
@@ -502,9 +510,8 @@ function! jsdoc#insert() abort
502510 let l: paste = &g: paste
503511 let &g: paste = 1
504512
505- call append (line (' .' ) - 1 , l: lines )
506-
507- let l: pos = line (' .' ) - (len (l: lines ) - 1 )
513+ call append (startpos - 1 , l: lines )
514+ let l: pos = startpos + 1
508515
509516 silent ! execute ' normal! ' . l: pos . ' G$'
510517 if l: desc == # ' ' && l: funcName !=# ' '
0 commit comments