Sublime Forum

Any way to capture the current theme selector to clipboard?

#1

I don’t know it I’m calling it the right thing: I mean when you are creating a color scheme and hit shift-command-p to get what the current selector is (e.g. “meta.structure.dictionary.json”) so you can style it.

It appears briefly in the status bar, but it is sometimes too long to fit, and disappears after a few seconds.

In TextMate, I usually need to take a quick screen capture of the tooltip that appears.

Having it as text, ready to be pasted into a theme file would be perfect.

0 Likes

#2

You can enter this in the console:

sublime.set_clipboard(view.syntax_name(view.sel()[0].b))
0 Likes

#3

[quote=“jps”]You can enter this in the console:

sublime.set_clipboard(view.syntax_name(view.sel()[0].b)) [/quote]

Great, thanks.

0 Likes

#4

[quote=“jps”]You can enter this in the console:

sublime.set_clipboard(view.syntax_name(view.sel()[0].b)) [/quote]

How could I make this into a custom command?

0 Likes

How to obtain the current scope under the cursor
#5

Tools > New Plugin:

[code]import sublime, sublime_plugin

class ScopeToClipboardCommand(sublime_plugin.TextCommand):
def run(self, edit):
sublime.set_clipboard(self.view.syntax_name(self.view.sel()[0].b))[/code]

Preferences > User Keybindings:

{ "keys": "shift+alt+command+p"], "command": "scope_to_clipboard"  }
0 Likes

#6

Very cool, thanks!

0 Likes

#7

i love you allllllll

0 Likes

#8

Sorry to revive this old post but is there anyway to do this for Sublime 3? I’ve tried to run the command sublime.set_clipboard(view.syntax_name(view.sel()[0].b)) in the console, but am getting the error.

Traceback (most recent call last):
File “”, line 1, in
AttributeError: ‘View’ object has no attribute ‘syntax_name’

what am I missing?!?..

0 Likes

#9

The method is now called “scope_name”.

1 Like

#10

Thank you so much!

0 Likes