Created
October 9, 2013 20:32
-
-
Save gavinblair/6907847 to your computer and use it in GitHub Desktop.
Sublime Text plugin to display the current function in the status bar.
I put it in %APPDATA%/Sublime Text 2/Packages/currentfunction/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Stolen shamelessly from http://www.sublimetext.com/forum/viewtopic.php?f=2&t=4589#p20780