# HG changeset patch # User Mikael Berthe # Date 1178054189 -7200 # Node ID 5b5eaf194467ed9c84675b91e78da92e4c2e4e60 # Parent d3207cb5a7773436d0f7dd907b2493c2558105ff New Aspell plugin diff -r d3207cb5a777 -r 5b5eaf194467 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'])