Skip to content

fold: add -p/--punctuation flag for tiered break-point folding#13327

Open
abdorah wants to merge 1 commit into
uutils:mainfrom
abdorah:main
Open

fold: add -p/--punctuation flag for tiered break-point folding#13327
abdorah wants to merge 1 commit into
uutils:mainfrom
abdorah:main

Conversation

@abdorah

@abdorah abdorah commented Jul 9, 2026

Copy link
Copy Markdown

As I said in an earlier comment in the issue 13316, I've implemented -p / --punctuation as a standalone flag (no argument). When the line hits the width limit, it searches backwards through
the buffered content for the best break point using this priority: sentence-ending punctuation (. ! ? :) -> clause punctuation (, ;) -> whitespace -> any non-alphanumeric character -> hard cut at width.

The rightmost match of the highest-priority tier wins, which maximizes line usage while still preferring semantically meaningful breaks. This is mutually exclusive with -s (enforced by clap). The tiered fallback means a single -p invocation replaces what would otherwise require piping through fold four times with different break characters.

The character sets are hardcoded to ASCII for now but the structure makes it straightforward to extend with locale-aware or CJK punctuation (e.g., 。 、 ?) in a follow-up if needed.

This has changed many things in the way that fold used to work. Since the only attribute that requires 'back tracking' of spaces is space itself, we only had a true or false switch for that, which is perfectly fine, but for an intelligent fold like the one suggested by Dmole, we need more than that, hence the big changes to the fold context.

@codspeed-hq

codspeed-hq Bot commented Jul 9, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 4 improved benchmarks
❌ 5 regressed benchmarks
✅ 322 untouched benchmarks
⏩ 46 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation shuf_lines[100000] 27.4 ms 32.2 ms -14.89%
Simulation fold_many_lines[100000] 57.3 ms 63.6 ms -9.85%
Simulation shuf_repeat_sampling[50000] 4.5 ms 5 ms -9.83%
Simulation fold_custom_width[50000] 22.9 ms 25.2 ms -9.09%
Memory fold_many_lines[100000] 26.7 KB 27.6 KB -3.38%
Simulation false_consecutive_calls 199.4 ns 170.3 ns +17.13%
Simulation true_consecutive_calls 199.4 ns 170.3 ns +17.13%
Simulation unexpand_large_file[10] 291.9 ms 282.3 ms +3.41%
Simulation unexpand_many_lines[100000] 139.3 ms 134.7 ms +3.4%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing abdorah:main (e1eece4) with main (b42827c)

Open in CodSpeed

Footnotes

  1. 46 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Comment thread src/uu/fold/src/fold.rs
.arg(
Arg::new(options::PUNCTUATION)
.long(options::PUNCTUATION)
.short('p')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.short('p')

Please don't add short option which potentially conflicts with GNU's new options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants