Skip to content

Commit

Permalink
Updating default settings, adding "min_duplicate_count" option
Browse files Browse the repository at this point in the history
  • Loading branch information
LordBrom committed Aug 24, 2021
1 parent fb39c73 commit 4f89edf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 6 additions & 0 deletions highlight_duplicates.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -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" : []
}
16 changes: 13 additions & 3 deletions hightlight_duplicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down Expand Up @@ -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', [])
Expand Down

0 comments on commit 4f89edf

Please sign in to comment.