[Tkabber-dev] r876 - in trunk/tkabber: . doc plugins/chat plugins/general plugins/unix

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Tue Jan 16 19:33:08 MSK 2007


Author: sergei
Date: 2007-01-16 19:33:02 +0300 (Tue, 16 Jan 2007)
New Revision: 876

Added:
   trunk/tkabber/plugins/general/ispell.tcl
Removed:
   trunk/tkabber/plugins/unix/ispell.tcl
Modified:
   trunk/tkabber/ChangeLog
   trunk/tkabber/README
   trunk/tkabber/doc/tkabber.html
   trunk/tkabber/doc/tkabber.xml
   trunk/tkabber/plugins/chat/me_command.tcl
   trunk/tkabber/plugins/chat/nick_colors.tcl
Log:
	* plugins/chat/me_command.tcl, plugins/chat/nick_colors.tcl: Fixed
	  bug with inserting nicknames to chat input windows on /me
	  messages.

	* plugins/general/ispell.tcl: Some code cleanup, replaced option
	  options(dictionary) by more general options(command_line) to
	  allow any ispell/aspell options. Moved plugin to general directory
	  because it works not only in UNIX (the only requirement is working
	  ispell).

	* README, doc/tkabber.html, doc/tkabber.xml: Documented changes in
	  ispell module.


Modified: trunk/tkabber/ChangeLog
===================================================================
--- trunk/tkabber/ChangeLog	2007-01-15 21:06:31 UTC (rev 875)
+++ trunk/tkabber/ChangeLog	2007-01-16 16:33:02 UTC (rev 876)
@@ -1,3 +1,18 @@
+2007-01-16  Sergei Golovan  <sgolovan at nes.ru>
+
+	* plugins/chat/me_command.tcl, plugins/chat/nick_colors.tcl: Fixed
+	  bug with inserting nicknames to chat input windows on /me
+	  messages.
+
+	* plugins/general/ispell.tcl: Some code cleanup, replaced option
+	  options(dictionary) by more general options(command_line) to
+	  allow any ispell/aspell options. Moved plugin to general directory
+	  because it works not only in UNIX (the only requirement is working
+	  ispell).
+
+	* README, doc/tkabber.html, doc/tkabber.xml: Documented changes in
+	  ispell module.
+
 2007-01-15  Sergei Golovan  <sgolovan at nes.ru>
 
 	* plugins/general/autoaway.tcl: Fixed bug with restoring status

Modified: trunk/tkabber/README
===================================================================
--- trunk/tkabber/README	2007-01-15 21:06:31 UTC (rev 875)
+++ trunk/tkabber/README	2007-01-16 16:33:02 UTC (rev 876)
@@ -9,7 +9,7 @@
                                                      New Economic School
                                                                M. Litvak
                                                   Information Centre ISP
-                                                        January 14, 2007
+                                                        January 16, 2007
 
 
                              Tkabber v0.9.9
@@ -1066,7 +1066,7 @@
 
 
        set plugins::ispell::options(executable)          /usr/bin/ispell
-       set plugins::ispell::options(dictionary)          russian
+       set plugins::ispell::options(command_line)        -C -d russian
        set plugins::ispell::options(dictionary_encoding) koi8-r
        set plugins::ispell::options(check_every_symbol)  1
 
@@ -1407,15 +1407,15 @@
    an external program _ispell_.  To enable this feature, add following
    lines to postload function:
 
-   set plugins::ispell::options(dictionary) 1
+   set plugins::ispell::options(enable) 1
 
    If you enabled this module, then you can also define:
 
    o  the path to the _ispell_ executable by setting
       "plugins::ispell::options(executable)"
 
-   o  the path to the dictionary by setting
-      "plugins::ispell::options(dictionary)"; and,
+   o  the _ispell_ command line options by setting
+      "plugins::ispell::options(command_line)"; and,
 
    o  the encoding of the output by setting
       "plugins::ispell::options(dictionary_encoding)".

