Skip to content
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

Merged
merged 3 commits into from
Jul 22, 2017
Merged

Fold import, var, and const blocks #1339

merged 3 commits into from
Jul 22, 2017

Conversation

arp242
Copy link
Contributor

@arp242 arp242 commented Jun 30, 2017

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

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
Copy link
Owner

@fatih fatih left a 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']
<
Copy link
Owner

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.

Copy link
Contributor Author

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.

Copy link
Owner

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'*
Copy link
Owner

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
Copy link
Owner

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
Copy link
Owner

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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be removed probably?

@fatih fatih merged commit d5f5505 into fatih:master Jul 22, 2017
@arp242 arp242 deleted the foldmore branch September 10, 2017 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants