From bf68ba0c362f91c2fdeb77208ef6a975547d2b49 Mon Sep 17 00:00:00 2001 From: Martin Tournoij Date: Fri, 30 Jun 2017 05:28:08 +0100 Subject: [PATCH] Also select variable when using af on anonymous functions When using `af` on an anonymous function that is assigned, such as: peanuts := func(a string) error { return errors.New("I'm alergic!") } we will now also select the `peanuts` variable. This could be improved by not assuming a single space between `=` and the `func`. Dunno if that's worth the effort ... use gofmt? ;-) Fixes: #1181 --- autoload/go/textobj.vim | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/autoload/go/textobj.vim b/autoload/go/textobj.vim index 21789dc417..cdf952c1e7 100644 --- a/autoload/go/textobj.vim +++ b/autoload/go/textobj.vim @@ -57,13 +57,24 @@ function! go#textobj#Function(mode) abort if a:mode == 'a' " anonymous functions doesn't have associated doc. Also check if the user - " want's to include doc comments for function declarations + " wants 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) else call cursor(info.func.line, info.func.col) endif + " Select variable too when an anonymous function is assigned. + if info['sig']['name'] == '' + " Get function plus two characters before, to see if we're assigning it. + let assign = getline('.')[info['func']['col']-3:][:len(info['sig']['full'])+1] + + " Back it up! + if assign == '= ' . info['sig']['full'] + normal! bb + endif + endif + normal! v call cursor(info.rbrace.line, info.rbrace.col) return