Modified: trunk/tkabber/doc/tkabber.html
===================================================================
--- trunk/tkabber/doc/tkabber.html	2007-01-15 21:06:31 UTC (rev 875)
+++ trunk/tkabber/doc/tkabber.html	2007-01-16 16:33:02 UTC (rev 876)
@@ -1,6 +1,6 @@
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 <html lang="en"><head><title>Tkabber v0.9.9</title>
-<meta http-equiv="Expires" content="Sun, 14 Jan 2007 19:17:58 +0000">
+<meta http-equiv="Expires" content="Tue, 16 Jan 2007 16:25:42 +0000">
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 <meta name="description" content="Tkabber v0.9.9">
 <meta name="generator" content="xml2rfc v1.30 (http://xml.resource.org/)">
@@ -132,7 +132,7 @@
 <tr><td class="header">&nbsp;</td><td class="header">New Economic School</td></tr>
 <tr><td class="header">&nbsp;</td><td class="header">M. Litvak</td></tr>
 <tr><td class="header">&nbsp;</td><td class="header">Information Centre ISP</td></tr>
-<tr><td class="header">&nbsp;</td><td class="header">January 14, 2007</td></tr>
+<tr><td class="header">&nbsp;</td><td class="header">January 16, 2007</td></tr>
 </table></td></tr></table>
 <div align="right"><span class="title"><br />Tkabber v0.9.9</span></div>
 
@@ -1097,7 +1097,7 @@
 
     set plugins::ispell::options(enable)              1
     set plugins::ispell::options(executable)          /usr/bin/ispell
-    set plugins::ispell::options(dictionary)          russian
+    set plugins::ispell::options(command_line)        -C -d russian
     set plugins::ispell::options(dictionary_encoding) koi8-r
     set plugins::ispell::options(check_every_symbol)  1
 
@@ -1473,7 +1473,7 @@
 	    following lines to postload function:
 	    
 </p><pre>
-set plugins::ispell::options(dictionary) 1
+set plugins::ispell::options(enable) 1
 </pre>
 <p>
 	    If you enabled this module, then you can also define:
@@ -1482,8 +1482,8 @@
 <li>the path to the <span class="emph">ispell</span> executable by setting
 <span class="verb">plugins::ispell::options(executable)</span>
 </li>
-<li>the path to the dictionary by setting
-<span class="verb">plugins::ispell::options(dictionary)</span>; and,
+<li>the <span class="emph">ispell</span> command line options by setting
+<span class="verb">plugins::ispell::options(command_line)</span>; and,
 </li>
 <li>the encoding of the output by setting
 <span class="verb">plugins::ispell::options(dictionary_encoding)</span>.

Modified: trunk/tkabber/doc/tkabber.xml
===================================================================
--- trunk/tkabber/doc/tkabber.xml	2007-01-15 21:06:31 UTC (rev 875)
+++ trunk/tkabber/doc/tkabber.xml	2007-01-16 16:33:02 UTC (rev 876)
@@ -821,7 +821,7 @@
 
     set plugins::ispell::options(enable)              1
     set plugins::ispell::options(executable)          /usr/bin/ispell
-    set plugins::ispell::options(dictionary)          russian
+    set plugins::ispell::options(command_line)        -C -d russian
     set plugins::ispell::options(dictionary_encoding) koi8-r
     set plugins::ispell::options(check_every_symbol)  1
 
@@ -1199,7 +1199,7 @@
 	    following lines to postload function:
 	    </preamble>
 <artwork>
-set plugins::ispell::options(dictionary) 1
+set plugins::ispell::options(enable) 1
 </artwork>
 	  </figure>
 
@@ -1209,8 +1209,8 @@
 <t>the path to the <spanx>ispell</spanx> executable by setting
 <spanx style='verb'>plugins::ispell::options(executable)</spanx></t>
 
-<t>the path to the dictionary by setting
-<spanx style='verb'>plugins::ispell::options(dictionary)</spanx>; and,</t>
+<t>the <spanx>ispell</spanx> command line options by setting
+<spanx style='verb'>plugins::ispell::options(command_line)</spanx>; and,</t>
 
 <t>the encoding of the output by setting
 <spanx style='verb'>plugins::ispell::options(dictionary_encoding)</spanx>.</t>

