New Aspell plugin
authorMikael Berthe <mikael@lilotux.net>
Tue, 01 May 2007 23:16:29 +0200
changeset 14 5b5eaf194467
parent 13 d3207cb5a777
child 15 c7bc5fcabc81
New Aspell plugin
plugins/aspell_plugin.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/aspell_plugin.py	Tue May 01 23:16:29 2007 +0200
@@ -0,0 +1,42 @@
+#$ neutron_plugin 01
+
+import popen2
+import re
+
+ASPELL = "/usr/bin/aspell -a"
+
+def handler_aspell(type, source, parameters):
+    parameters = parameters.lstrip().rstrip()
+    splitdata = parameters.split()
+    aspell = ASPELL
+    reply = ""
+
+    if len(splitdata) > 1:
+        lang = parameters.lower()
+        if re.match(r"\w\w ", lang):
+            parameters = parameters[3:].lstrip()
+            aspell += " --lang=" + lang
+
+    stdout, stdin = popen2.popen2(aspell)
+
+    stdin.write(parameters)
+    stdin.close()
+
+    r = stdout.readline()
+    for r in stdout.readlines():
+        if r == "*\n":
+            reply += "* Word correctly spelled.\n"
+        elif r.startswith("& "):
+            if r.count(": "):
+                reply += "* Let me suggest " + r[r.find(": ")+2:].strip()
+                reply += ".\n"
+            else:
+                reply += r
+
+    if not reply:
+        reply = "Unknown error"
+
+    smsg(type, source, reply.rstrip())
+
+register_command_handler(handler_aspell, 'aspell', 0, 'Check the spelling',
+			 'aspell [lang]', ['aspell fr bonjour'])