From 4f89edfddf124e4c3edf8d49a05053f4cebac16b Mon Sep 17 00:00:00 2001 From: Nate Mills Date: Tue, 24 Aug 2021 14:47:55 -0700 Subject: [PATCH] Updating default settings, adding "min_duplicate_count" option --- highlight_duplicates.sublime-settings | 6 ++++++ hightlight_duplicates.py | 16 +++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/highlight_duplicates.sublime-settings b/highlight_duplicates.sublime-settings index 14a4855..2ae0654 100644 --- a/highlight_duplicates.sublime-settings +++ b/highlight_duplicates.sublime-settings @@ -8,9 +8,15 @@ // If true, whitespace gets trimmed off each line before checking for matching lines "trim_white_space" : true, + // If true, letter casing is ignored for checking for matching lines "ignore_case" : false, + // The minimun length a line needs to be in order to be included as a matching line "min_line_length" : 4, + // The minimum number of duplicate lines needed to be found, in order to be included as a matching line + "min_duplicate_count" : 1, + + // Lines that match entries in this list are ignored as matching lines "ignore_list" : [] } diff --git a/hightlight_duplicates.py b/hightlight_duplicates.py index 0d3f478..d46dc89 100644 --- a/hightlight_duplicates.py +++ b/hightlight_duplicates.py @@ -25,6 +25,7 @@ DEFAULT_IS_ENABLED = True DEFAULT_IS_DISABLED = False DEFAULT_MIN_LINE_LENGTH = 4 +DEFAULT_MIN_DUPLICATE_COUNT = 1 def count_lines(lines, view): '''Counts line occurrences of a view using a hash. @@ -42,13 +43,14 @@ def count_lines(lines, view): return counts -def filter_counts(counts, treshold=1): +def filter_counts(counts): '''Filters the line counts by rejecting every line having a count - lower or equal to the treshold, which defaults to 1. + lower or equal to the "min_duplicate_count" user setting, which defaults to 1. ''' filtered = dict() + threshold = getMinDuplicateCount(); for k, v in counts.items(): - if len(v) > treshold: + if len(v) > threshold: filtered[k] = v return filtered @@ -176,6 +178,14 @@ def getMinLineLength(): else: return DEFAULT_MIN_LINE_LENGTH +def getMinDuplicateCount(): + settings = sublime.load_settings('highlight_duplicates.sublime-settings') + minLength = settings.get('min_duplicate_count', DEFAULT_MIN_DUPLICATE_COUNT) + if isinstance(minLength, int): + return max(DEFAULT_MIN_DUPLICATE_COUNT, minLength) + else: + return DEFAULT_MIN_DUPLICATE_COUNT + def getIgnoreList(): settings = sublime.load_settings('highlight_duplicates.sublime-settings') ignoreList = settings.get('ignore_list', [])