summaryrefslogtreecommitdiff
blob: 0001ae75acaa5d779992ae1800cc13b4cae83509 (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
(***********************************************************************)
(*                                                                     *)
(*                 MLTk, Tcl/Tk interface of Objective Caml            *)
(*                                                                     *)
(*    Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis    *)
(*               projet Cristal, INRIA Rocquencourt                    *)
(*            Jacques Garrigue, Kyoto University RIMS                  *)
(*                                                                     *)
(*  Copyright 2002 Institut National de Recherche en Informatique et   *)
(*  en Automatique and Kyoto University.  All rights reserved.         *)
(*  This file is distributed under the terms of the GNU Library        *)
(*  General Public License, with the special exception on linking      *)
(*  described in file LICENSE found in the Objective Caml source tree. *)
(*                                                                     *)
(***********************************************************************)
open Tk

let top = opentk ()

let scroll_link sb tx =
  Text.configure tx [YScrollCommand (Scrollbar.set sb)];
  Scrollbar.configure sb [ScrollCommand (Text.yview tx)]

let f = Frame.create top []
let text = Text.create f []
let scrollbar = Scrollbar.create f []

let buffer = ref ""

let kill () =
  buffer := 
     Text.get text (TextIndex (Insert, []))
                   (TextIndex (Insert, [LineEnd]));
     Text.delete text (TextIndex (Insert, []))
                   (TextIndex (Insert, [LineEnd]))
;;

let yank () =
  Text.insert text (TextIndex (Insert, [])) !buffer [] 

let _ = bind text [[Control], KeyPressDetail "y"] (BindSet ([], fun _ ->
  yank () ))
;;
let _ = bind text [[Control], KeyPressDetail "k"] (BindSet ([], fun _ ->
  kill () ))
;;

let _ =
  scroll_link scrollbar text;

  pack [text;f][];
  pack [f][];
  mainLoop ()
;;