@matheusbsbs / matheus-bagliano / commits / 827743b2e8
Fork 0

git-gui: Gracefully display non-aspell version errors to users

If the user has somehow managed to make us execute ispell instead of aspell, even though our code is invoking aspell, and ispell is not recognizing the aspell command line options we use to invoke it then we don't want a giant usage message back from ispell. Instead we show the ispell version number, letting the user know we don't actually support that spell checker. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Feb 21, 2008 at 00:17 UTC 827743b2e893a0e81e9286ef12de4c02486e6c5e
1 file changed +25 -1
lib/spellcheck.tcl
+25 -1
@@ -6,6 +6,8 @@ class spellcheck {
6 field s_fd {} ; # pipe to ispell/aspell
7 field s_version {} ; # ispell/aspell version string
8 field s_lang {} ; # current language code
9 +field s_prog aspell; # are we actually old ispell?
10 +field s_failed 0 ; # is $s_prog bogus and not working?
11
12 field w_text ; # text widget we are spelling
13 field w_menu ; # context menu for the widget
@@ -36,6 +38,28 @@ method _connect {pipe_fd} {
38
39 if {[gets $pipe_fd s_version] <= 0} {
40 if {[catch {close $pipe_fd} err]} {
41 +
42 + # Eh? Is this actually ispell choking on aspell options?
43 + #
44 + if {$s_prog eq {aspell}
45 + && [regexp -nocase {^Usage: } $err]
46 + && ![catch {
47 + set pipe_fd [open [list | $s_prog -v] r]
48 + gets $pipe_fd s_version
49 + close $pipe_fd
50 + }]
51 + && $s_version ne {}} {
52 + if {{@(#) } eq [string range $s_version 0 4]} {
53 + set s_version [string range $s_version 5 end]
54 + }
55 + set s_failed 1
56 + error_popup [strcat \
57 + [mc "Unsupported spell checker"] \
58 + ":\n\n$s_version"]
59 + set s_version {}
60 + return
61 + }
62 +
63 regsub -nocase {^Error: } $err {} err
64 if {$s_fd eq {}} {
65 error_popup [strcat [mc "Spell checking is unavailable"] ":\n\n$err"]
@@ -89,7 +113,7 @@ method _connect {pipe_fd} {
113 }
114
115 method lang {{n {}}} {
92 - if {$n ne {} && $s_lang ne $n} {
116 + if {$n ne {} && $s_lang ne $n && !$s_failed} {
117 set spell_cmd [list |]
118 lappend spell_cmd aspell
119 lappend spell_cmd --master=$n