[cl-typesetting-devel] hyphenation patch

Peter Seibel peter at javamonkey.com
Tue Oct 5 20:19:20 UTC 2004


There was a slight bug in hyphenation.lisp that caused it to sometimes
hyphenate a word after the first character despite
*left-hyphen-minimum* being 2. Below is a patch to hyphenatation.lisp
(as well as a tiny bit of tidying to hyphenatation-fp.lisp to get rid
of some unportable SETFs of undeclared variables.)

If you wanted you might also get rid of the checks in hyphenatation
that the string and word are greater than 4 characters long--since
hyphen-find-hyphen-points observes *left-hyphen-minimum* and
*right-hyphen-minimum* those checks aren't really needed.

-Peter


Index: hyphenation.lisp
===================================================================
--- hyphenation.lisp	(revision 66)
+++ hyphenation.lisp	(working copy)
@@ -4,12 +4,13 @@
 (in-package typeset)
 
 (defun hyphenate-string (string)
-(when (> (length string) 4)
-  (loop with hyphen-points
-        for start = 0 then (position-if #'alpha-char-p string :start (1+ end))
-        for end = (when start (position-if-not #'alpha-char-p string :start (1+ start)))
-        while end
-        when (> (- end start) 4)
-        nconc (mapcar #'(lambda (n) (+ start n))
-		      (nix::hyphen-find-hyphen-points
-		       nix::*american-hyphen-trie* (subseq string start end))))))
+  (when (> (length string) 4)
+    (loop
+       for prev-word-end = 0 then word-end
+       for word-start = (position-if #'alpha-char-p string :start prev-word-end)
+       for word-end = (when word-start (position-if-not #'alpha-char-p string :start word-start))
+       while word-end
+       when (> (- word-end word-start) 4)
+       nconc (mapcar #'(lambda (n) (+ word-start n))
+                     (nix::hyphen-find-hyphen-points
+                      nix::*american-hyphen-trie* (subseq string word-start word-end))))))
Index: hyphenation-fp.lisp
===================================================================
--- hyphenation-fp.lisp	(revision 66)
+++ hyphenation-fp.lisp	(working copy)
@@ -293,8 +293,8 @@
     (setf (exception-trie hyphen-trie) (hyphen-make-trie exceptions 0))
     ))
 
-(setf *american-hyphen-trie* (make-instance 'hyphen-trie :language :american))
-(setf *french-hyphen-trie* (make-instance 'hyphen-trie :language :french))
+(defparameter *american-hyphen-trie* (make-instance 'hyphen-trie :language :american))
+(defparameter *french-hyphen-trie* (make-instance 'hyphen-trie :language :french))
 (read-hyphen-file *american-hyphen-trie*)
 (read-hyphen-file *french-hyphen-trie*)
 


-- 
Peter Seibel                                      peter at javamonkey.com

         Lisp is the red pill. -- John Fraser, comp.lang.lisp




More information about the cl-typesetting-devel mailing list