summaryrefslogtreecommitdiff
path: root/support/tcltexed/lib/spelling.tcl
blob: c05e9badedc4a3afb0c201f95d507f69757ced9b (plain)
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
# Copyright (C) 1999 - Martin Strauss - under terms of GPL
##############################################################
proc spell {E mode spell_start spell_end} {
 global T spell_not spell_array spell_yes spell_flag
 if $spell_flag {
  set spell_flag 0 
  switch $mode add {
   if {[lsearch -exact [$E tag names insert] spell] != -1} {
    set ksp1 [$E search -backwards -regexp -- $spell_yes insert {insert linestart}]
    if {$ksp1 == ""} {set ksp1 "insert linestart"} else {append ksp1 +1c}
    set ksp2 [$E search -forwards -regexp -- $spell_yes insert {insert lineend}]
    if {$ksp2 == ""} {set ksp2 "insert lineend"}
    set I [$E get $ksp1 $ksp2]
    switch [tk_messageBox -parent $E -type okcancel -icon question -message $T(spell-1)$I$T(spell-2)] ok {
     if ![info exists spell_array($I)] {
      set spell_array($I) O
      set I_s "spell + [string length $I] chars"
      set I_s1 "spell + [expr [string length $I] +1 ] chars"
      set nowindex [$E search -- $I $spell_start $spell_end]
      while {$nowindex != ""} {
       $E mark set spell $nowindex
       set ksp1 [$E get spell-1c spell]
       set ksp2 [$E get $I_s $I_s1]
       if {[regexp -- $spell_yes $ksp1] != 0} {
        if {[regexp -- $spell_yes $ksp2] != 0} {
         $E tag remove spell spell $I_s
        }
       }
       set nowindex [$E search -- $I spell+1c $spell_end]
      }
     }
    } cancel {
     switch [tk_messageBox -parent $E -type okcancel -icon question -message $T(spell-3)] ok {
      $E mark set insert "insert wordstart"
      InitSearch
      .wsearch.text1 delete 0 end
      .wsearch.text1 insert 0 $I
      .wsearch.text2 delete 0 end
      .wsearch.text2 insert 0 $I
     }
    } 
   }
  } show {
  $E tag remove spell $spell_start $spell_end
  set last ""
  set LISTE [lsort [split [$E get $spell_start $spell_end] $spell_yes]]
  foreach I $LISTE {
   if {[string compare $last $I]!=0} {
    if {[regexp -- $spell_not $I] == 0} {
     if {![info exists spell_array($I)]} {
      if {$I != ""} {
       set I_s "spell + [string length $I] chars"
       set I_s1 "spell + [expr [string length $I] +1 ] chars"
       set nowindex [$E search -- $I $spell_start $spell_end]
       while {$nowindex != ""} {
        $E mark set spell $nowindex
        set ksp1 [$E get spell-1c spell]
        set ksp2 [$E get $I_s $I_s1]
        if {[regexp -- $spell_yes $ksp1] != 0} {
         if {[regexp -- $spell_yes $ksp2] != 0} {
          $E tag add spell spell $I_s
         }
        }
        set nowindex [$E search -- $I spell+1c $spell_end]
       }
   }}}}
   set last $I
  }
 }
 set spell_flag 1
}}
proc spell_load {} {
 global spellfile spellfileown language I_befehl spell_array
 if [file exists $spellfileown$language] then {
  set f [open $spellfileown$language r]
  set LISTE [gets $f]
  close $f
  foreach I $LISTE {set spell_array($I) O}
 }
 if [file exists $spellfile$language] then {
  set f [open $spellfile$language r]
  set LISTE [gets $f]
  close $f
  foreach I $LISTE {set spell_array($I) G}
 }
}
proc spell_save {} {
 global spellfileown language spell_array
 set LISTE ""
 set L [array get spell_array]
 foreach {I V} $L {if {$V == "O"} {lappend LISTE $I}}
 set f [open $spellfileown$language w]
 puts $f [lsort $LISTE]
 close $f
}