Modified: trunk/tkabber/plugins/chat/me_command.tcl
===================================================================
--- trunk/tkabber/plugins/chat/me_command.tcl	2007-01-15 21:06:31 UTC (rev 875)
+++ trunk/tkabber/plugins/chat/me_command.tcl	2007-01-16 16:33:02 UTC (rev 876)
@@ -15,11 +15,11 @@
 	set nick [chat::get_nick $connid $from $type]
 	set cw [chat::winid $chatid]
 
+	$chatw insert end "* $nick" [list $tag NICK-$nick] " "
+
 	$chatw mark set MSGLEFT "end - 1 char"
 	$chatw mark gravity MSGLEFT left
 
-	$chatw insert end "* $nick " $tag
-
 	if {[cequal $type groupchat]} {
 	    set myjid [chat::our_jid $chatid]
 	    set mynick [chat::get_nick $connid $myjid $type]
@@ -38,7 +38,7 @@
 	    tab_set_updated $cw 1 mesg_to_user
 	}
 
-        $chatw tag add NICK-$nick MSGLEFT "end - 1 char"
+        $chatw tag add NICKMSG-$nick MSGLEFT "end - 1 char"
 
 	return stop
     }

Modified: trunk/tkabber/plugins/chat/nick_colors.tcl
===================================================================
--- trunk/tkabber/plugins/chat/nick_colors.tcl	2007-01-15 21:06:31 UTC (rev 875)
+++ trunk/tkabber/plugins/chat/nick_colors.tcl	2007-01-16 16:33:02 UTC (rev 876)
@@ -117,6 +117,7 @@
     foreach {nick clr} [array get NickColors] {
 	if {$options(use_colored_nicks)} {
 	    $W tag configure NICK-$nick -foreground $clr
+	    $W tag configure NICKMSG-$nick -foreground $clr
 	}
 	if {$options(use_colored_messages)} {
 	    $W tag configure MSG-$nick -foreground $clr

Copied: trunk/tkabber/plugins/general/ispell.tcl (from rev 873, trunk/tkabber/plugins/unix/ispell.tcl)
===================================================================
--- trunk/tkabber/plugins/general/ispell.tcl	                        (rev 0)
+++ trunk/tkabber/plugins/general/ispell.tcl	2007-01-16 16:33:02 UTC (rev 876)
@@ -0,0 +1,363 @@
+# $Id$
+
+#############################################################################
+
+package require textutil
+
+#############################################################################
+
+namespace eval ispell {
+    custom::defgroup Plugins [::msgcat::mc "Plugins options."] \
+	-group Tkabber
+
+    custom::defgroup Ispell [::msgcat::mc "Spell check options."] \
+	-group Plugins
+
+    variable options
+
+    custom::defvar options(enable) 0 \
+	[::msgcat::mc "Enable spellchecker in text input windows."] \
+	-type boolean \
+	-group Ispell \
+	-command [namespace current]::stop
+
+    custom::defvar options(executable) /usr/bin/ispell \
+	[::msgcat::mc "Path to the ispell executable."] \
+	-group Ispell \
+	-command [namespace current]::stop
+
+    custom::defvar options(command_line) "" \
+	[::msgcat::mc "Ispell options. See ispell manual for details.
+
+Examples:
+  -d russian
+  -d german -T latin1
+  -C -d english"] \
+	-type string \
+	-group Ispell \
+	-command [namespace current]::stop
+
+    custom::defvar options(dictionary_encoding) "" \
+	[::msgcat::mc "Ispell dictionary encoding. If it is empty,\
+		       system encoding is used."] \
+	-type string \
+	-group Ispell \
+	-command [namespace current]::stop
+
+    custom::defvar options(check_every_symbol) 0 \
+	[::msgcat::mc "Check spell after every entered symbol."] \
+	-type boolean \
+	-group Ispell \
+	-command [namespace current]::stop
+
+    variable misspelled
+    variable word_id 0
+
+    option add *Text.errorColor Red widgetDefault
+    option add *Text.comboColor Blue widgetDefault
+}
+
+#############################################################################
+
+proc ispell::stop {args} {
+    variable pipe
+
+    catch {close $pipe}
+    catch {unset pipe}
+}
+
+#############################################################################
+
+proc ispell::start {} {
+    variable options
+    variable pipe
+
+    set pipe [open "|[list $options(executable)] -a $options(command_line)" r+]
+
+    set version [gets $pipe]
+    if {[cequal $version ""]} {
+	stop
+	return
+    }
+
+    fconfigure $pipe -blocking off -buffering line
+
+    if {![cequal $options(dictionary_encoding) ""]} {
+	fconfigure $pipe -encoding $options(dictionary_encoding)
+    }
+
+    fileevent $pipe readable [namespace current]::process_filter
+}
+
+#############################################################################
+
+proc ispell::process_filter {} {
+    variable pipe
+    variable response
+    variable current_word
+    variable input_window
+    variable misspelled
+
+    set word [read $pipe]
+    if {[string length $word] <= 1} {
+	set response $word
+	return
+    }
+    switch -- [string index $word 0] {
+	\- {
+	    set misspelled($current_word) combo
+	}
+	\& -
+	\? -
+	\# {
+	    set misspelled($current_word) err
+	}
+	default {
+	    set misspelled($current_word) ok
+	}
+    }
+    set response $word
+}
+
+#############################################################################
+
+proc ispell::pipe_word {word} {
+    variable options
+    variable pipe
+    variable response
+    variable current_word
+    variable misspelled
+
+    if {!$options(enable)} return
+
+    set current_word $word
+
+    if {![info exist pipe]} {
+	start
+	if {![info exist pipe]} {
+	    after idle [list NonmodalMessageDlg .ispell_error \
+			     -aspect 50000 \
+			     -icon error \
+			     -message [::msgcat::mc "Could not start ispell\
+						     server. Check your ispell\
+						     path and dictionary name.\
+						     Ispell is disabled now"]]
+	    set options(enable) 0
+	    return
+	}
+    }
+    if {[string length $word] <= 1} {
+	set misspelled($word) ok
+	return
+    }
+    puts $pipe $word
+    vwait [namespace current]::response
+}
+
+#############################################################################
+
+proc ispell::process_word {iw insind} {
+    variable input_window
+    variable misspelled
+    variable word_id
+
+    set wid $word_id
+    incr word_id
+
+    set ins [lindex [split $insind .] 1]
+    set line [$iw get "$insind linestart" "$insind lineend"]
+    set wordstart [string wordstart $line $ins]
+    set wordend   [expr {[string wordend $line $ins] - 1}]
+    set w [crange $line $wordstart $wordend]
+    $iw mark set ispell_wordstart$wid "insert linestart +$wordstart chars"
+    $iw mark set ispell_wordend$wid \
+	"insert linestart +$wordend chars +1 chars"
+    if {[info exists misspelled($w)]} {
+	$iw tag remove err ispell_wordstart$wid ispell_wordend$wid
+	$iw tag remove combo ispell_wordstart$wid ispell_wordend$wid
+	$iw tag add $misspelled($w) \
+	    ispell_wordstart$wid ispell_wordend$wid
+    } elseif {[string length $w] > 1} {
+	pipe_word $w
+	if {![winfo exists $iw]} {
+	    return 0
+	}
+	$iw tag remove err ispell_wordstart$wid ispell_wordend$wid
+	$iw tag remove combo ispell_wordstart$wid ispell_wordend$wid
+	if {[info exists misspelled($w)]} {
+	    $iw tag add $misspelled($w) \
+		ispell_wordstart$wid ispell_wordend$wid
+	}
+    } else {
+	$iw tag remove err ispell_wordstart$wid ispell_wordend$wid
+	$iw tag remove combo ispell_wordstart$wid ispell_wordend$wid
+	$iw mark unset ispell_wordstart$wid
+	$iw mark unset ispell_wordend$wid
+	return 0
+    }
+    $iw mark unset ispell_wordstart$wid
+    $iw mark unset ispell_wordend$wid
+    return 1
+}
+
+#############################################################################
+
+proc ispell::process_line {iw sym} {
+    variable state
+    variable insert_prev
+    variable options
+
+    if {![winfo exists $iw]} {
+	return
+    }
+
+    switch -- $state($iw) {
+	0 {
+	    if {[cequal $sym ""]} {
+		set state($iw) 1
+		# in state 0 it's more likely that the word is to the left
+		# of cursor position
+		set leftword [process_word $iw [$iw index "$insert_prev -1 chars"]]
+		# but in rare cases (BackSpace) the word could be to the right
+		if {!$leftword} {
+		    process_word $iw [$iw index "$insert_prev +0 chars"]
+		}
+	    } elseif {![string is wordchar $sym] && ($sym != "\u0008")} {
+		set state($iw) 1
+		process_word $iw [$iw index "$insert_prev -1 chars"]
+		process_word $iw [$iw index "insert +0 chars"]
+	    } elseif {$options(check_every_symbol)} {
+	        process_word $iw [$iw index "insert -1 chars"]
+	    }
+	}
+	1 {
+	    if {[cequal $sym ""]} {
+		# do nothing
+	    } elseif {![string is wordchar $sym]} {
+		process_word $iw [$iw index "$insert_prev -1 chars"]
+		process_word $iw [$iw index "insert +0 chars"]
+		process_word $iw [$iw index "insert -1 chars"]
+	    } else {
+		set leftword [process_word $iw [$iw index "insert -1 chars"]]
+		set cur_sym [$iw get "insert" "insert +1 chars"]
+		if {!$leftword && ![string is wordchar $cur_sym]} {
+		    set state($iw) 0
+		}
+	    }
+	    
+	}
+    }
+
+    set insert_prev [$iw index "insert"]
+
+    variable after_id
+    unset after_id($iw)
+}
+
+#############################################################################
+
+proc ispell::clear_ispell {iw} {
+    variable misspelled
+    variable state
+    variable insert_prev
+
+    set insert_prev [$iw index "insert"]
+    if {[llength [array names misspelled]] > 2048} {
+	array unset misspelled
+    }
+    set state($iw) 0
+}
+
+#############################################################################
+
+proc ispell::popup_menu {iw x y} {
+    variable response
+
+    set ind [$iw index @$x,$y]
+    lassign [split $ind .] l i
+    set line [$iw get "$ind linestart" "$ind lineend"]
+    set wordstart [string wordstart $line $i]
+    set wordend   [expr {[string wordend $line $i] - 1}]
+    set w [crange $line $wordstart $wordend]
+    pipe_word $w
+    if {[catch { string trim $response } r]} {
+	return
+    }
+    if {[winfo exists [set m .ispellpopupmenu]]} {
+	destroy $m
+    }
+    switch -- [string index $r 0] {
+	\& -
+	\? {
+	    regsub -all {: } $r {:} r
+	    regsub -all {, } $r {,} r
+	    set variants [split [lindex [split $r ":"] 1] ","]
+	    menu $m -tearoff 0
+	    foreach var $variants {
+		$m add command -label "$var" \
+		    -command [list [namespace current]::substitute $iw \
+				   $l.$wordstart $l.[expr {$wordend + 1}] \
+				   $var]
+	    }
+	    tk_popup $m [winfo pointerx .] [winfo pointery .]
+	}
+	\# {
+	    menu $m -tearoff 0
+	    $m add command -label [::msgcat::mc "- nothing -"] -command {}
+	    tk_popup $m [winfo pointerx .] [winfo pointery .]
+	}
+	default {}
+    }
+    
+}
+
+#############################################################################
+
+proc ispell::substitute {iw wordstart wordend sub} {
+    $iw delete $wordstart $wordend
+    $iw insert $wordstart $sub
+}
+
+#############################################################################
+
+proc ispell::key_process {iw key} {
+    if {$key == 65288} {
+	# BackSpace
+	after_process $iw "\u0008"
+    } elseif {$key >= 65280} {
+	# All nonletters
+	after_process $iw ""
+    }
+}
+
+#############################################################################
+
+proc ispell::after_process {iw sym} {
+    variable state
+    variable after_id
+
+    if {![info exists state($iw)]} return
+
+    if {![info exists after_id($iw)]} {
+	set after_id($iw) \
+	    [after idle [list [namespace current]::process_line $iw $sym]]
+    }
+}
+
+hook::add text_on_keypress_hook [namespace current]::ispell::after_process
+
+#############################################################################
+
+proc ispell::setup_bindings {iw} {
+    clear_ispell $iw
+    bind $iw <KeyPress> [list [namespace current]::key_process $iw %N]
+    bind $iw <Return> +[list [namespace current]::clear_ispell $iw]
+    bind $iw <3> [list [namespace current]::popup_menu $iw %x %y]
+    $iw tag configure err -foreground [option get $iw errorColor Text]
+    $iw tag configure combo -foreground [option get $iw comboColor Text]
+}
+
+hook::add text_on_create_hook [namespace current]::ispell::setup_bindings
+
+#############################################################################
+

Deleted: trunk/tkabber/plugins/unix/ispell.tcl
===================================================================
--- trunk/tkabber/plugins/unix/ispell.tcl	2007-01-15 21:06:31 UTC (rev 875)
+++ trunk/tkabber/plugins/unix/ispell.tcl	2007-01-16 16:33:02 UTC (rev 876)
@@ -1,333 +0,0 @@
-# $Id$
-
-package require textutil
-
-namespace eval ispell {
-    custom::defgroup Plugins [::msgcat::mc "Plugins options."] \
-	-group Tkabber
-    custom::defgroup Ispell [::msgcat::mc "Spell check options."] \
-    -group Plugins
-
-    variable options
-
-    custom::defvar options(enable) 0 \
-	[::msgcat::mc "Enable spellchecker in text input windows."] \
-	-type boolean \
-	-group Ispell \
-	-command [namespace current]::stop
-
-    custom::defvar options(executable) /usr/bin/ispell \
-	[::msgcat::mc "Path to the ispell executable."] \
-	-group Ispell \
-	-command [namespace current]::stop
-
-    custom::defvar options(check_every_symbol) 0 \
-	[::msgcat::mc "Check spell after every entered symbol."] \
-	-type boolean \
-	-group Ispell \
-	-command [namespace current]::stop
-
-    custom::defvar options(dictionary) "" \
-	[::msgcat::mc "Ispell dictionary. If it is empty,\
-		       default dictionary is used."] \
-	-type string \
-	-group Ispell \
-	-command [namespace current]::stop
-
-    custom::defvar options(dictionary_encoding) "" \
-	[::msgcat::mc "Ispell dictionary encoding. If it is empty,\
-		       system encoding is used."] \
-	-type string \
-	-group Ispell \
-	-command [namespace current]::stop
-
-    variable misspelled
-    variable word_id 0
-
-    option add *Text.errorColor Red widgetDefault
-    option add *Text.comboColor Blue widgetDefault
-}
-
-proc ispell::stop {args} {
-    variable pipe
-
-    catch {close $pipe}
-    catch {unset pipe}
-}
-
-proc ispell::start {} {
-    variable options
-    variable pipe
-
-    if {[info exists options(dictionary)] \
-	    && ![cequal $options(dictionary)  ""]} {
-	set dict_string "-d [list $options(dictionary)]"
-    } else {
-	set dict_string ""
-    }
-    set pipe [open "|[list $options(executable)] -a $dict_string" r+]
-    set version [gets $pipe]
-    if {[cequal $version ""]} {
-	stop
-	return
-    }
-    if {[info exists options(dictionary_encoding)] \
-	    && ![cequal $options(dictionary_encoding) ""]} {
-	fconfigure $pipe -blocking off \
-			 -buffering line \
-			 -encoding $options(dictionary_encoding)
-    } else {
-	fconfigure $pipe -blocking off \
-			 -buffering line
-    }
-    fileevent $pipe readable [namespace current]::process_filter
-}
-
-proc ispell::process_filter {} {
-    variable pipe
-    variable response
-    variable current_word
-    variable input_window
-    variable misspelled
-
-    set word [read $pipe]
-    if {[string length $word] <= 1} {
-	set response $word
-	return
-    }
-    switch -- [string index $word 0] {
-	\- {
-	    set misspelled($current_word) combo
-	}
-	\& -
-	\? -
-	\# {
-	    set misspelled($current_word) err
-	}
-	default {
-	    set misspelled($current_word) ok
-	}
-    }
-    set response $word
-}
-
-proc ispell::pipe_word {word} {
-    variable options
-    variable pipe
-    variable response
-    variable current_word
-    variable misspelled
-
-    if {!$options(enable)} return
-
-    set current_word $word
-
-    if {![info exist pipe]} {
-	start
-	if {![info exist pipe]} {
-	    after idle [list NonmodalMessageDlg .ispell_error \
-			     -aspect 50000 \
-			     -icon error \
-			     -message [::msgcat::mc "Could not start ispell\
-						     server. Check your ispell\
-						     path and dictionary name.\
-						     Ispell is disabled now"]]
-	    set options(enable) 0
-	    return
-	}
-    }
-    if {[string length $word] <= 1} {
-	set misspelled($word) ok
-	return
-    }
-    puts $pipe $word
-    vwait [namespace current]::response
-}
-
-proc ispell::process_word {iw insind} {
-    variable input_window
-    variable misspelled
-    variable word_id
-
-    set wid $word_id
-    incr word_id
-
-    set ins [lindex [split $insind .] 1]
-    set line [$iw get "$insind linestart" "$insind lineend"]
-    set wordstart [string wordstart $line $ins]
-    set wordend   [expr {[string wordend $line $ins] - 1}]
-    set w [crange $line $wordstart $wordend]
-    $iw mark set ispell_wordstart$wid "insert linestart +$wordstart chars"
-    $iw mark set ispell_wordend$wid \
-	"insert linestart +$wordend chars +1 chars"
-    if {[info exists misspelled($w)]} {
-	$iw tag remove err ispell_wordstart$wid ispell_wordend$wid
-	$iw tag remove combo ispell_wordstart$wid ispell_wordend$wid
-	$iw tag add $misspelled($w) \
-	    ispell_wordstart$wid ispell_wordend$wid
-    } elseif {[string length $w] > 1} {
-	pipe_word $w
-	if {![winfo exists $iw]} {
-	    return 0
-	}
-	$iw tag remove err ispell_wordstart$wid ispell_wordend$wid
-	$iw tag remove combo ispell_wordstart$wid ispell_wordend$wid
-	if {[info exists misspelled($w)]} {
-	    $iw tag add $misspelled($w) \
-		ispell_wordstart$wid ispell_wordend$wid
-	}
-    } else {
-	$iw tag remove err ispell_wordstart$wid ispell_wordend$wid
-	$iw tag remove combo ispell_wordstart$wid ispell_wordend$wid
-	$iw mark unset ispell_wordstart$wid
-	$iw mark unset ispell_wordend$wid
-	return 0
-    }
-    $iw mark unset ispell_wordstart$wid
-    $iw mark unset ispell_wordend$wid
-    return 1
-}
-
-proc ispell::process_line {iw sym} {
-    variable state
-    variable insert_prev
-    variable options
-
-    if {![winfo exists $iw]} {
-	return
-    }
-
-    switch -- $state($iw) {
-	0 {
-	    if {[cequal $sym ""]} {
-		set state($iw) 1
-		# in state 0 it's more likely that the word is to the left of cursor position
-		set leftword [process_word $iw [$iw index "$insert_prev -1 chars"]]
-		# but in rare cases (BackSpace) the word could be to the right
-		if {!$leftword} {
-		    process_word $iw [$iw index "$insert_prev +0 chars"]
-		}
-	    } elseif {![string is wordchar $sym] && ($sym != "\u0008")} {
-		set state($iw) 1
-		process_word $iw [$iw index "$insert_prev -1 chars"]
-		process_word $iw [$iw index "insert +0 chars"]
-	    } elseif {$options(check_every_symbol)} {
-	        process_word $iw [$iw index "insert -1 chars"]
-	    }
-	}
-	1 {
-	    if {[cequal $sym ""]} {
-		# do nothing
-	    } elseif {![string is wordchar $sym]} {
-		process_word $iw [$iw index "$insert_prev -1 chars"]
-		process_word $iw [$iw index "insert +0 chars"]
-		process_word $iw [$iw index "insert -1 chars"]
-	    } else {
-		set leftword [process_word $iw [$iw index "insert -1 chars"]]
-		set cur_sym [$iw get "insert" "insert +1 chars"]
-		if {!$leftword && ![string is wordchar $cur_sym]} {
-		    set state($iw) 0
-		}
-	    }
-	    
-	}
-    }
-
-    set insert_prev [$iw index "insert"]
-
-    variable after_id
-    unset after_id($iw)
-}
-
-proc ispell::clear_ispell {iw} {
-    variable misspelled
-    variable state
-    variable insert_prev
-
-    set insert_prev [$iw index "insert"]
-    if {[info exists misspelled] && \
-	    ([llength [array names misspelled]] > 2048)} {
-	unset misspelled
-    }
-    set state($iw) 0
-}
-    
-proc ispell::popup_menu {iw x y} {
-    variable response
-
-    set ind [$iw index @$x,$y]
-    lassign [split $ind .] l i
-    set line [$iw get "$ind linestart" "$ind lineend"]
-    set wordstart [string wordstart $line $i]
-    set wordend   [expr {[string wordend $line $i] - 1}]
-    set w [crange $line $wordstart $wordend]
-    pipe_word $w
-    if {[catch { string trim $response } r]} {
-	return
-    }
-    if {[winfo exists [set m .ispellpopupmenu]]} {
-	destroy $m
-    }
-    switch -- [string index $r 0] {
-	\& -
-	\? {
-	    regsub -all {: } $r {:} r
-	    regsub -all {, } $r {,} r
-	    set variants [split [lindex [split $r ":"] 1] ","]
-	    menu $m -tearoff 0
-	    foreach var $variants {
-		$m add command -label "$var" \
-		    -command [list [namespace current]::substitute $iw $l.$wordstart $l.[expr $wordend + 1] $var]
-	    }
-	    tk_popup $m [winfo pointerx .] [winfo pointery .]
-	}
-	\# {
-	    menu $m -tearoff 0
-	    $m add command -label [::msgcat::mc "- nothing -"] -command {}
-	    tk_popup $m [winfo pointerx .] [winfo pointery .]
-	}
-	default {}
-    }
-    
-}
-
-proc ispell::substitute {iw wordstart wordend sub} {
-    $iw delete $wordstart $wordend
-    $iw insert $wordstart $sub
-}
-
-proc ispell::key_process {iw key} {
-    if {$key == 65288} {
-	# BackSpace
-	after_process $iw "\u0008"
-    } elseif {$key >= 65280} {
-	# All nonletters
-	after_process $iw ""
-    }
-}
-
-proc ispell::after_process {iw sym} {
-    variable state
-    variable after_id
-
-    if {![info exists state($iw)]} return
-
-    if {![info exists after_id($iw)]} {
-	set after_id($iw) \
-	    [after idle [list [namespace current]::process_line $iw $sym]]
-    }
-}
-
-hook::add text_on_keypress_hook [namespace current]::ispell::after_process
-
-proc ispell::setup_bindings {iw} {
-    clear_ispell $iw
-    bind $iw <KeyPress> [list [namespace current]::key_process $iw %N]
-    bind $iw <Return> +[list [namespace current]::clear_ispell $iw]
-    bind $iw <3> [list [namespace current]::popup_menu $iw %x %y]
-    $iw tag configure err -foreground [option get $iw errorColor Text]
-    $iw tag configure combo -foreground [option get $iw comboColor Text]
-}
-
-hook::add text_on_create_hook [namespace current]::ispell::setup_bindings
-



More information about the Tkabber-dev mailing list