-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fold import, var, and const blocks #1339
Conversation
This adds `foldmethod=syntax` folding for `import`, `var`, and `const` blocks. I added a new `g:go_fold_enable` setting to selectively enable which regions get folded. I find this useful personally as I only want to fold `import` blocks. Future extension to this might be: - `struct` and `interface`, to selectively fold `type foo struct { .. }` and `type foo interface { .. }` definitions; - `package`, to fold the package-level comment. But that's another PR for another day ;-) Fixes: #963
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Carpetsmoker This looks awesome. There are some things that needs to be taken care of. Once we have these I think it's good to go
doc/vim-go.txt
Outdated
Enable folding of only imports: | ||
> | ||
let g:go_fold = ['import'] | ||
< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like changing variables to two different types. I would rather have two settings than one. One of enabling/disabling and one for changing the settings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could also just make the default be let g:go_fold = ['import', 'block', 'varconst']
? The 1
was just a shortcut for this.
I'm not sure if we need two variables, and it will confuse things if they're both set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok that works. But can you add a piece of text on how to disable it (i.e: setting to empty list) so people know it.
@@ -1589,6 +1588,23 @@ By default "snakecase" is used. Current values are: ["snakecase", | |||
> | |||
let g:go_addtags_transform = 'snakecase' | |||
< | |||
*'g:go_fold_enable'* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should add a line explaining that they get this when they also add set foldmethod=syntax
to their vimrc
syntax/go.vim
Outdated
syn keyword goDeclaration var const | ||
syn keyword goPackage package | ||
syn keyword goImport import contained | ||
syn keyword goVarConst var const contained |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changes the semantics of the syntax settings. In go const, var and type all are declarations, so goDeclaration
is the correct setting here. Actually things like import
or func
are also declarations. I'm not sure why they were added as goDirective
back then. If you need to access them, I think the better way would be using goVar
and goConst
, instead of combining them. At least that would give it a correct meaning (even if it's more fine grained now)
syntax/go.vim
Outdated
endif | ||
|
||
" Single-line var, const, and import. | ||
syn match goSingleImport /\(import\|var\|const\) [^(]\@=/ contains=goImport,goVarConst |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
goSingleImport -> goSingleDecl
syntax/go.vim
Outdated
" Single-line var, const, and import. | ||
syn match goSingleImport /\(import\|var\|const\) [^(]\@=/ contains=goImport,goVarConst | ||
|
||
"syn region goImport start='var ' end=''contains=goVarConst |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be removed probably?
This adds
foldmethod=syntax
folding forimport
,var
, andconst
blocks.I added a new
g:go_fold_enable
setting to selectively enable which regions getfolded. I find this useful personally as I only want to fold
import
blocks.Future extension to this might be:
struct
andinterface
, to selectively foldtype foo struct { .. }
andtype foo interface { .. }
definitions;package
, to fold the package-level comment.But that's another PR for another day ;-)
Fixes: #963