1
(***********************************************************************)
5
(* Pierre Weis, projet Cristal, INRIA Rocquencourt *)
7
(* Copyright 2001, 2004 Institut National de Recherche en Informatique *)
8
(* et en Automatique. All rights reserved. This file is distributed *)
9
(* only by permission. *)
11
(***********************************************************************)
13
(* $Id: mytext.ml,v 1.2 2004/07/07 09:39:15 weis Exp $ *)
15
(* A text widget with kill and yank capabilities ``� la'' Emacs. *)
21
let scroll_link sb tx =
22
Text.configure tx [YScrollCommand (Scrollbar.set sb)];
23
Scrollbar.configure sb [ScrollCommand (Text.yview tx)];;
25
let f = Frame.create top [];;
26
let text = Text.create f [];;
27
let scrollbar = Scrollbar.create f [];;
30
let kill_ring = ref [];;
32
let add_to_kill_ring s = kill_ring := s :: !kill_ring;;
34
let get_killed_text () =
39
(* Note: for the text widgets, the insertion cursor is
40
not TextIndex (Insert, []),
41
but TextIndex (Mark "insert", []) *)
42
let insertMark = TextIndex (Mark "insert", []);;
43
let eol_insertMark = TextIndex (Mark "insert", [LineEnd]);;
46
let s = Text.get text insertMark eol_insertMark in
48
prerr_endline ("Killed: " ^ s);
49
Text.delete text insertMark eol_insertMark;;
52
let s = get_killed_text () in
53
Text.insert text insertMark s [];
54
prerr_endline ("Yanked: " ^ s);;
57
let ring = !kill_ring in
58
let more = ref ring in
59
let rec get_killed_more () =
61
| [] -> more := ring; get_killed_more ()
62
| s :: l -> more := l; s in
63
let insert_killed_more () =
64
let s = get_killed_more () in
65
prerr_endline ("Yanked more: " ^ s);
66
Text.insert text insertMark s [] in
67
insert_killed_more ();
68
bind text [[Alt], KeyPressDetail "y"]
69
(BindSet ([], fun _ -> insert_killed_more ()));;
72
scroll_link scrollbar text;
74
pack [text; scrollbar][Side Side_Left; Fill Fill_Y];
77
bind text [[Control], KeyPressDetail "y"]
78
(BindSet ([], fun _ -> yank ()));
80
bind text [[Alt], KeyPressDetail "y"]
81
(BindSet ([], fun _ -> yank_more () ));
83
bind text [[Control], KeyPressDetail "k"]
84
(BindSet ([], fun _ -> kill () ));
86
bind text [[Control], KeyPressDetail "c"]
87
(BindSet ([], fun _ -> exit 0 ));