shagabutdinov / sublime-snippet-caller

Snippet system on top of default sublime snippets
Other
6 stars 3 forks source link

Using sublime regex on eval variables doesn't work #3

Closed VorpalBlade closed 9 years ago

VorpalBlade commented 9 years ago

Using sublime snippets built in support for regular expressions (for example ${foo/a/b/ig}) on snippet variables doesn't work if the variables come from <eval>. (It does still work for the built in variables like TM_FILENAME and for "positional" variables.)

It may be related to that ${foo} syntax doesn't work on eval variables either. (It does still work for normal variables). This would be a useful feature to support anyway, since without that, doing something like ${foo}othertext would not be possible when foo comes from eval.

VorpalBlade commented 9 years ago

Also worth mentioning is that using eval variables as default values should work. For example ${1:${foo/a/b/ig}}

shagabutdinov commented 9 years ago

Check ${1:$foo} snippet - it should work. ${1:${foo/a/b/ig}} does not work because ${foo/a/b/ig} does not work.

shagabutdinov commented 9 years ago

As for regexps: it is not supported, sorry; I'll get crazy adding full snippet support here, especially for border cases with nested brackets and escaped backslashes (here is need parser for snippets, not just one regexp as I did).

However, if you would like to add regexp supports to snippets, you can start digging here: snippet_info.py in method _get_content_with_values(self, values).

Also you can use native python regexps in eval section: {"foo": __import__('re').sub(r'a', 'b', 'variable-content')}

I'll add description of this issue to readme.

shagabutdinov commented 9 years ago

Closed in 25522a40d2a11d844bc932f13dde9235244b5fe2

VorpalBlade commented 9 years ago

I still thing that ${foo} is useful though. For example I needed the following:

typedef boost::shared_ptr<$class> ${class}SP;

That doesn't work currently either.

VorpalBlade commented 9 years ago

I will see if I get time to look into this issue at some point. Regex are useful still, since due to the very limited nature of <eval> syntax, I moved all my code into an external python module that returns a dict. It is somewhat annoying and messy to have to add every variant of a variable into that script (i.e. foo/bar/quux as well as foo::bar::quux if you are dealing with C++ paths and namespaces).

shagabutdinov commented 9 years ago

Tried to fix in 495753377fa2bcff535bedc3ba73147666c92026 commit. Please check if your snippet typedef boost::shared_ptr<$class> ${class}SP; works.

shagabutdinov commented 9 years ago

I moved all my code into an external python module that returns a dict

I use same approach in my snippets: eval serves as bridge between my python modules and snippet. I didn't found way to eval several lines of code and get the result of execution in python.

VorpalBlade commented 9 years ago

It appears that in the very last revision, no snippets work at all. I get no messages in the python console of sublime, and nothing is inserted at all.

VorpalBlade commented 9 years ago

Correction: Some snippets work, but I see no pattern in which ones. I will debug this further.

VorpalBlade commented 9 years ago

${1:$foo} is one thing that breaks it now. ${foo} does however work. Yay. I will try to look into how to write a proper parser at some point soon. ${1:${foo}} also doesn't work by the way

shagabutdinov commented 9 years ago

I've found bug only after I've push changes; I refixed it in commit b7c974129c9fe0c084d18e239ff2e6ce47f6b818, please check it again.

VorpalBlade commented 9 years ago

Appears to work now.