表題通り。
こんな感じ。誤字脱字にハイライトを表示するシンプルなプラグイン。変換候補とかも出そうと思ったけれど、ハイライトだけで十分なので、ハイライトだけ。
ツール>デベロッパー>ニュープラグイン
でテンプレートを出し、それが保存されるPackagesディレクトリに「word_caveat」ディレクトリを作り、その中に色々と作っていく。
プラグイン本体。
WordCaveatCommand.py
import sublime
import sublime_plugin
def settings_template(self, add_flag):
settings = sublime.load_settings('WordCaveat.sublime-settings')
words = settings.get('words')
for region in self.view.sel():
sel_string = self.view.substr(region)
if len(sel_string) > 0:
if add_flag:
words += [sel_string]
else:
if sel_string in words:
words.remove(sel_string)
settings.set("words", words)
sublime.save_settings("WordCaveat.sublime-settings")
class WordCaveatCommand(sublime_plugin.EventListener):
def on_modified(self, view):
settings = sublime.load_settings('WordCaveat.sublime-settings')
words = settings.get('words')
regions = []
for word in words:
regions += view.find_all(word)
view.add_regions("WordCaveat", regions, "region.redish",
"dot",
sublime.DRAW_NO_FILL)
class WordCaveatAddCommand(sublime_plugin.TextCommand):
def run(self, edit):
settings_template(self, True)
class WordCaveatRemoveCommand(sublime_plugin.TextCommand):
def run(self, edit):
settings_template(self, False)
WordCaveatCommandでセッティングから単語リストを読み出し、文章が書き込まれるたびに、そこにハイライトをつける。
WordCaveatAddCommandで新たな単語を追加する。
WordCaveatRemoveCommandで選択した単語をリストから削除する。
Context.sublime-menu
[
{ "command": "word_caveat_add","caption":"ハイライト単語追加"},
{ "command": "word_caveat_remove","caption":"選択ハイライト単語削除"},
]
右クリックに単語追加用と削除用のメニューを追加する。
Main.sublime-menu
[
{
"mnemonic": "n",
"caption": "Preferences",
"id": "preferences",
"children": [
{
"mnemonic": "P",
"caption": "Package Settings",
"id": "package-settings",
"children": [
{
"caption": "Word Caveat",
"children": [
{
"caption": "Settings – Default",
"args": {
"file": "${packages}/word_caveat/WordCaveat.sublime-settings"
},
"command": "open_file"
},
{
"caption": "Settings – User",
"args": {
"file": "${packages}/User/WordCaveat.sublime-settings"
},
"command": "open_file"
},
{
"caption": "-"
}
]
}
]
}
]
}
]
設定のパッケージセッティングにユーザーセッティングとパッケージセッティングファイルへのリンクを作る。
WordCaveat.sublime-settings
{
"words": [
"あんた",
]
}
プラグインのデフォルト設定ファイルを作る。
これで、誤字脱字の部分を右クリックし、単語を追加すると、以後、単語が出るとハイライトしてくれるようになる。やったぜ!