From fee05f769d4e5aaaf36fefd7b6c244b863fd1768 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 25 Jan 2026 10:32:06 +0000 Subject: [PATCH] Fix C module to match Elisp behavior for last-line overflow handling When is_last && ideal > line_width, the C module now correctly triggers force break logic, matching ekp--dp-cache-elisp behavior. This ensures consistent results between C module and pure Elisp paths. Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com> --- _codeql_detected_source_root | 1 + ekp_c/ekp_kp.c | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) create mode 120000 _codeql_detected_source_root diff --git a/_codeql_detected_source_root b/_codeql_detected_source_root new file mode 120000 index 0000000..fe661d3 --- /dev/null +++ b/_codeql_detected_source_root @@ -0,0 +1 @@ +./ekp_c \ No newline at end of file diff --git a/ekp_c/ekp_kp.c b/ekp_c/ekp_kp.c index 4504bc6..4229432 100644 --- a/ekp_c/ekp_kp.c +++ b/ekp_c/ekp_kp.c @@ -166,8 +166,10 @@ static void process_dp_range(void *arg) max_w += p->hyphen_width; } - /* Too long? */ - if (min_w > line_width) { + /* Too long? Also handle is_last && ideal > line_width. + * This matches Elisp's ekp--dp-cache-elisp which breaks when + * content won't fit even at the end of a paragraph. */ + if (min_w > line_width || (is_last && ideal > line_width)) { /* Force break if nothing else found */ if (k > 1 && work->demerits[k - 1] >= EKP_INFINITY) { int32_t rest = line_width - (p->ideal_prefix[k - 1] - @@ -497,8 +499,10 @@ ekp_result_t *ekp_break_with_prefixes( max_w += hyphen_width; } - /* Too long? Force break at k-1 if no valid break found yet */ - if (min_w > line_width) { + /* Too long? Also handle is_last && ideal > line_width. + * This matches Elisp's ekp--dp-cache-elisp which breaks when + * content won't fit even at the end of a paragraph. */ + if (min_w > line_width || (is_last && ideal > line_width)) { if (k > i + 1 && demerits[k - 1] >= EKP_INFINITY) { /* Force break at previous position with high penalty */ int32_t prev_ideal = ideal_prefix[k - 1] - ideal_prefix[i] - lead_ideal;