Is there a setting, a builtin key binding, or package available that would let me copy text from the Status Bar to the pasteboard? Could you point me in the right direction?
Copy text from the Status Bar?
What text are you trying to get?
The only available method of getting status bar text is view.get_status( key )
, but it requires that you know the key
of the particular text you want to extract.
IMO there should be something like view.get_all_statuses()
, which would return an array of tuples containing [ ( key_1, value_1 ), ... ]
Â
Â
A workaround would be to search the plugin you want to extract text from for set_status
& use the string value of their key with the get_status
command.
There’s also a status_message
command that developers can use to post messages, but I don’t believe there is an associated key; so you might not be able to extract the text in that case.
I already looked at the particular plugin that has the message I want, in this case Rubocop, and it uses the key rubocop when posting status bar messages, so I can just assign a hotkey to view.get_status( 'rubocop' )
to get the message? I’ll try that.
I like your suggestion, I could even live with view.get_status_keys()
, but I prefer yours.
I can create a hotkey that issues the command, but How do I get the text to the pasteboard?
Save This @:
/Packages/CopyRubocopStatus/CopyRubocopStatus.py
Â
import sublime, sublime_plugin
class copy_rubocop_status( sublime_plugin.TextCommand ):
def run( self, edit ):
status = self.view.get_status( "rubocop" )
sublime.set_clipboard( status )
Â
Add This @:
Preferences > Key Bindings - User
Â
{
"keys": [ "ctrl+shift+alt+c" ],
"command": "copy_rubocop_status",
},
Thanks for your help. I followed your directions, when I hit the hotkey combo I get a new clipboard entry with “No prinatable characters” I have to move on now, I will fool around with this later.
a little more investigating, if I set status to a literal string, that string is copied to pasteboard. So the problem is that status is not being populated properly. Rubocop sets the status at line 143 of rubocop_listener.py My best guess is that it’s a scoping problem, or possibly some weird issue with the Rubocop status message structure
What happens if you create an override of rubocop_listener.py
& change line 143 to:
view.set_status('rubocop', str('RuboCop: {0}'.format(view_dict[row])))
@fico Thanks for all the help. I made the change you suggested and get the same result.
I got it working here. Change this line:
status = self.view.get_status( "rubocop" )
To:
status = sublime.active_window().active_view().get_status( "rubocop" )
They should not be the same thing?
Why they are getting different results?
Someone know? Is this a bug within Sublime Text
?
Here I when I do:
class GetScopeAlwaysTextCommand( sublime_plugin.TextCommand ):
def run( self, edit ):
// status = self.view.get_status( "scope_always" )
status = sublime.active_window().active_view().get_status( "scope_always" )
print( status )
The first one (commented) get text.plain
which is wrong.
But the second one get the correct result source.octave source.matlab punctuation.definition.brackets.begin.matlab