/usr/share/jed/jed-extra/drop-in/flyspell.sl is in jed-extra 2.5.6-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | % flyspell.sl
%
% $Id: flyspell.sl,v 1.23 2007/12/07 17:01:47 paul Exp paul $
%
% Copyright (c) 2003-2007 Paul Boekholt.
% Released under the terms of the GNU GPL (version 2 or later).
%
% This file provides a minor mode for on-the-fly spell checking.
require("syntax");
require("ispell_common");
use_namespace("ispell");
% The DFA trick used in this file does not work with "-" as an otherchar,
% so we trim it.
variable flyspell_otherchars = strtrim_beg(ispell_otherchars, "-");
variable flyspell_wordchars = flyspell_otherchars + ispell_letters;
variable flyspell_syntax_table;
private variable accumulator = "";
% do you want to use keyword2 to have red misspellings?
custom_variable("flyspell_use_keyword2", 1);
variable flyspell_chars = "
";
!if (is_defined("flyspell_process"))
public variable flyspell_process = -1;
%{{{ Flyspell process
% This will also restart flyspell, through the flyspell_is_dead() function
define kill_flyspell()
{
if (-1 != flyspell_process)
kill_process(flyspell_process);
}
private define flyspell_parse_output (pid, output)
{
accumulator += output;
variable name = flyspell_syntax_table;
variable lines = strchop(accumulator, '\n', 0);
if (length(lines) < 2)
{
return;
}
accumulator = lines[-1];
variable line;
foreach line (lines[[:-2]])
{
line = strtok(strtrim(line));
if (length(line) < 2) continue;
line = line[1];
try
{
if (flyspell_use_keyword2)
add_keyword_n(name, line, 2);
else
add_keyword(name, line);
}
catch AnyError;
}
}
private define flyspell_is_dead (pid, flags, status)
{
if (flags & 14)
flyspell_process = -1;
}
private define toggle_local_flyspell();
private define flyspell_init_process ()
{
% we need to redefine these in case this process was started
% by switching to a buffer in another language
flyspell_otherchars = strtrim_beg(ispell_otherchars, "-");
flyspell_wordchars = flyspell_otherchars + ispell_letters;
variable buf, ibuf = " *flyspell*";
% JED has problems with asynchronous processes that are stopped and
% immediately restarted so we make sure that we kill the process when
% the dictionary changes, and start it when it's needed.
if (flyspell_process != -1)
return;
buf = whatbuf();
variable args = strtok (ispell_command + " -a");
setbuf(ibuf);
erase_buffer;
message ("starting flyspell process....");
foreach (args)
;
length (args) - 1;
flyspell_process = open_process ();
sleep(0.5);
get_process_input(2);
if (flyspell_process == -1)
throw RunTimeError, "could not start ispell";
% Give ispell a chance to start. Maybe I should use
% wait_for_ispell_output() here.
variable flyspell_started = 0;
loop (5)
{
bob ();
if (looking_at_char ('@')) % ispell header
{
flyspell_started = 1;
del_through_eol ();
break;
}
else get_process_input(2);
}
!if (flyspell_started)
% if we're not looking at the ispell header, there was probably an
% error. For some reason flyspell does not exit (or maybe the
% signal handler can't run) before this function returns so telling
% if a process has started successfully is a bit difficult.
{
pop2buf(whatbuf);
flyspell_process = -1;
if (looking_at("execvp"))
{
pop2buf(buf);
throw RunTimeError, "Could not start ispell!";
}
else
{
pop2buf(buf);
throw RunTimeError, "Flyspell crashed!";
}
}
send_process(flyspell_process, "!\n");
set_process (flyspell_process, "signal", &flyspell_is_dead);
set_process (flyspell_process, "output", &flyspell_parse_output);
process_query_at_exit(flyspell_process, 0);
accumulator = "";
setbuf(buf);
}
%}}}
%{{{ Flyspelling
variable lastword = "", lastpoint = 0;
public define flyspell_word()
{
variable word, point;
if (flyspell_process == -1)
{
try
{
flyspell_init_process();
}
catch AnyError:
{
toggle_local_flyspell(0);
return;
}
}
push_spot();
bskip_chars(ispell_non_letters);
push_mark();
bskip_chars(flyspell_wordchars);
skip_chars(flyspell_otherchars);
point = _get_point();
word = bufsubstr();
if (word == "") return pop_spot();
EXIT_BLOCK
{
(lastword, lastpoint) = word, point;
pop_spot();
}
if (word == lastword)
{
if (point != lastpoint)
{
bskip_chars(ispell_non_letters);
bskip_chars(flyspell_wordchars);
skip_chars(flyspell_otherchars);
if (looking_at(word))
{
message("double word");
beep();
}
}
return;
}
if (strlen(word) < 3) return;
clear_message;
send_process( flyspell_process, strcat ("^", word, "\n"));
}
private define after_key_hook ()
{
try
{
if (is_substr(flyspell_chars, LASTKEY))
flyspell_word();
}
catch AnyError:
{
toggle_local_flyspell(0);
}
}
%}}}
%{{{ Turning flyspell mode on/off
define flyspell_switch_active_buffer_hook()
{
remove_from_hook ("_jed_after_key_hooks", &after_key_hook);
if (get_blocal_var("flyspell", 0))
add_to_hook ("_jed_after_key_hooks", &after_key_hook);
flyspell_syntax_table = get_blocal_var("flyspell_syntax_table", "Flyspell_" + flyspell_current_dictionary);
}
private define toggle_local_flyspell() % on/off
{
variable flyspell;
!if (_NARGS) not get_blocal_var("flyspell", 0);
flyspell = ();
define_blocal_var("flyspell", flyspell);
if (flyspell)
{
set_status_line(str_replace_all(Status_Line_String, "%m", "%m fly"), 0);
if (flyspell_current_dictionary != ispell_current_dictionary)
{
kill_flyspell;
flyspell_current_dictionary = ispell_current_dictionary;
}
}
else
{
set_status_line(Status_Line_String, 0);
}
flyspell_switch_active_buffer_hook();
}
%}}}
#ifdef HAS_DFA_SYNTAX
%%% DFA_CACHE_BEGIN %%%
define setup_dfa_callback (name)
{
dfa_define_highlight_rule
(sprintf("[%s][%s]*[%s]",ispell_letters, flyspell_wordchars, ispell_letters),
"Knormal", name);
dfa_define_highlight_rule("[^ -~%s]+", "normal", name);
dfa_build_highlight_table (name);
}
%%% DFA_CACHE_END %%%
#endif
private variable syntax_tables = Assoc_Type[Integer_Type, 0];
define flyspell_make_syntax_table(name)
{
flyspell_otherchars = strtrim_beg(ispell_otherchars, "-");
flyspell_wordchars = flyspell_otherchars + ispell_letters;
if (syntax_tables[name]) return;
syntax_tables[name] = 1;
create_syntax_table(name);
set_syntax_flags(name, 0);
define_syntax(flyspell_wordchars, 'w', name);
dfa_set_init_callback (&setup_dfa_callback, name);
}
% A change in syntax table is from starting flyspell in a buffer with
% another language, or from changing the language while flyspelling. If
% you just switch to a buffer with a different setting for language, it
% should continue to use its own syntax table.
define flyspell_change_syntax_table(language)
{
variable table = get_blocal_var("flyspell_syntax_table", NULL);
if(table != NULL)
{
use_syntax_table(table);
define_syntax(ispell_wordchars, 'w', table);
use_dfa_syntax(0);
flyspell_syntax_table=table;
}
else
{
% this will get confused when you change the global language from a
% buffer that has a blocal language.
table = "Flyspell_" + language;
flyspell_make_syntax_table(table);
flyspell_syntax_table = table;
use_syntax_table(table);
use_dfa_syntax(1);
}
}
%!%+
%\function{flyspell_mode}
%\synopsis{toggle flyspell mode}
%\usage{flyspell_mode()}
%\description
% This toggles flyspell mode for the buffer. In flyspell mode,
% misspelled words are highlighted as you type. If you're in doubt
% whether flyspell mode is on, look at the statusbar - it should say
% something like "(text fly)"
%\notes
% Flyspell works by adding the misspellings to a flyspell syntax table
% asynchronously, which means that JED's flyspell mode does not give
% the slow responsiveness of Emacs' flyspell mode and other similar
% products. It also means that mode-dependent syntax highlighting is
% turned off while you flyspell. You can make flyspell write its
% misspellings to a syntax table of your choice by setting the
% bufferlocal variable \var{flyspell_syntax_table} (\var{mail_mode} does this)
%\seealso{ispell, flyspell_region}
%!%-
public define flyspell_mode()
{
flyspell_init_process();
flyspell_change_syntax_table(ispell_current_dictionary);
toggle_local_flyspell();
if (flyspell_use_keyword2)
set_color("keyword2", "brightred", get_color("normal"), exch(), pop);
}
%!%+
%\function{flyspell_region}
%\synopsis{highlight misspellings in the region}
%\usage{flyspell_region()}
%\description
% Send the region, or the buffer if there is no visible mark, to the
% flyspell process. If the buffer is not in flyspell mode, flyspell
% mode is turned on.
%\seealso{flyspell_mode, ispell_region}
%!%-
public define flyspell_region()
{
variable line;
flyspell_current_dictionary = ispell_current_dictionary;
!if (get_blocal_var("flyspell", 0))
flyspell_mode();
push_spot();
!if (is_visible_mark())
mark_buffer();
flush ("flyspelling...");
try
{
foreach line (strchop(bufsubstr(), '\n', 0))
{
send_process( flyspell_process, "^" + line + "\n");
}
}
finally
{
pop_spot();
}
flush("flyspelling...done");
}
provide("flyspell");
|