Skip to content

Commit a0c9333

Browse files
committed
Optimizes Line-Matching.
auto_match_words setting to only match the filter against whole words.
1 parent 918b853 commit a0c9333

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

logview.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ class LogView:
4747
"none": sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE
4848
}
4949

50+
regexPrefix = "(?<![\\w])("
51+
regexSuffix = ")(?![\\w])"
52+
5053
def highlight(self, view, regex, regionName, scope, icon, regionFlags):
5154
if (regex == "") or (regex == None):
5255
return []
@@ -57,7 +60,7 @@ def highlight(self, view, regex, regionName, scope, icon, regionFlags):
5760
if (numFoundRegions > 0):
5861
# Expand all regions to match the whole line and mark the line with the given scpe
5962
for i in range(0, numFoundRegions):
60-
foundRegions[i] = view.expand_by_class(foundRegions[i], sublime.CLASS_LINE_START | sublime.CLASS_LINE_END)
63+
foundRegions[i] = view.line(foundRegions[i])
6164
view.add_regions(regionName, foundRegions, scope, "Packages/LogView/" + icon + ".png", regionFlags);
6265

6366
return foundRegions
@@ -68,13 +71,20 @@ def markupView(self, view, statusAnimation):
6871
errorRegex = settings.get("error_filter", "error|fail|exception")
6972
errorScope = settings.get("error_scope", "markup.deleted")
7073
errorStatusCaption = settings.get("error_status_caption", "Errors")
71-
warningRegex = settings.get("warning_filter", "warning|not found|[^\w]defer")
74+
warningRegex = settings.get("warning_filter", "warning|not found|defer(ed)?")
7275
warningScope = settings.get("warning_scope", "markup.changed")
7376
warningStatusCaption = settings.get("warning_status_caption", "Warnings")
74-
markRegex = settings.get("mark_filter", "[^\w](start|quit|end|shut(ing)* down)[^\w]")
77+
markRegex = settings.get("mark_filter", "start(ing|ed)?|quit|end|shut(ing)? down")
7578
markScope = settings.get("mark_scope", "markup.inserted")
7679
markStatusCaption = settings.get("mark_status_caption", "Marks")
7780
highlighStyle = settings.get("highlight_style", "underline")
81+
autoMatchWords = settings.get("auto_match_words", True)
82+
83+
# If auto_match_words is set to true, extend the regular expressions with lookarounds to only match words.
84+
if (autoMatchWords):
85+
errorRegex = self.regexPrefix + errorRegex + self.regexSuffix
86+
warningRegex = self.regexPrefix + warningRegex + self.regexSuffix
87+
markRegex = self.regexPrefix + markRegex + self.regexSuffix
7888

7989
# Determin the falgs to set on the region for correct highlighting
8090
if (highlighStyle in self.regionStyles):
@@ -94,7 +104,7 @@ def markupView(self, view, statusAnimation):
94104
del foundRegions
95105

96106
# Set a bookmark for each region
97-
view.add_regions("bookmarks", bookmarks, "bookmarks", "bookmark", sublime.HIDDEN);
107+
view.add_regions("bookmarks", bookmarks, "bookmarks", "", sublime.HIDDEN);
98108
del bookmarks
99109

100110
# Stop the animation
@@ -141,9 +151,6 @@ def on_clone(self, view):
141151
if (view.settings().get('syntax') == "Packages/LogView/logview.tmLanguage"):
142152
self.prepareView(view)
143153

144-
def on_reload(self, view):
145-
print("reload")
146-
147154
# Called if a text command is executed on the buffer
148155
def on_text_command(self, view, command_name, args):
149156
if (command_name == "set_file_type"):

logview.sublime-settings

+8-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
// Assigns the scope defined in warning_scope to the line if they contain a match for
1919
// this regular expression. Normally the line is marked with the "markup.changed"
2020
// (yellow) scope.
21-
"warning_filter": "warning|not found|[^\\w]defer",
21+
"warning_filter": "warning|not found|defer(ed)?",
2222

2323
// If you want to use another scope for marking errors change the following line:
2424
"warning_scope": "markup.changed",
@@ -30,7 +30,7 @@
3030
// Assigns the scope defined in warning_scope to the line if they contain a match for
3131
// this regular expression. Normally the line is marked with the "markup.inserted"
3232
// (green) scope.
33-
"mark_filter": "[^\\w](start|quit|end|shut(ing)* down)[^\\w]",
33+
"mark_filter": "start(ing|ed)?|quit|end|shut(ing)? down",
3434

3535
// If you want to use another scope for marking errors change the following line:
3636
"mark_scope": "markup.inserted",
@@ -39,6 +39,12 @@
3939
// regular expression. This can be used for I18N.
4040
"mark_status_caption": "Marks",
4141

42+
// If this config option is set to true the reguluar expression set via error_filter,
43+
// warning_filter and mark_filter is automatically extended to only match whole words.
44+
// If you want to use the regular expressions as they are specified, set this value
45+
// to false.
46+
"auto_match_words": true,
47+
4248
// Defines how the error, warning and mark scopes are highlighted.
4349
// Available styles are:
4450
// fill: The background of the matching line is filled with the color defined by the scope.

0 commit comments

Comments
 (0)