branch: elpa/spell-fu
commit ed504863f54b639a2bed82e4a82424f2b1308889
Author: Campbell Barton <ideasma...@gmail.com>
Commit: Campbell Barton <ideasma...@gmail.com>

    Fix #13: Every word marked as incorrect on MS-Windows
    
    Line endings were included in the words,
    now utf8-unix encoding is forced.
---
 changelog.rst |  1 +
 spell-fu.el   | 19 ++++++++++++-------
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/changelog.rst b/changelog.rst
index 1d20171cea..7cdcd7e609 100644
--- a/changelog.rst
+++ b/changelog.rst
@@ -4,6 +4,7 @@ Change Log
 ##########
 
 - In development.
+  - Fix #13, failure to properly generate word-list cache on MS-Windows.
   - Support buffer local word-lists via ``spell-fu-buffer-session-localwords``.
   - Fix faces of overlays (such as ``hl-line-mode``) no longer mask other 
faces when selecting words to check.
   - Support for multiple dictionaries at once.
diff --git a/spell-fu.el b/spell-fu.el
index 4bfdb0d630..ac3a076cf1 100644
--- a/spell-fu.el
+++ b/spell-fu.el
@@ -155,7 +155,7 @@ Notes:
 
 ;; Use to ensure the cache is not from a previous release.
 ;; Only ever increase.
-(defconst spell-fu--cache-version "0.1")
+(defconst spell-fu--cache-version "0.2")
 
 ;; Keep track of the last overlay, this allows expanding the existing overlay 
where possible.
 ;; Useful since font-locking often uses multiple smaller ranges which can be 
merged into one range.
@@ -420,7 +420,10 @@ save some time by not spending time reading it back."
   (let
     ( ;; The header, an associative list of items.
       (cache-header (list (cons "version" spell-fu--cache-version)))
-      (word-table nil))
+      (word-table nil)
+      ;; Needed for Windows to prevent CRLF including new-lines in strings.
+      (coding-system-for-read 'utf-8-unix)
+      (coding-system-for-write 'utf-8-unix))
 
     (with-temp-buffer
       (insert-file-contents-literally words-file)
@@ -1156,11 +1159,13 @@ Return t if the file was updated."
               (setq word-list-ncase
                 (sort word-list-ncase (lambda (a b) (string-lessp (car a) (car 
b)))))
 
-              ;; Write to 'words-file'.
-              (with-temp-buffer
-                (dolist (line-cons word-list-ncase)
-                  (insert (cdr line-cons) "\n"))
-                (write-region nil nil words-file nil 0))))))
+              ;; Needed for Windows to prevent CRLF including new-lines in 
strings.
+              (let ((coding-system-for-write 'utf-8-unix))
+                ;; Write to 'words-file'.
+                (with-temp-buffer
+                  (dolist (line-cons word-list-ncase)
+                    (insert (cdr line-cons) "\n"))
+                  (write-region nil nil words-file nil 0)))))))
 
       updated)))
 

Reply via email to