Create a plugin that always highlights arbitrary text in Sublime Text 2

Or rather, I just modified plug-in that highlights double-byte space.

AlwaysHighlight.py


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

class AlwaysHighlight(sublime_plugin.EventListener):
    # highlight
    def highlight(self, view):
        pattern = view.settings().get('alwayshighlight_pattern')
        if pattern:
            view.add_regions('AlwaysHighlight', view.find_all(pattern), "invalid", sublime.DRAW_OUTLINED)

    # 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)

The text to be highlighted is specified by a regular expression. Open the settings file with Preferences> Settings --User and write:

    ...
    // "foo"、"bar", Full-width space, full-width alphanumeric characters are always highlighted
    "alwayshighlight_pattern": "foo|bar|[ 0-9A-Za-z]",
    ...

I also put the code on GitHub.

Recommended Posts

Create a plugin that always highlights arbitrary text in Sublime Text 2
Create a plugin that allows you to search Sublime Text 3 tabs in Python
[Sublime Text 2] Always execute a specific file in the project
I tried to make it on / off by setting "Create a plug-in that highlights double-byte space with Sublime Text 2".
"Inline" Sublime Text plugin callbacks with a generator
Create a python3 build environment with Sublime Text3
Create a plugin to run Python Doctest in Vim (2)
Create a plugin to run Python Doctest in Vim (1)
In Python, create a decorator that dynamically accepts arguments Create a decorator
Create a Wox plugin (Python)
Create a function in Python
Create a dictionary in Python
Let's create a script that registers with Ideone.com in Python.
Create code that outputs "A and pretending B" in python
[Python / Django] Create a web API that responds in JSON format
Qiskit: I want to create a circuit that creates arbitrary states! !!
How to create a heatmap with an arbitrary domain in Python
Create a CSV reader in Flask
GOTO in Python with Sublime Text 3
Create a DI Container in Python
Create a binary file in Python
Write a vim plugin in Python
Create a Kubernetes Operator in Python
Create a random string in Python
Create a LINE Bot in Django
Let's create a customer database that automatically issues a QR code in Python
Create a simple GUI app in Python
Create a JSON object mapper in Python
Create a large text file with shellscript
Create a Python-GUI app in Docker (PySimpleGUI)
Create a new dict that combines dicts
[Python] Create a LineBot that runs regularly
[GPS] Create a kml file in Python
Write a simple Vim Plugin in Python 3
Create a bot that boosts Twitter trends
Create a matrix with PythonGUI (text box)
Create a web service in Flask-SQLAlchemy + PostgreSQL
I tried to create a class that can easily serialize Json in Python
I want to create a priority queue that can be updated in Python (2.7)
Create a BOT that displays the number of infected people in the new corona
What to do if a Unicode Encode Error occurs in Sublime Text Python
[Django] Create a form that automatically fills in the address from the zip code
Create a web app that converts PDF to text using Flask and PyPDF2