A
A
Artem Mudryak2015-10-11 16:50:45
Sublime Text
Artem Mudryak, 2015-10-11 16:50:45

How to call my plugin written in Sublime Text 2?

Good day.
I want to write my plugin for Sublime Text 2, but I don't understand how to run it.
I read this article on Habré habrahabr.ru/post/136529 , as well as this (first part) code.tutsplus.com/tutorials/how-to-create-a-sublim... .
By Habr created a new plugin, set hotkeys, left only "Hello World" from the code, saved it.
I try to call it and .... nothing happens!
Maybe I'm doing something wrong? Or am I looking in the wrong place?
Please tell me how, from start to finish, run your plugin on Sublime Text 2 and see its results?
If there is somewhere to read - I will also look with gratitude.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Artem Mudryak, 2015-10-12
@artem_1403

Alexander, thanks for the hint, but it didn't quite help :)
But I still understood what my problem was!
It's all about how to name the class and how to call it later via hotkeys!
I could not understand in any way that if I call a class

class SqlBeautifierCommand(sublime_plugin.TextCommand):

(and be sure to highlight the keywords in the title in capital letters)
Then you will need to call it using hot keys like this:
[
   { "keys": ["ctrl+m","ctrl+b"], "command": "sql_beautifier" }
]

I will emphasize that the word Command in the name of the class does not play a role (at least, I have not yet understood what it is for, it also works without it).
Results:
Here is the code for Hello World, with an arbitrary class name (stuff for me):
import sublime, sublime_plugin

class SqlBeautifierCommand(sublime_plugin.TextCommand):
  def run(self, edit):
    self.view.insert(edit, 0, "Hello, World!")

And the keyboard shortcut to call this plugin (press ctrl and the m and b keys in sequence):
[
   { "keys": ["ctrl+m","ctrl+b"], "command": "sql_beautifier" }
]

Hope it helps someone :)

A
Alexander Ruchkin, 2015-10-11
@VoidEx

In the Packages folder, put your *.py file (in a subfolder with the name of your plugin, although you can just put it in the User folder for testing) with the ExampleCommand from the link you provided.
Then in the console (ctrl+`):

import sublime
sublime.active_window().active_view().run_command('example')

If it works, then the command was picked up, now you need to register it somewhere:
1. in ctrl-p commands - a file with the .sublime-commands extension, also in the plugin folder, but it will work in User
2. in the menu - .sublime -menu
3. to the context menu - Context.sublime-menu
4. to the keyboard shortcut - .sublime-keymap
I think you can find examples.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question