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 ability to use global flag in switch mappings #40

Open
purpleP opened this issue May 30, 2016 · 1 comment
Open

Add ability to use global flag in switch mappings #40

purpleP opened this issue May 30, 2016 · 1 comment

Comments

@purpleP
Copy link

purpleP commented May 30, 2016

In python I've found that sometimes I need to change dictionary to a list of key, value pairs. So from that

{'key1: 'value1', 'key2': 'value2'}

(('key1', 'value1), ('key2', 'value2'))

I don't think it's possible with current implementation because of lack of ability to use g modifier.

@AndrewRadev
Copy link
Owner

I'm sorry it took so long to get to this issue.

The problem with using the "global" modifier is that it's impossible to scope it to only a part of the line. If it were allowed, the substitution would be made on anything else in the line as well, not just in the limits of the dict.

I remember a while ago when I was investigating the issue I tried to come up with some clever implementation for it, but I found out it was much harder than I had thought. I left it around to think about it... which is why it took so long to communicate with you.

Unfortunately, at this time, I don't really have a good solution for you. If I were to implement this independently for something I need, I might use my sideways plugin, or at least its internal plumbing to locate the arguments: https://gist.github.com/AndrewRadev/bd15a43f8cc5f8ec3c01741cb88753bf. But, currently, I have no way to plug this into switch. I've been planning since the beginning to make it more configurable and allow not only substitutions, but the execution of general macros and functions upon a particular pattern, but I never got around to doing it.

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