TKE  3.6
Advanced code editor for programmers
cliphist Namespace Reference

Functions

 load
 
 save
 
 add_from_clipboard
 
 add_detail str txt
 
 add_to_clipboard str
 
 get_history
 
 show_cliphist
 
 printable_hist
 
 handle_cliphist_depth name1 name2 op
 

Function Documentation

§ add_detail()

cliphist::add_detail   str txt  

Definition at line 121 of file cliphist.tcl.

121  proc add_detail {str txt} {
122 
123  $txt insert end $str
124 
125  }

§ add_from_clipboard()

cliphist::add_from_clipboard

Definition at line 88 of file cliphist.tcl.

88  proc add_from_clipboard {} {
89 
90  variable hist
91 
92  # Get the clipboard content
93  set str [string map {\{ \\\{} [clipboard get]]
94 
95  if {[string trim $str] ne ""} {
96 
97  # If the string doesn't exist in history, add it
98  if {[set index [lsearch -exact $hist $str]] == -1} {
99 
100  # Append the string to the history file
101  lappend hist $str
102 
103  # Trim the history to meet the maxsize requirement, if necessary
104  if {[llength $hist] > [preferences::get Editor/ClipboardHistoryDepth]} {
105  set hist [lrange $hist 1 end]
106  }
107 
108  # Otherwise, move the current string to the beginning of the history
109  } else {
110 
111  set hist [linsert [lreplace $hist $index $index] end $str]
112 
113  }
114 
115  }
116 
117  }

§ add_to_clipboard()

cliphist::add_to_clipboard   str  

Definition at line 131 of file cliphist.tcl.

131  proc add_to_clipboard {str} {
132 
133  # Add the string to the clipboard
134  clipboard clear
135  clipboard append [string map {\\\{ \{} $str]
136 
137  # We need to make sure that this string is updated within the clipboard
139 
140  # Insert the string in the current text widget
142 
143  }

§ get_history()

cliphist::get_history

Definition at line 149 of file cliphist.tcl.

149  proc get_history {} {
150 
151  variable hist
152 
153  set items [list]
154 
155  foreach item [lreverse $hist] {
156  set lines [split $item \n]
157  set short [lindex $lines 0]
158  if {[llength $lines] > 1} {
159  append short " ..."
160  }
161  lappend items [list [string map {\\\{ \{} $short] [string map {\\\{ \{} $item]]
162  }
163 
164  return $items
165 
166  }

§ handle_cliphist_depth()

cliphist::handle_cliphist_depth   name1 name2 op  

Definition at line 199 of file cliphist.tcl.

199  proc handle_cliphist_depth {name1 name2 op} {
200 
201  variable hist
202 
203  if {[set diff [expr [llength $hist] - [preferences::get Editor/ClipboardHistoryDepth]]] > 0} {
204  set hist [lrange $hist $diff end]
205  }
206 
207  }

§ load()

cliphist::load

Definition at line 32 of file cliphist.tcl.

32  proc load {} {
33 
34  variable cliphist_file
35  variable hist
36 
37  if {![catch { open $cliphist_file r} rc]} {
38 
39  # Read the contents of the file
40  set contents [read $rc]
41  close $rc
42 
43  # Parse the file
44  set in_history 0
45  foreach line [split $contents \n] {
46  if {$line eq "clipping:"} {
47  set in_history 1
48  set clipping ""
49  } elseif {$in_history && [regexp {^\t(.*)$} $line -> str]} {
50  append clipping "$str\n"
51  } elseif {$in_history} {
52  set clipping [string range $clipping 0 end-1]
53  set in_history 0
54  lappend hist $clipping
55  }
56  }
57 
58  }
59 
60  # Handle any changes to the clipboard history depth
61  trace variable preferences::prefs(Editor/ClipboardHistoryDepth) w cliphist::handle_cliphist_depth
62 
63  }

§ printable_hist()

cliphist::printable_hist

Definition at line 189 of file cliphist.tcl.

189  proc printable_hist {} {
190 
191  variable hist
192 
193  return [format { -%s } [join $hist "\n -"]]
194 
195  }

§ save()

cliphist::save

Definition at line 68 of file cliphist.tcl.

68  proc save {} {
69 
70  variable cliphist_file
71  variable hist
72 
73  if {![catch { open $cliphist_file w} rc]} {
74  foreach clipping $hist {
75  puts $rc "clipping:"
76  foreach line [split $clipping \n] {
77  puts $rc "\t$line"
78  }
79  puts $rc ""
80  }
81  close $rc
82  }
83 
84  }

§ show_cliphist()

cliphist::show_cliphist

Definition at line 170 of file cliphist.tcl.

170  proc show_cliphist {} {
171 
172  variable hist
173 
174  # Add temporary registries to launcher
175  set i 0
176  foreach strs [get_history] {
177  lassign $strs name str
178  launcher::register_temp "`CLIPHIST:$name" [list cliphist::add_to_clipboard $str] $name $i [list cliphist::add_detail $str]
179  incr i
180  }
181 
182  # Display the launcher in CLIPHIST: mode
183  launcher::launch "`CLIPHIST:" 1
184 
185  }