[Tkabber-dev] r2157 - in trunk/tkabber: . plugins/chat

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Thu May 8 13:49:13 MSK 2014


Author: sergei
Date: 2014-05-08 13:49:13 +0400 (Thu, 08 May 2014)
New Revision: 2157

Modified:
   trunk/tkabber/ChangeLog
   trunk/tkabber/plugins/chat/completion.tcl
Log:
	* plugins/chat/completion.tcl: Use Shift-Tab to search through the
	  completion choices backward. Also, did a bit of code cleanup.


Modified: trunk/tkabber/ChangeLog
===================================================================
--- trunk/tkabber/ChangeLog	2014-05-06 04:34:17 UTC (rev 2156)
+++ trunk/tkabber/ChangeLog	2014-05-08 09:49:13 UTC (rev 2157)
@@ -1,3 +1,8 @@
+2014-05-08  Sergei Golovan  <sgolovan at nes.ru>
+
+	* plugins/chat/completion.tcl: Use Shift-Tab to search through the
+	  completion choices backward. Also, did a bit of code cleanup.
+
 2014-05-02  Sergei Golovan  <sgolovan at nes.ru>
 
 	* presence.tcl: Fixed caching maximum JID priority for a roster

Modified: trunk/tkabber/plugins/chat/completion.tcl
===================================================================
--- trunk/tkabber/plugins/chat/completion.tcl	2014-05-06 04:34:17 UTC (rev 2156)
+++ trunk/tkabber/plugins/chat/completion.tcl	2014-05-08 09:49:13 UTC (rev 2157)
@@ -15,9 +15,9 @@
     
     hook::run generate_completions_hook \
       $chatid [namespace current]::comps \
-      [clength [$input_window get 1.0 $word_pos]] \
+      [string length [$input_window get 1.0 $word_pos]] \
       [$input_window get 1.0 "end -1c"]
