FB_init

Wednesday, July 14, 2021

Regular expression plug-in for Sublime Text

 I often need to look at logs. I needed a way to quickly highlight different parts of the logs. I created a plugin for Sublime Text to do that. 

  Here are instructions to create a plugins. 

  Here is my plugin:

import sublime
import sublime_plugin
class ReggaeCommand(sublime_plugin.TextCommand):
def run(self, edit, pattern_args):
p = 0
colours = ["region.cyanish", "region.orangish", "region.bluish"]
icons = ["dot", "circle"]
for pattern_arg in pattern_args:
region_key = 'regexreg'+str(p)
regionst = self.view.get_regions(region_key)
if regionst:
self.view.erase_regions(region_key)
regions = self.view.find_all(pattern_arg)
self.view.add_regions(region_key, regions, colours[p % len(colours)], icons[p % len(icons)], sublime.DRAW_STIPPLED_UNDERLINE)
p = p + 1
view raw reggae_regex.py hosted with ❤ by GitHub

  You can invoke it with

view.run_command("reggae", {"pattern_args": ["pattern 1", "pattern 2"]})