Nice, I’d like to expand this to css selectors as well. Especially when in scss files, the nesting can get out of control!
[quote=“nizur”]Very nice and very much appreciated! I took what you started and changed it to:
[code]import sublime, sublime_plugin
class FunctionInStatusListener(sublime_plugin.EventListener):
def on_deactived(self, view):
view.erase_status(‘function name’)
def on_close(self, view):
view.erase_status('function name')
def on_activated(self, view):
cf = self.get_current_function(view)
if cf is None:
view.erase_status('function name')
else:
view.set_status('function name', 'Function: ' + cf)
def on_selection_modified(self, view):
cf = self.get_current_function(view)
if cf is None:
view.erase_status('function name')
else:
view.set_status('function name', 'Function: ' + cf)
def get_current_function(self, view):
sel = view.sel()[0]
functionRegs = view.find_by_selector('entity.name.function')
cf = None
for r in reversed(functionRegs):
if r.a < sel.a:
cf = view.substr(r)
break
return cf
[/code]
That seems to work for JS, PHP and Python for me. It’s rough, but it does the job well enough for me![/quote]