Subject: bug#17742: Acknowledgement (Support for enchant?)

From: Reuben Thomas <[email-masked]>
Date: Mon, 5 Dec 2016 21:41:06 +0000

Attached, a patch to add initial enchant support.

This seems to work fine with one major limitation: at present there's no
dictionary auto-discovery, and as the built-in ispell-dictionary-alist is
all 8-bit encodings, while enchant is UTF-8, without some manual
configuration the dreaded "misalignment errors" occur.

I shall add dictionary listing support.

I have already added replace-for-session ("$$ra") to my enchant patch, so
enchant can use this functionality in ispell.el.

-- 
http://rrt.sc3d.org
From f3dce7c44241c0a17e6fb39f07a2cb32dc05a92a Mon Sep 17 00:00:00 2001
From: Reuben Thomas <[email-masked]>
Date: Sun, 4 Dec 2016 22:39:27 +0000
Subject: [PATCH 23/23] Add basic Enchant support to ispell.el
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* lisp/textmodes/ispell.el (ispell-program-name): Add “enchant”.
(ispell-really-enchant): Add variable.
(ispell-check-version): If using Enchant, check it’s new enough (at
least 1.6.1).  (Like the ispell check, this is absolute: cannot work
without.)
(ispell-send-replacement): Make it work with Enchant.
---
 lisp/textmodes/ispell.el | 40 ++++++++++++++++++++++++++++------------
 1 file changed, 28 insertions(+), 12 deletions(-)

diff --git a/lisp/textmodes/ispell.el b/lisp/textmodes/ispell.el
index 6733c75..1b81a5d 100644
--- a/lisp/textmodes/ispell.el
+++ b/lisp/textmodes/ispell.el
@@ -209,7 +209,8 @@ ispell-choices-win-default-height
   :group 'ispell)
 
 (defcustom ispell-program-name
-  (or (executable-find "aspell")
+  (or (executable-find "enchant")
+      (executable-find "aspell")
       (executable-find "ispell")
       (executable-find "hunspell")
       "ispell")
@@ -605,6 +606,8 @@ ispell-really-aspell
   "Non-nil if we can use Aspell extensions.")
 (defvar ispell-really-hunspell nil
   "Non-nil if we can use Hunspell extensions.")
+(defvar ispell-really-enchant nil
+  "Non-nil if we can use Enchant extensions.")
 (defvar ispell-encoding8-command nil
   "Command line option prefix to select encoding if supported, nil otherwise.
 If setting the encoding is supported by spellchecker and is selectable from
@@ -740,17 +743,29 @@ ispell-check-version
 		  (and (search-forward-regexp
 			"(but really Hunspell \\([0-9]+\\.[0-9\\.-]+\\)?)"
                         nil t)
+		       (match-string 1)))
+            (setq ispell-really-enchant
+		  (and (search-forward-regexp
+			"(but really Enchant \\([0-9]+\\.[0-9\\.-]+\\)?)"
+                        nil t)
 		       (match-string 1)))))
 
-      (let ((aspell-minver    "0.50")
-	    (aspell8-minver   "0.60")
-	    (ispell-minver    "3.1.12")
-	    (hunspell8-minver "1.1.6"))
-
-	(unless (version<= ispell-minver ispell-program-version)
-	  (error "%s release %s or greater is required"
+      (let* ((aspell-minver    "0.50")
+             (aspell8-minver   "0.60")
+             (ispell-minver    "3.1.12")
+             (hunspell8-minver "1.1.6")
+             (enchant-minver   "1.6.1")
+             (minver (cond
+                      ((not (version<= ispell-minver ispell-program-version))
+                       ispell-minver)
+                      ((and ispell-really-enchant
+                            (not (version<= enchant-minver ispell-really-enchant)))
+                       enchant-minver))))
+
+        (if minver
+	    (error "%s release %s or greater is required"
 		 ispell-program-name
-		 ispell-minver))
+		 minver))
 
 	(cond
 	 (ispell-really-aspell
@@ -1735,9 +1750,10 @@ ispell-accept-output
 	    (erase-buffer)))))))
 
 (defun ispell-send-replacement (misspelled replacement)
-  "Notify Aspell that MISSPELLED should be spelled REPLACEMENT.
-This allows improving the suggestion list based on actual misspellings."
-  (and ispell-really-aspell
+  "Notify spell checker that MISSPELLED should be spelled REPLACEMENT.
+This allows improving the suggestion list based on actual misspellings.
+Only works for Aspell and Enchant."
+  (and (or ispell-really-aspell ispell-really-enchant)
        (ispell-send-string (concat "$$ra " misspelled "," replacement "\n"))))

-- 
2.7.4