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 package-level comments #1377

Merged
merged 1 commit into from
Sep 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,8 @@ BUG FIXES:

FEATURES:

* We now have folding support based on Go syntax. Check out the
[demo](https://twitter.com/fatih/status/893843722093330433) to see it in
action. To enable it you have to set the following vim setting: `set
foldmethod=syntax`. Currently it folds at block (`{ }`), var and const level.
These can be individually disabled/enabled if wished. For more info please
read the documentation for the `g:go_fold_enable` setting. [gh-1339]
* `:GoFiles` accepts now an argument to change the type of files it can show.
By default it shows`.go source files` but now it can be changed to show
various kind of files. The full list can be seen via `go list --help` under
the `// Source Files` section [gh-1372] i.e:
* We now have folding support based on Go syntax. To enable it you have to set the following Vim setting: `set foldmethod=syntax`. Currently it folds blocks (`{ }`), `import`, `var`, and `const` blocks, and package-level comments. These can be individually disabled/enabled if desired. For more info please read the documentation for the `g:go_fold_enable` setting. [gh-1339] [gh-1377]
* `:GoFiles` accepts now an argument to change the type of files it can show. By default it shows`.go source files` but now it can be changed to show various kind of files. The full list can be seen via `go list --help` under the `// Source Files` section [gh-1372] i.e:

```
:GoFiles CgoFiles // shows .go sources files that import "C"
Expand Down
9 changes: 5 additions & 4 deletions doc/vim-go.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1618,13 +1618,14 @@ Control syntax-based folding which takes effect when 'foldmethod' is set to
`syntax`.
You can enable specific fold regions by setting an array. Possible values are:

- "block" `{` .. `}` blocks.
- "import" `import` block.
- "varconst" `var` and `const` blocks.
- "block" `{` .. `}` blocks.
- "import" `import` block.
- "varconst" `var` and `const` blocks.
- "package_comment" The package comment.

By default they're all enabled:
>
let g:go_fold_enable = ['block', 'import', 'varconst']
let g:go_fold_enable = ['block', 'import', 'varconst', 'package_comment']
<
Enable folding of only imports:
>
Expand Down
17 changes: 14 additions & 3 deletions syntax/go.vim
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ endif
let s:fold_block = 1
let s:fold_import = 1
let s:fold_varconst = 1
let s:fold_package_comment = 1
if exists("g:go_fold_enable")
if index(g:go_fold_enable, 'block') == -1
let s:fold_block = 0
Expand All @@ -102,6 +103,9 @@ if exists("g:go_fold_enable")
if index(g:go_fold_enable, 'varconst') == -1
let s:fold_varconst = 0
endif
if index(g:go_fold_enable, 'package_comment') == -1
let s:fold_package_comment = 0
endif
endif

syn case match
Expand Down Expand Up @@ -403,15 +407,22 @@ if g:go_highlight_build_constraints != 0
hi def link goBuildCommentStart Comment
hi def link goBuildDirectives Type
hi def link goBuildKeyword PreProc
endif

if g:go_highlight_build_constraints != 0 || s:fold_package_comment
" One or more line comments that are followed immediately by a "package"
" declaration are treated like package documentation, so these must be
" matched as comments to avoid looking like working build constraints.
" The he, me, and re options let the "package" itself be highlighted by
" the usual rules.
syn region goPackageComment start=/\v(\/\/.*\n)+\s*package/
\ end=/\v\n\s*package/he=e-7,me=e-7,re=e-7
\ contains=@goCommentGroup,@Spell
exe 'syn region goPackageComment start=/\v(\/\/.*\n)+\s*package/'
\ . ' end=/\v\n\s*package/he=e-7,me=e-7,re=e-7'
\ . ' contains=@goCommentGroup,@Spell'
\ . (s:fold_package_comment ? ' fold' : '')
exe 'syn region goPackageComment start=/\v\/\*.*\n(.*\n)*\s*\*\/\npackage/'
\ . ' end=/\v\n\s*package/he=e-7,me=e-7,re=e-7'
\ . ' contains=@goCommentGroup,@Spell'
\ . (s:fold_package_comment ? ' fold' : '')
hi def link goPackageComment Comment
endif

Expand Down