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

Option for autocreate to treat empty directories as a package named after that directory #1053

Closed
jimmyfrasche opened this issue Sep 17, 2016 · 2 comments
Labels

Comments

@jimmyfrasche
Copy link
Contributor

I love opening a new file and having the package name filled in.

I don't have much use for the default template, though. I set it to an empty file.

It would be nice if there were an option so that opening a new go file in an empty directory caused the buffer to contain "package d", where d is the name of the directory.

I'd have to change it if I were writing a command, but more often than not it would be the correct action, at least in my case.

@fatih
Copy link
Owner

fatih commented Nov 21, 2016

Hi @jimmyfrasche

If you feel adventerous and want to learn some vimscript (and also contribute to vim-go), the code is here: https://github.com/fatih/vim-go/blob/master/autoload/go/template.vim#L19

You can easily add a new setting, such as go_template_no_file which is added to line 14. So we would check first if go_template_no_file is set to 1 or if l:package_name is -1. Because go_template_no_file would come first, the else branch will be executed, which in return does what you want, basically creating a file with the package name.

@fatih fatih added the feature label Nov 21, 2016
@jimmyfrasche
Copy link
Contributor Author

Thanks for taking the time to lay that out, @fatih.

I've managed to cobble something together after much googling. I'll do some tests locally and try to send a PR tomorrow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants