Commit Graph

28 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
af855e3394 refactor: Linus-style code quality improvements across Elisp and C modules
- Extract shared binary search from duplicate ekp--hyphenate-p/ekp--flagged-p
- Remove duplicate ekp-root-dir definition (shadowed ekp-utils.el version)
- Remove dead ekp-clear-caches from ekp-utils.el (cleared non-existent var)
- Replace hardcoded 'zsh' with shell-file-name for portability
- Deduplicate module reload: shared ekp--module-reload for Rust/C
- Add NULL guard for ekp_global in ekp_paragraph.c (crash prevention)
- Track actual thread count in pool to fix destroy joining wrong count
- Normalize line endings (CRLF→LF) in ekp-utils.el

Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
2026-02-10 12:18:00 +00:00
copilot-swe-agent[bot]
5e3571f689 Fix: preserve paragraph indentation, strip only line-break artifact spaces
Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
2026-01-25 13:09:59 +00:00
copilot-swe-agent[bot]
8e39dc2b83 Fix: DP line metrics now excludes leading/trailing space box widths to match rendering
Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
2026-01-25 12:55:58 +00:00
copilot-swe-agent[bot]
c60ddb3903 Fix: DP algorithm now excludes leading/trailing space box widths to match rendering behavior
Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
2026-01-25 12:41:04 +00:00
copilot-swe-agent[bot]
836ff75c89 Refactor: use efficient char list building instead of string concat in loop
Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
2026-01-25 12:30:08 +00:00
copilot-swe-agent[bot]
5b8a328855 Fix: words with embedded hyphens now split at hyphens instead of using hyphenation algorithm
Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
2026-01-25 12:28:09 +00:00
copilot-swe-agent[bot]
32021fbe35 Implement Looseness, Threshold Pruning, and Flagged Penalties
Feature 1: Looseness (Complete Implementation)
- Added alt-paths hash table to track alternative paths by (position, line-count)
- Modified DP loop to track all paths reaching each position
- ekp--dp-trace-breaks-with-looseness uses alt-paths to find closest match
- Added ekp--dp-trace-alt-path helper with safety limit

Feature 2: Threshold Pruning
- Added ekp-threshold-factor variable (default 0 = disabled)
- Paths with demerits > best × (1 + factor) are skipped
- Tracks best-end-demerits during DP for pruning decisions

Feature 3: Flagged Penalties (Forced Breaks)
- Added flagged-positions field to ekp-para struct
- Added ekp-flagged-penalty variable (negative = preferred)
- Added ekp--flagged-p with O(log n) binary search
- Modified DP to always accept flagged breaks

Tests:
- ekp-test-unit--hyphenate-p-binary-search
- ekp-test-unit--flagged-p-binary-search
- ekp-test-unit--alt-paths-hash
- ekp-test-unit--threshold-factor
- ekp-test-unit--flagged-penalty
- Updated ekp-test-unit--struct-access for new fields

Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
2026-01-25 11:35:30 +00:00
copilot-swe-agent[bot]
b70affb9ef Optimize hyphen position lookup O(n)->O(log n) and add named constants
Performance:
- ekp--hyphenate-p: O(n) cl-find -> O(log n) binary search
- is_hyphen_break: O(n) linear -> O(log n) binary search
- is_hyphen_pos: O(n) linear -> O(log n) binary search

In O(n²) DP loop, this reduces worst-case complexity from O(n³) to O(n² log n)

Code quality:
- Add ekp-consecutive-hyphen-penalty (was hardcoded 100)
- Add ekp-forced-break-penalty (was hardcoded 10000)
- Add ekp-last-line-short-penalty (was hardcoded 50)
- Update ekp-looseness docstring noting partial implementation

Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
2026-01-25 11:15:42 +00:00
copilot-swe-agent[bot]
fb58a9b19a Fix remaining global glue param usages in DP and glue distribution functions
Code review found additional functions using global glue params instead
of para's stored params:
- ekp--compute-stretch-capacity: now takes para param
- ekp--compute-shrink-capacity: now takes para param
- ekp--line-badness-and-fitness: now takes para param
- ekp--dp-compute-line-demerits: now takes para param
- ekp--distribute-gap-adjustment: now takes para param

All capacity/distribution calculations now use para's stored glue params
for full consistency across multi-font paragraphs.

Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
2026-01-25 11:03:27 +00:00
copilot-swe-agent[bot]
333618bb57 Fix glue parameter caching inconsistency for multi-font paragraphs
When multiple paragraphs with different fonts were processed, subsequent
executions would use wrong glue parameters from the cache. This caused
misalignment because different fonts have different spacing values.

Changes:
- Add glue-params field to ekp-para struct to store params at creation
- Add helper functions: ekp--para-glue-ideal/shrink/stretch/min/max
- Update all C module interface functions to use para's stored params
- Update all glue computation functions for consistency

Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
2026-01-25 10:52:45 +00:00
Kinneyzhang
a790aa87c3 update 2026-01-25 18:23:33 +08:00
Kinneyzhang
6cf6f75f71 fix bugs of C moudule 2026-01-25 16:53:23 +08:00
Kinneyzhang
c88bbdd395 add dynamic moudle to improve prefermance 2026-01-25 13:50:46 +08:00
Kinneyzhang
91d9bbc1e9 process spaces between words 2026-01-25 01:17:18 +08:00
Kinneyzhang
6421f6b1fb refactor ekp cache and code improve 2026-01-24 22:40:53 +08:00
Kinneyzhang
68b46f8337 code improve 2026-01-24 20:44:38 +08:00
copilot-swe-agent[bot]
dab9ca280e Add optional use-cache parameter to ekp-pixel-justify and ekp-pixel-range-justify
Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
2025-11-29 17:56:42 +00:00
copilot-swe-agent[bot]
f56ec5a520 Fix ekp-text-hash to consider text properties
Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
2025-11-29 17:09:16 +00:00
Kinneyzhang
37baccded8 keep original text properties of string after typesetting 2025-08-22 00:06:14 +08:00
Kinneyzhang
796d3e49d2 misc 2025-08-18 00:35:40 +08:00
Kinneyzhang
3df885bef8 Merge branch 'main' of github.com:Kinneyzhang/emacs-kp 2025-08-09 19:30:12 +08:00
Kinneyzhang
28d6c8ee77 fix bug in ekp-hyphen-str 2025-08-09 19:29:07 +08:00
Kinneyzhang
b6ee3dedcc fix bug when a line only has one word ends with hyphen 2025-07-29 15:43:23 +08:00
Kinneyzhang
eb78e5316f fix _ local variable bug 2025-07-28 16:58:30 +08:00
Kinneyzhang
e9b36312fb update readme 2025-07-27 22:33:28 +08:00
Kinneyzhang
6efd1985d1 update readme 2025-07-27 21:53:46 +08:00
Kinneyzhang
a265357e41 update readme 2025-07-27 21:35:44 +08:00
Kinneyzhang
f7f1f7104c first commit 2025-07-26 23:52:04 +08:00