LoginSignup
6
6

More than 5 years have passed since last update.

「Sublime Text 2で全角スペースをハイライト表示するプラグインを作る」コメント欄のTipsをマージしてみた。

Posted at

Sublime Text 2で全角スペースをハイライト表示するプラグインを作るのコメント欄をマージしときました。

AlwaysHighlight.py
#!/usr/bin/python
# -*- coding: utf8 -*-
import sublime
import sublime_plugin

class AlwaysHihghlight(sublime_plugin.EventListener):
    # highlight
    def highlight(self, view):
        pattern = view.settings().get('alwayshighlight_pattern')
        if view.settings().get('fullwhitespace_viewable') == True:
            if pattern:
                view.add_regions('AlwaysHighlight',view.find_all(pattern), "invalid", sublime.DRAW_OUTLINED)
        else:
            view.erase_regions('highlight')
    # Called after changes have been made to a view.
    # @override
    def on_modified(self, view):
        self.highlight(view)

    # Called when a view gains input focus.
    # @override
    def on_activated(self, view):
        self.highlight(view)

    # Called when the file is finished loading.
    # @override
    def on_load(self, view):
        self.highlight(view)

設定は下記

Preferences.sublime-settings
    // 全角スペースのハイライトをするかどうか
    "fullwhitespace_viewable" : true,
    //"fullwhitespace_viewable" : Flase,
    // "foo"、"bar"、全角空白、全角英数字を常にハイライトする
    "alwayshighlight_pattern": "foo|[ 0-9A-Za-z]",

皆様に感謝!

6
6
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
6
6