From 5daa63c69ee36d9ec75e3591f58c9733d69fa87d Mon Sep 17 00:00:00 2001 From: Fatih Arslan Date: Fri, 7 Jul 2017 00:23:40 +0300 Subject: [PATCH] textobj: include function variable for anonymous functions fixes #1181 --- autoload/go/textobj.vim | 14 ++++++++++++++ doc/vim-go.txt | 9 +++++++++ 2 files changed, 23 insertions(+) diff --git a/autoload/go/textobj.vim b/autoload/go/textobj.vim index 21789dc417..ab74d3220f 100644 --- a/autoload/go/textobj.vim +++ b/autoload/go/textobj.vim @@ -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 @@ -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 diff --git a/doc/vim-go.txt b/doc/vim-go.txt index 8aceb3fc8b..679b91f956 100644 --- a/doc/vim-go.txt +++ b/doc/vim-go.txt @@ -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, @@ -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'*