Skip to content

Commit

Permalink
textobj: include function variable for anonymous functions
Browse files Browse the repository at this point in the history
fixes #1181
  • Loading branch information
fatih committed Jul 6, 2017
1 parent bcf3f23 commit 5daa63c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
14 changes: 14 additions & 0 deletions autoload/go/textobj.vim
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ if !exists("g:go_textobj_include_function_doc")
let g:go_textobj_include_function_doc = 1
endif

if !exists("g:go_textobj_include_function_assignment")
let g:go_textobj_include_function_assignment = 1
endif

" ( ) motions
" { } motions
" s for sentence
Expand Down Expand Up @@ -60,6 +64,16 @@ function! go#textobj#Function(mode) abort
" want's to include doc comments for function declarations
if has_key(info, 'doc') && g:go_textobj_include_function_doc
call cursor(info.doc.line, info.doc.col)
elseif info['sig']['name'] == '' && g:go_textobj_include_variable
" one liner anonymous functions
if info.lbrace.line == info.rbrace.line
" jump to first nonblack char, to get the correct column
call cursor(info.lbrace.line, 0 )
normal! ^
call cursor(info.func.line, col("."))
else
call cursor(info.func.line, info.rbrace.col)
endif
else
call cursor(info.func.line, info.func.col)
endif
Expand Down
9 changes: 9 additions & 0 deletions doc/vim-go.txt
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,8 @@ af "a function", select contents from a function definition to the
closing bracket. If |'g:go_textobj_include_function_doc'| is
enabled it also includes the comment doc for a function
declaration. This text-object also supports literal functions.
If |'g:go_textobj_include_variable'| is enabled it also
includes the variable of an function assignment

*go-v_if* *go-if*
if "inside a function", select contents of a function,
Expand Down Expand Up @@ -1348,6 +1350,13 @@ Consider the comment above a function to be part of the function when using
the `af` text object and `[[` motion. By default it's enabled. >
let g:go_textobj_include_function_doc = 1
<
*'g:go_textobj_include_variable'*

Consider the variable of an function assignment to be part of the anonymous
function when using the `af` text object. By default it's enabled. >
let g:go_textobj_include_variable = 1
<
*'g:go_metalinter_autosave'*

Expand Down

0 comments on commit 5daa63c

Please sign in to comment.