Fix: words with embedded hyphens now split at hyphens instead of using hyphenation algorithm
Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
This commit is contained in:
parent
a855bce99b
commit
5b8a328855
22
ekp.el
22
ekp.el
@ -175,6 +175,18 @@ Each takes ideal, stretch (+), and shrink (-) values."
|
|||||||
"[A-Za-z'\\-\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF\u0100-\u024F\u1E00-\u1EFF]"
|
"[A-Za-z'\\-\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF\u0100-\u024F\u1E00-\u1EFF]"
|
||||||
"Regexp matching Latin characters including accented forms.")
|
"Regexp matching Latin characters including accented forms.")
|
||||||
|
|
||||||
|
(defun ekp--split-hyphenated-word (word)
|
||||||
|
"Split WORD at existing hyphens into parts with hyphens attached.
|
||||||
|
E.g., \"help-echo\" -> (\"help-\" \"echo\").
|
||||||
|
Does NOT apply dictionary hyphenation - just uses existing hyphens."
|
||||||
|
(let* ((segments (split-string word "-" t)) ; t = omit empty/null strings
|
||||||
|
(num-segs (length segments)))
|
||||||
|
(cl-loop for seg in segments
|
||||||
|
for i from 0
|
||||||
|
collect (if (< i (1- num-segs))
|
||||||
|
(concat seg "-")
|
||||||
|
seg))))
|
||||||
|
|
||||||
(defun ekp--split-with-hyphen (string)
|
(defun ekp--split-with-hyphen (string)
|
||||||
"Split STRING into boxes with hyphenation points marked.
|
"Split STRING into boxes with hyphenation points marked.
|
||||||
Returns (boxes-vector . hyphen-positions-vector)."
|
Returns (boxes-vector . hyphen-positions-vector)."
|
||||||
@ -185,12 +197,16 @@ Returns (boxes-vector . hyphen-positions-vector)."
|
|||||||
(format "^\\([[{<„‚¿¡*@\"']*\\)\\(%s+\\)\\([]}>.,*?\"']*\\)$"
|
(format "^\\([[{<„‚¿¡*@\"']*\\)\\(%s+\\)\\([]}>.,*?\"']*\\)$"
|
||||||
ekp--latin-regexp)
|
ekp--latin-regexp)
|
||||||
box)
|
box)
|
||||||
;; Latin word: apply hyphenation
|
;; Latin word (possibly with embedded hyphens)
|
||||||
(let* ((left (match-string 1 box))
|
(let* ((left (match-string 1 box))
|
||||||
(word (match-string 2 box))
|
(word (match-string 2 box))
|
||||||
(right (match-string 3 box))
|
(right (match-string 3 box))
|
||||||
(parts (ekp-hyphen-boxes
|
;; If word contains hyphens, split at those points only (no further hyphenation)
|
||||||
(ekp-hyphen-create ekp-latin-lang) word))
|
;; Otherwise, apply dictionary hyphenation
|
||||||
|
(parts (if (string-match-p "-" word)
|
||||||
|
(ekp--split-hyphenated-word word)
|
||||||
|
(ekp-hyphen-boxes
|
||||||
|
(ekp-hyphen-create ekp-latin-lang) word)))
|
||||||
(n (length parts)))
|
(n (length parts)))
|
||||||
(when left (setcar parts (concat left (car parts))))
|
(when left (setcar parts (concat left (car parts))))
|
||||||
(when right (setcar (last parts)
|
(when right (setcar (last parts)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user