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

Ability to #include a file with all lines indented #68

Open
computator opened this issue Jul 14, 2024 · 2 comments
Open

Ability to #include a file with all lines indented #68

computator opened this issue Jul 14, 2024 · 2 comments

Comments

@computator
Copy link

I would like to be able to include one file inside another, but have the contents of the included file all indented by a certain amount. For example:

test.inc

multiline
example

test.yaml

example:
  content: |
    #include_indented test.inc
  other: asdf

Intended result:

example:
  content: |
    multiline
    example
  other: asdf

I am not sure if this is currently possible with gpp only? If so, I couldn't figure out how. Perhaps there's a way to use the output of include in a macro to then prefix all the lines with a string?

The only solution I could come up with so far is using exec, which I would prefer to avoid if possible.

@logological
Copy link
Owner

There's no built-in support for this, though your YAML example makes for a compelling use case.

I suspect that you could kludge together a solution that defines the newline itself as a macro that echoes a certain number of spaces followed by its argument. For this you'd need to define a new mode that allows the newline to be a macro name, and everything that follows it up to the next newline its argument. You'd have to activate this mode before the include macro, and probably turn it off again afterwards. However, I don't have time to experiment to test this suspicion.

Probably exec would be a simpler solution. (Either that, or I actually implement an include_indented meta-macro, though I won't have time to do that soon.)

@computator
Copy link
Author

Thanks for the response. I might have to try that out!

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