emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/ebdb c56d9e2 02/11: Get ebdb-ispell working again


From: Eric Abrahamsen
Subject: [elpa] externals/ebdb c56d9e2 02/11: Get ebdb-ispell working again
Date: Sun, 22 Oct 2017 13:17:01 -0400 (EDT)

branch: externals/ebdb
commit c56d9e26ae58b479088b0d70a22f71ae6afc9f41
Author: Eric Abrahamsen <address@hidden>
Commit: Eric Abrahamsen <address@hidden>

    Get ebdb-ispell working again
    
    * ebdb-ispell.el (ebdb-ispell-dictionary-list): Remove variable. Maybe
      I'm misunderstanding how this worked, but why were we looping over
      _other_ dictionaries? The previous version as written also errored
      out, unable to find the personal dictionary. Simplify the whole
      thing: just check the word, and add it if it's "misspelled".
      (ebdb-ispell-field-list): Remove variable. Just loop all the names.
      (ebdb-ispell-word-list): Remove variable. Have the function
      return the word list instead of setting this variable.
      (ebdb-ispell-export): Simplify function.
---
 ebdb-ispell.el | 124 ++++++++++++++++++++++++++-------------------------------
 1 file changed, 56 insertions(+), 68 deletions(-)

diff --git a/ebdb-ispell.el b/ebdb-ispell.el
index a42b3c0..ff79d6a 100644
--- a/ebdb-ispell.el
+++ b/ebdb-ispell.el
@@ -26,22 +26,7 @@
 (require 'ispell)
 (require 'ebdb)
 
-(defcustom ebdb-ispell-dictionary-list '("default")
-  "List of ispell personal dictionaries.
-Allowed elements are as in the return value of `ispell-valid-dictionary-list'."
-  :group 'ebdb-utilities-ispell
-  :type (cons 'set (mapcar (lambda (dict) `(string ,dict))
-                           (ispell-valid-dictionary-list))))
-
-(defcustom ebdb-ispell-field-list '(name organization aka)
-  "List of fields of each EBDB record considered for the personal dictionary."
-  :group 'ebdb-utilities-ispell
-  :type (list 'repeat
-              (append '(choice) (mapcar (lambda (field) `(const ,field))
-                                        '(name organization affix aka address))
-                      '((symbol :tag "xfield")))))
-
-(defcustom ebdb-ispell-min-word-length 3
+(defcustom ebdb-ispell-min-word-length 2
   "Words with fewer characters are ignored."
   :group 'ebdb-utilities-ispell
   :type 'number)
@@ -51,62 +36,65 @@ Allowed elements are as in the return value of 
`ispell-valid-dictionary-list'."
   :group 'ebdb-utilities-ispell
   :type 'regexp)
 
-;; Internal variable
-(defvar ebdb-ispell-word-list nil
-  "List of words extracted from the EBDB records.")
-
 ;;;###autoload
 (defun ebdb-ispell-export ()
   "Export EBDB records to ispell personal dictionaries."
   (interactive)
-  (message "Exporting to personal dictionary...")
-  (let (ebdb-ispell-word-list)
-    ;; Collect words from EBDB records.
-    (dolist (record (ebdb-records))
-      (dolist (field ebdb-ispell-field-list)
-        (ebdb-ispell-collect-words (ebdb-record-field record field))))
-
-    ;; Update personal dictionaries
-    (dolist (dict (or ebdb-ispell-dictionary-list '("default")))
-      (ispell-change-dictionary dict)
-      ;; Initialize variables and dicts alists
-      (ispell-set-spellchecker-params)
-      (ispell-init-process)
-      ;; put in verbose mode
-      (ispell-send-string "%\n")
-      (let (new)
-        (dolist (word (delete-dups ebdb-ispell-word-list))
-          (ispell-send-string (concat "^" word "\n"))
-          (while (progn
-                   (ispell-accept-output)
-                   (not (string= "" (car ispell-filter)))))
-          ;; remove extra \n
-          (setq ispell-filter (cdr ispell-filter))
-          (when (and ispell-filter
-                     (listp ispell-filter)
-                     (not (eq (ispell-parse-output (car ispell-filter)) t)))
-            ;; ok the word doesn't exist, add it
-            (ispell-send-string (concat "*" word "\n"))
-            (setq new t)))
-        (when new
-          ;; Save dictionary:
-          ;; aspell doesn't tell us when it completed the saving.
-          ;; So we send it another word for spellchecking.
-          (ispell-send-string "#\n^hello\n")
-          (while (progn
-                   (ispell-accept-output)
-                   (not (string= "" (car ispell-filter)))))))))
-  (message "Exporting to personal dictionary...done"))
-
-(defun ebdb-ispell-collect-words (field)
-  "Parse EBDB FIELD and collect words in `ebdb-ispell-word-list'."
-  ;; Ignore everything in FIELD that is not a string or a sequence.
-  (cond ((stringp field)
-         (dolist (word (split-string field))
-           (if (and (>= (length word) ebdb-ispell-min-word-length)
-                    (not (string-match ebdb-ispell-ignore-re word)))
-               (push word ebdb-ispell-word-list))))
-        ((sequencep field) (mapc 'ebdb-ispell-collect-words field))))
+  (message "Exporting 0 words to personal dictionary...")
+  ;; Collect words from EBDB records.
+  (let ((word-list
+        (seq-mapcat
+         (lambda (r)
+           (ebdb-ispell-collect-words
+            (cons (ebdb-record-name r)
+                  (ebdb-record-alt-names r))))
+         (ebdb-records)))
+       (count 0))
+
+    ;; Initialize variables and dicts alists
+    (ispell-set-spellchecker-params)
+    (ispell-init-process)
+    ;; put in verbose mode
+    (ispell-send-string "%\n")
+    (let (new)
+      (dolist (word (delete-dups word-list))
+        (ispell-send-string (concat "^" word "\n"))
+        (while (progn
+                 (ispell-accept-output)
+                 (not (string= "" (car ispell-filter)))))
+        ;; remove extra \n
+        (setq ispell-filter (cdr ispell-filter))
+        (when (and ispell-filter
+                   (listp ispell-filter)
+                   (not (eq (ispell-parse-output (car ispell-filter)) t)))
+          ;; ok the word doesn't exist, add it
+          (ispell-send-string (concat "*" word "\n"))
+         (message "Exporting %d words to personal dictionary..."
+                  (cl-incf count))
+          (setq new t)))
+      (when new
+        ;; Save dictionary:
+        ;; aspell doesn't tell us when it completed the saving.
+        ;; So we send it another word for spellchecking.
+        (ispell-send-string "#\n^hello\n")
+        (while (progn
+                 (ispell-accept-output)
+                 (not (string= "" (car ispell-filter))))))))
+  (message "Exporting %d words to personal dictionary...done" count))
+
+(defun ebdb-ispell-collect-words (strings)
+  "Find all individual words in STRINGS and filter.
+Removes strings that are too short
+\(`ebdb-ispell-min-word-length'\) or explicitly ignored
+\(`ebdb-ispell-ignore-re'\)."
+  (seq-filter
+   (lambda (word)
+     (and (>= (length word) ebdb-ispell-min-word-length)
+          (not (string-match ebdb-ispell-ignore-re word))))
+   (seq-mapcat
+    (lambda (s)
+      (split-string s "[ ,]"))
+    strings)))
 
 (provide 'ebdb-ispell)
 ;;; ebdb-ispell.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]