Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compress pptxt report of adjacent spaces/dashes #641

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions src/guiguts/tools/pptxt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,7 @@ def adjacent_spaces_check() -> None:
if re.search(r"\s\s+?", line) and not re.search(r"^\s+?", line):
no_adjacent_spaces_found = False
# Generate a new dialog line for each match on the line.
report_all_occurrences_on_line(r"\s\s+", line, line_number)
report_multiple_occurrences_on_line(r"\s\s+", line, line_number)

line_number += 1

Expand Down Expand Up @@ -1324,6 +1324,33 @@ def double_dash_replace(matchobj: re.Match) -> str:
return matchobj.group(1) + "—" + matchobj.group(2)


def report_multiple_occurrences_on_line(
pattern: str, line: str, line_number: int
) -> None:
"""Report multiple occurrences in one message for this line.

Args:
pattern: A regex of the pattern to be matched and highlighted.
line: The string on which to match the pattern.
line_number: The line number of the line in the file.
"""

matches = list(re.finditer(pattern, line))
if not matches:
return
# Get start/end of first/last error on line.
error_start = matches[0].start()
error_end = matches[-1].end()
# Add record to the dialog with prefix if repeated matches.
checker_dialog.add_entry(
line,
IndexRange(f"{line_number}.{error_start}", f"{line_number}.{error_end}"),
error_start,
error_end,
error_prefix=f"(x{len(matches)}) " if len(matches) > 1 else "",
)


def report_all_occurrences_on_line(pattern: str, line: str, line_number: int) -> int:
"""Abstraction of dialog code that's used repeatedly for reporting.

Expand Down Expand Up @@ -1847,7 +1874,7 @@ def dash_review() -> None:
for record in a_hh:
line_number = record[0]
line = record[1]
report_all_occurrences_on_line(r"(\p{Pd}\p{Pd}+)", line, line_number)
report_multiple_occurrences_on_line(r"(\p{Pd}\p{Pd}+)", line, line_number)

# Report hyphen-minus

Expand Down
Loading