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

Add a %PARENT% variable #131

Open
Shadow53 opened this issue Oct 9, 2018 · 2 comments
Open

Add a %PARENT% variable #131

Shadow53 opened this issue Oct 9, 2018 · 2 comments

Comments

@Shadow53
Copy link
Contributor

Shadow53 commented Oct 9, 2018

This is particularly for the Go template, since it currently assumes that all files are part of a main package. In most cases, the parent folder of the file has the same name as the package for its containing files. With a %PARENT% variable, the line in the Go template could be changed from

package main

to

package %PARENT%

which will be correct more often.

As a side note, I'm proposing the name %PARENT% instead of something like %FOLDER% since the latter could be understood to expand to the absolute path of the containing folder.

@Shadow53
Copy link
Contributor Author

Shadow53 commented Oct 9, 2018

I somehow missed the bit of documentation about user-defined variables. I've added the following to my NeoVim init.vim, which implements the above.

let g:templates_user_variables = [
    \ ['PARENT', 'GetParentDir']
    \ ]

function! GetParentDir()
    return expand('%:p:h:t')
endfunction

@aperezdc
Copy link
Owner

@Shadow53 I guess it wouldn't hurt to have %PARENT% added, maybe with a more descriptive name like %PARENT_DIR_NAME% — but as you have discovered it's possible to add it anyway as an user variable so I won't be in a hurry to implement it myself. It's not difficult to add it, so for now I will leave it marked as “good first bug” so it can be picked by anyone willing to start contributing to the project 😉

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

No branches or pull requests

2 participants