4 A Programmer's Text Editor
8 Copyright (C) 1991-2007 Angel Ortega <angel@triptico.com>
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License
12 as published by the Free Software Foundation; either version 2
13 of the License, or (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 http://www.triptico.com
30 mp.actions['toggle_spellcheck'] = sub(d) { mp.ispell(-1); };
32 /* default key bindings */
34 /* action descriptions */
36 mp.actdesc['toggle_spellcheck'] = LL("Toggle spellchecking");
40 /* spellchecking command */
41 mp.config.ispell_cmd = "ispell -a";
45 sub mp.open_ispell_pipe
46 /* opens the pipe to ispell */
51 if((p = popen(mp.config.ispell_cmd, "r+")) == NULL)
54 /* read the first line */
57 /* check for the signature */
58 if(! regex('/^@\(#\) International Ispell/', l))
64 /* it works; set the word color function */
65 mp.word_color_func = mp.ispell_word_color_func;
72 sub mp.close_ispell_pipe
73 /* closes the pipe to ispell */
75 if(mp.ispell_pipe == NULL)
78 /* close and delete */
79 pclose(mp.ispell_pipe);
80 mp.ispell_pipe = NULL;
82 /* delete all words marked as misspelled from the word cache */
83 foreach(local w, keys(mp.word_color))
85 if(mp.word_color[w] == mp.colors.spell.attr)
86 hdel(mp.word_color, w);
89 /* delete the word color function */
90 mp.word_color_func = NULL;
94 sub mp.ispell_word_color_func(w)
95 /* mp.word_color_func() for ispell */
101 /* attributes must exist before entering here */
102 if(mp.colors.spell.attr == NULL)
106 write(mp.ispell_pipe, w ~ "\n");
108 /* wait for the response */
109 if((l = read(mp.ispell_pipe)) == NULL)
110 mp.close_ispell_pipe();
115 /* drop all lines until an empty one */
117 t = read(mp.ispell_pipe);
119 /* take first char of the response */
120 l = regex('/^./', l);
122 /* if it's not a '*' nor a '+', it's misspelled */
123 if(l ne '*' && l ne '+')
124 a = mp.colors.spell.attr;
127 /* store the attribute in the cache */
128 mp.word_color[w] = a;
135 /* sets or unsets spell checking (-1, toggle) */
138 b = mp.ispell_pipe == NULL && 1 || 0;
140 b && mp.open_ispell_pipe() || mp.close_ispell_pipe();