Hey guys,
I’m trying to write a generic plugin that performs arbitrary operations on your current selection in sublimetext. The usage I had in mind was that youd have a globals alias to the command, which is a function that accepts a function as a parameter – that function itself accepting and returning a single string. Example:
selmod(string.upper)
or
selmod(lambda s: str(len(s)))
Writing the plugin itself was simple, but for some reason when I try to pass a lambda or other function as a keyword argument, it claims its None. Heres my code:
class Selmod(sublime_plugin.TextCommand):
def run(self, edit, func=None):
for region in self.view.sel():
text = self.view.substr(region)
self.view.replace(edit, region, func(text))
But when I try to invoke it from the console, i get this:
>>> view.run_command("selmod", {"func": lambda s: 'test'})
Traceback (most recent call last):
File "./sublime_plugin.py", line 276, in run_
File "./selrep.py", line 9, in run
self.view.replace(edit, region, func(text))
TypeError: 'NoneType' object is not callable
Any ideas?