X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=lib%2Fspellcheck.tcl;h=78f344f08f34842c134b6b0e22b6eb8c49b1dbbd;hb=fbbdaa5f425417e7fee83f543b1d03806f034cab;hp=a37ff5f8f315e56270bec45ea4fa7394fb0a43af;hpb=35d04b3b110f9adcd485c8470d8048394f586018;p=git.git diff --git a/lib/spellcheck.tcl b/lib/spellcheck.tcl index a37ff5f8f..78f344f08 100644 --- a/lib/spellcheck.tcl +++ b/lib/spellcheck.tcl @@ -6,6 +6,8 @@ class spellcheck { field s_fd {} ; # pipe to ispell/aspell field s_version {} ; # ispell/aspell version string field s_lang {} ; # current language code +field s_prog aspell; # are we actually old ispell? +field s_failed 0 ; # is $s_prog bogus and not working? field w_text ; # text widget we are spelling field w_menu ; # context menu for the widget @@ -35,21 +37,66 @@ method _connect {pipe_fd} { -translation lf if {[gets $pipe_fd s_version] <= 0} { - close $pipe_fd - error [mc "Spell checker sliently failed on startup"] + if {[catch {close $pipe_fd} err]} { + + # Eh? Is this actually ispell choking on aspell options? + # + if {$s_prog eq {aspell} + && [regexp -nocase {^Usage: } $err] + && ![catch { + set pipe_fd [open [list | $s_prog -v] r] + gets $pipe_fd s_version + close $pipe_fd + }] + && $s_version ne {}} { + if {{@(#) } eq [string range $s_version 0 4]} { + set s_version [string range $s_version 5 end] + } + set s_failed 1 + error_popup [strcat \ + [mc "Unsupported spell checker"] \ + ":\n\n$s_version"] + set s_version {} + return + } + + regsub -nocase {^Error: } $err {} err + if {$s_fd eq {}} { + error_popup [strcat [mc "Spell checking is unavailable"] ":\n\n$err"] + } else { + error_popup [strcat \ + [mc "Invalid spell checking configuration"] \ + ":\n\n$err\n\n" \ + [mc "Reverting dictionary to %s." $s_lang]] + } + } else { + error_popup [mc "Spell checker silently failed on startup"] + } + return } + if {{@(#) } ne [string range $s_version 0 4]} { - close $pipe_fd - error [strcat [mc "Unrecognized spell checker"] ": $s_version"] + catch {close $pipe_fd} + error_popup [strcat [mc "Unrecognized spell checker"] ":\n\n$s_version"] + return } set s_version [string range $s_version 5 end] + regexp \ + {International Ispell Version .* \(but really (Aspell .*?)\)$} \ + $s_version _junk s_version + regexp {^Aspell (\d)+\.(\d+)} $s_version _junk major minor puts $pipe_fd ! ; # enable terse mode - puts $pipe_fd {$$cr master} ; # fetch the language - flush $pipe_fd - gets $pipe_fd s_lang - regexp {[/\\]([^/\\]+)\.[^\.]+$} $s_lang _ s_lang + # fetch the language + if {$major > 0 || ($major == 0 && $minor >= 60)} { + puts $pipe_fd {$$cr master} + flush $pipe_fd + gets $pipe_fd s_lang + regexp {[/\\]([^/\\]+)\.[^\.]+$} $s_lang _ s_lang + } else { + set s_lang {} + } if {$::default_config(gui.spellingdictionary) eq {} && [get_config gui.spellingdictionary] eq {}} { @@ -76,7 +123,7 @@ method _connect {pipe_fd} { } method lang {{n {}}} { - if {$n ne {} && $s_lang ne $n} { + if {$n ne {} && $s_lang ne $n && !$s_failed} { set spell_cmd [list |] lappend spell_cmd aspell lappend spell_cmd --master=$n