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

Symbol renaming should work in StringTemplate expressions #89

Open
szhorvat opened this issue Sep 18, 2017 · 3 comments
Open

Symbol renaming should work in StringTemplate expressions #89

szhorvat opened this issue Sep 18, 2017 · 3 comments

Comments

@szhorvat
Copy link
Contributor

It would be nice if renaming worked in this situation:

foo = 3;
Print[foo]
template  = StringTemplate["The number is <*foo+1*>"]

foo appears in the string as well, between the <*...*> expression delimiters. When renaming this symbol, it should also be renamed in the string.

Of course, this should be low priority.

Also, StringTemplate allows specifying non-default expression delimiters, so renaming couldn't possibly work in every situation.

@halirutan
Copy link
Owner

I need to look at the behaviour and understand the consequences better. The problem I see is that something like this is possible (and maybe commonly used?)

foo = 1;
t = StringTemplate["a is <*foo*>"];

TemplateApply[t]

Block[{foo = 2},
 TemplateApply[t]
 ]

Since I don't see the variable inside the template in the Block and cannot make a valid reference, renaming foo would break the code. But maybe this is not an issue.

What I can try is to extract the portion inside <*..*> and make it act as it would be normal code. It's completely similar to Kotlin's string injection and I'm sure I would find how this can be implemented.

@szhorvat
Copy link
Contributor Author

Thinking more about it, I think you're right. There is no good way to determine the scope of symbols in a string template.

It's better to leave things as they are. The current behaviour is not "smart", but it is predictable, which is good.

@szhorvat
Copy link
Contributor Author

szhorvat commented Mar 4, 2019

Also, the delimiters are customizable and not infrequently customized.

I would close this issue for now.

If it's implemented, the thing to look at are "language injections", I think.

https://www.jetbrains.com/help/idea/using-language-injections.html

I thought I got R code injected into an Mma string once, but I can no longer do it. Maybe I am misremembering.

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

No branches or pull requests

2 participants