-    set len [clength $word]
+    set len [string length $word]
     set matches {}
     foreach comp $comps {
         if {[string equal -nocase -length $len $word $comp]} {
@@ -28,7 +28,7 @@
     return $matches
 }
 
-proc completion::complete {chatid} {
+proc completion::complete {chatid shift} {
     variable completion
     # completion(state,$chatid) holds state of completion for each chatid.
     # Possible states are:
@@ -40,14 +40,14 @@
     # completion(word,$chatid) holds current word being completed
     # (for the "menu-style" completion)
     #
-    # completion(idx,
+    # completion(idx,$chatid)
     
     variable options
     variable comps {}
 
     # TODO: find out what is this state transition for ...
     if {![info exists completion(state,$chatid)] || \
-	    [cequal $completion(state,$chatid) normal]} {
+	    [string equal $completion(state,$chatid) normal]} {
 	set completion(state,$chatid) completed
     }
 
@@ -63,7 +63,7 @@
 	if {!$n} {return}
         
         # TODO: what is this for?
-	set completion(idx,$chatid) [expr ($completion(idx,$chatid)+1) % $n]
+	set completion(idx,$chatid) [expr {($completion(idx,$chatid)+$shift) % $n}]
 	set comp [lindex $matches $completion(idx,$chatid)]
 
         debugmsg plugins "COMPLETION deleting compstart compent for $comp"
@@ -76,8 +76,8 @@
 
     set ins [lindex [split [$iw index insert] .] 1]
     set line [$iw get "insert linestart" "insert lineend"]
-    set lbefore [crange $line 0 [expr $ins - 1]]
-    #set lafter [crange $line $ins end]
+    set lbefore [string range $line 0 [expr {$ins - 1}]]
+    #set lafter [string range $line $ins end]
 
     # Try to find out what part of the input we are going to complete.
     # If line is empty or consists of a single word, then complete that,
@@ -106,7 +106,7 @@
                 debugmsg plugins "MULTIWORD COMPLETION fallback to single word $word"
                 break
             }
-            set phrasestart [expr $ins - [clength $word]]
+            set phrasestart [expr {$ins - [string length $word]}]
             set matches [get_matching_completions $chatid $iw "insert linestart +$phrasestart chars" $word]
             debugmsg plugins "COMPLETION for $word: $matches"
             if {[llength $matches] == 0} {
@@ -119,19 +119,19 @@
         }
     }
     
-    #set wordstart [expr $ins - [clength $word]]
+    #set wordstart [expr {$ins - [string length $word]}]
     #set word [$iw get "insert -1 chars wordstart" insert]
     debugmsg plugins "COMPLETION: completing $word"
-    set len [clength $word]
+    set len [string length $word]
 
     if {1 || $word != ""} {
-        set wordstart [expr $ins - [clength $word]]
+        set wordstart [expr {$ins - [string length $word]}]
         set matches [get_matching_completions $chatid $iw "insert linestart +$wordstart chars" $word]
 	debugmsg plugins "COMPLETION: $matches"
 
-	if {[llength [lrmdups $matches]] == 1 || \
+	if {[llength [lsort -unique $matches]] == 1 || \
 		$completion(state,$chatid) == "menu_start"} {
-	    set comp [lindex $matches 0]
+	    set comp [lindex $matches [expr {$shift==1?0:"end"}]]
 
             debugmsg plugins "COMPLETION deleting from $wordstart for $comp"
 	    $iw delete "insert linestart +$wordstart chars" insert
@@ -139,7 +139,7 @@
 
 	    if {$completion(state,$chatid) == "menu_start"} {
 		set compstart $wordstart
-		set compend [expr $compstart + [clength $comp]]
+		set compend [expr {$compstart + [string length $comp]}]
 		$iw mark set compstart "insert linestart +$compstart chars"
 		$iw mark gravity compstart left
 		$iw mark set compend "insert linestart +$compend chars"
@@ -147,9 +147,9 @@
 		$iw mark set compins insert
 		set completion(state,$chatid) menu_next
 		set completion(word,$chatid) $word
-		set completion(idx,$chatid) 0
+		set completion(idx,$chatid) [expr {$shift==1?0:[llength $matches]-1}]
 	    }
-	} elseif {[llength [lrmdups $matches]] > 1} {
+	} elseif {[llength [lsort -unique $matches]] > 1} {
 	    set app ""
 	    while {[set ch [same_char $matches $len]] != ""} {
 		debugmsg plugins "COMPLETION APP: $len; $ch"
@@ -226,11 +226,11 @@
 
     if {![info exists completion(state,$chatid)]} return
 
-    if {([cequal $completion(state,$chatid) menu_next] || \
-	    [cequal $completion(state,$chatid) completed]) && \
+    if {([string equal $completion(state,$chatid) menu_next] || \
+	    [string equal $completion(state,$chatid) completed]) && \
 	    [$iw compare insert == {end - 1 chars}]} {
 	set ind [list insert - [string length $options(suffix)] chars]
-	if {[cequal [$iw get $ind insert] $options(suffix)]} {
+	if {[string equal [$iw get $ind insert] $options(suffix)]} {
             debugmsg plugins "COMPLETION deleting suffix"
 	    $iw delete $ind insert
 	}
@@ -267,8 +267,11 @@
     debugmsg plugins "COMPLETION TAGS: $bt"
 
     bind $cc <Key-Tab> \
-	[list [namespace current]::complete [double% $chatid]]
+	[list [namespace current]::complete [double% $chatid] 1]
     bind $cc <Key-Tab> +break
+    bind $cc <Shift-Tab> \
+	[list [namespace current]::complete [double% $chatid] -1]
+    bind $cc <Shift-Tab> +break
     bind $cc <Key-Return> \
 	[list [namespace current]::delete_suffix [double% $chatid]]
     bind $cc <KeyPress> \



More information about the Tkabber-dev mailing list