2 * lablgtksourceview, OCaml binding for the GtkSourceView text widget
4 * Copyright (C) 2005 Stefano Zacchiroli <zack@cs.unibo.it>
6 * This library is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 2.1 of the
9 * License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 let lang_mime_type = "text/x-c"
25 let lang_file = "test.lang"
26 let use_mime_type = false
27 let font_name = "Monospace 10"
29 let print_lang lang = prerr_endline (sprintf "language: %s" lang#get_name)
31 let print_lang_dirs languages_manager =
33 prerr_endline "lang_dirs:";
35 (fun dir -> incr i; prerr_endline (sprintf "%d: %s" !i dir))
36 languages_manager#lang_files_dirs
38 let win = GWindow.window ~title:"LablGtkSourceView test" ()
39 let vbox = GPack.vbox ~packing:win#add ()
40 let hbox = GPack.hbox ~packing:vbox#add ()
41 let bracket_button = GButton.button ~label:"( ... )" ~packing:hbox#add ()
42 let scrolled_win = GBin.scrolled_window ~packing:vbox#add ()
44 GSourceView.source_view
46 (* ~insert_spaces_instead_of_tabs:true ~tabs_width:2 *)
47 ~show_line_numbers:true
48 ~margin:80 ~show_margin:true
50 ~packing:scrolled_win#add ~height:500 ~width:650
52 (* let languages_manager =
53 GSourceView.source_languages_manager ~lang_files_dirs:["/etc"] () *)
54 let languages_manager = GSourceView.source_languages_manager ()
58 match languages_manager#get_language_from_mime_type lang_mime_type with
59 | None -> failwith (sprintf "no language for %s" lang_mime_type)
63 GSourceView.source_language_from_file ~languages_manager lang_file
65 | None -> failwith (sprintf "can't load %s" lang_file)
68 let matching_bracket () =
69 let iter = source_view#source_buffer#get_iter_at_mark `INSERT in
70 match GSourceView.find_matching_bracket iter with
71 | None -> prerr_endline "no matching bracket"
73 source_view#source_buffer#place_cursor iter;
74 source_view#misc#grab_focus ()
78 let ic = open_in "test.txt" in
79 let size = in_channel_length ic in
80 let buf = String.create size in
81 really_input ic buf 0 size;
85 win#set_allow_shrink true;
86 source_view#misc#modify_font_by_name font_name;
87 print_lang_dirs languages_manager;
89 source_view#source_buffer#set_language lang;
90 source_view#source_buffer#set_highlight true;
91 source_view#source_buffer#set_text text;
92 ignore (win#connect#destroy (fun _ -> GMain.quit ()));
93 ignore (bracket_button#connect#clicked matching_bracket);
94 (* ignore (source_view#connect#move_cursor (fun _ _ ~extend ->
95 prerr_endline "move_cursor"));
96 ignore (source_view#connect#undo (fun _ -> prerr_endline "undo")); *)