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

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

[nongnu] elpa/spell-fu 4782667d7b 76/86: Fail gracefully with a message


From: ELPA Syncer
Subject: [nongnu] elpa/spell-fu 4782667d7b 76/86: Fail gracefully with a message when aspell can't be found
Date: Thu, 7 Jul 2022 12:03:45 -0400 (EDT)

branch: elpa/spell-fu
commit 4782667d7b6b97658f7649598e47aa6cf4d1bd80
Author: Campbell Barton <ideasman42@gmail.com>
Commit: Campbell Barton <ideasman42@gmail.com>

    Fail gracefully with a message when aspell can't be found
    
    Resolve #19
---
 spell-fu.el | 105 ++++++++++++++++++++++++++++++++++++------------------------
 1 file changed, 63 insertions(+), 42 deletions(-)

diff --git a/spell-fu.el b/spell-fu.el
index 09fd263954..591116c068 100644
--- a/spell-fu.el
+++ b/spell-fu.el
@@ -1010,7 +1010,9 @@ Return t if the file was updated."
       (dict-aspell-name (cadr (nth 5 (assoc dict-name 
ispell-aspell-dictionary-alist))))
       (dict-file (and dict-aspell-name (spell-fu--aspell-find-data-file 
dict-name)))
       (is-dict-outdated
-        (and has-words-file dict-file (spell-fu--file-is-older words-file 
dict-file))))
+        (and has-words-file dict-file (spell-fu--file-is-older words-file 
dict-file)))
+      ;; Return value, failure to run `aspell' leaves this nil.
+      (updated nil))
 
     (when (or (not has-words-file) is-dict-outdated)
 
@@ -1028,54 +1030,73 @@ Return t if the file was updated."
                   (or (and ispell-really-aspell ispell-program-name) 
(executable-find "aspell"))))
 
               (cond
+                ((null aspell-bin)
+                  (message "\"aspell\" command not found!"))
                 ((string-equal dict-name "default")
-                  (call-process aspell-bin nil t nil "dump" "master"))
+                  (condition-case err
+                    (progn
+                      (call-process aspell-bin nil t nil "dump" "master")
+                      (setq updated t))
+                    (error
+                      (message
+                        "failed to run \"aspell\" with default dictionary with 
error: %s"
+                        (error-message-string err)))))
                 (t
-                  (call-process aspell-bin nil t nil "-d" dict-name "dump" 
"master")))
-
-              ;; Check whether the dictionary has affixes, expand if necessary.
-              (when (re-search-backward "^[[:alpha:]]*/[[:alnum:]]*$" nil t)
-                (let ((lang (spell-fu--aspell-lang-from-dict dict-name)))
-                  (unless
-                    (zerop
-                      (shell-command-on-region
-                        (point-min) (point-max)
-                        (cond
-                          (lang
-                            (format "%s -l %s expand" aspell-bin lang))
-                          (t
-                            (format "%s expand" aspell-bin)))
-                        t t
-                        ;; Output any errors into the message buffer instead 
of the word-list.
-                        "*spell-fu word generation errors*"))
-                    (message
-                      (format
-                        "spell-fu: affix extension for dictionary '%s' failed 
(with language: %S)."
+                  (condition-case err
+                    (progn
+                      (call-process aspell-bin nil t nil "-d" dict-name "dump" 
"master")
+                      (setq updated t))
+                    (error
+                      (message
+                        "failed to run aspell with %S dictionary with error: 
%s"
                         dict-name
-                        lang)))
-                  (goto-char (point-min))
-                  (while (search-forward " " nil t)
-                    (replace-match "\n")))))
+                        (error-message-string err))))))
 
-            (setq word-list (spell-fu--buffer-as-line-list (current-buffer) 
word-list)))
+              ;; Check whether the dictionary has affixes, expand if necessary.
+              (when updated
+                (when (re-search-backward "^[[:alpha:]]*/[[:alnum:]]*$" nil t)
+                  (let ((lang (spell-fu--aspell-lang-from-dict dict-name)))
+                    (unless
+                      (zerop
+                        (shell-command-on-region
+                          (point-min) (point-max)
+                          (cond
+                            (lang
+                              (format "%s -l %s expand" aspell-bin lang))
+                            (t
+                              (format "%s expand" aspell-bin)))
+                          t t
+                          ;; Output any errors into the message buffer instead 
of the word-list.
+                          "*spell-fu word generation errors*"))
+                      (message
+                        (format
+                          "spell-fu: affix extension for dictionary '%s' 
failed (with language: %S)."
+                          dict-name
+                          lang)))
+                    (goto-char (point-min))
+                    (while (search-forward " " nil t)
+                      (replace-match "\n"))))
+
+                (setq word-list (spell-fu--buffer-as-line-list 
(current-buffer) word-list)))))
 
           ;; Case insensitive sort is important if this is used for 
`ispell-complete-word-dict'.
           ;; Which is a handy double-use for this file.
-          (let ((word-list-ncase nil))
-            (dolist (word word-list)
-              (push (cons (downcase word) word) word-list-ncase))
-
-            ;; Sort by the lowercase word.
-            (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)))))
-
-      t)))
+          (when updated
+            (let ((word-list-ncase nil))
+              (dolist (word word-list)
+                (push (cons (downcase word) word) word-list-ncase))
+
+              ;; Sort by the lowercase word.
+              (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))))))
+
+      updated)))
 
 ;; Word List Initialization
 



reply via email to

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