0
0

More than 1 year has passed since last update.

Sublime Text 自作Plugin Scripts API TIPS 個人用メモ

Last updated at Posted at 2022-01-11

選択範囲が無い場合、行を取得する。

        for region in self.view.sel():
            if region.empty():
                region = self.view.line(region)

region

選択範囲を示すregionは、開始地点と終了地点の数字の入ったオブジェクト

region = sublime.Region(0, 10)##Region自作。0文字目から10文字目
print(region)
##regionの開始地点と終了地点の数字取得
reg1 = str(region.begin())
reg2 = str(region.end())

自作誤字脱字選択肢表示機能

いちいちlinterとかインストールするのとか面倒くさいので自分で作りたいとき。

        i=0
##選択範囲を数字で取得
            reg1 = str(region.begin())
            reg2 = str(region.end())
##置き換え文字列
            replace = "テスト"
##置き換え文字列用minihtml
            links = '<a href=\'subl:testtest {"reg1":%s,"reg2":%s,"rep":"%s"}\'>te2d</a>' % (reg1,reg2,replace)
            # links = '<a href=\'subl:testtest {"reg1":0}\'>tesdt2</a>'
##検索文字列
        for region in view.find_all(' '):
            i =i+1
##viewへ範囲表示と選択肢部分構築。同じ文字列を建築しても、それぞれ別々でキー設定しないといけないので、forループで構築する。
            view.add_regions('HighlightTest'+str(i),
                         [region], 
                         "region.redish",
                         "dot",
                         sublime.DRAW_NO_FILL+sublime.DRAW_STIPPLED_UNDERLINE+sublime.DRAW_NO_OUTLINE,
                         [links]
                         )
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0