]> matita.cs.unibo.it Git - helm.git/commitdiff
fixed segfault issue with matching bracket search
authorStefano Zacchiroli <zack@upsilon.cc>
Sat, 11 Jun 2005 10:23:27 +0000 (10:23 +0000)
committerStefano Zacchiroli <zack@upsilon.cc>
Sat, 11 Jun 2005 10:23:27 +0000 (10:23 +0000)
helm/DEVEL/lablgtksourceview/ACKNOWLEDGEMENTS [new file with mode: 0644]
helm/DEVEL/lablgtksourceview/ml_gtk_sourceview.c
helm/DEVEL/lablgtksourceview/test/test.lang [new file with mode: 0644]
helm/DEVEL/lablgtksourceview/test/test.ml

diff --git a/helm/DEVEL/lablgtksourceview/ACKNOWLEDGEMENTS b/helm/DEVEL/lablgtksourceview/ACKNOWLEDGEMENTS
new file mode 100644 (file)
index 0000000..e69de29
index 5d813d446edd28635e3cfd354880188ebbec2088..965618d2662737c598cbbcad3fae3cacd3bc544f 100644 (file)
@@ -90,7 +90,7 @@ ml_gtk_source_languages_manager_set_lang_files_dirs(GObject *obj, value list)
 #define GtkSourceTagTable_val(val) check_cast(GTK_SOURCE_TAG_TABLE,val)
 #define GtkSourceBuffer_val(val) check_cast(GTK_SOURCE_BUFFER,val)
 #define GtkSourceView_val(val) check_cast(GTK_SOURCE_VIEW,val)
-#define GtkTextIter_val(val) ((GtkTextIter*)Data_custom_val(val))
+#define GtkTextIter_val(val) ((GtkTextIter*)MLPointer_val(val))
 #define Val_option_GtkAny(v) Val_option(v,Val_GtkAny)
 #define string_list_of_GSList(l) Val_GSList(l, (value_in) Val_string)
 /* #define GSList_of_string_list(l) GSList_val(l, String_val) */
diff --git a/helm/DEVEL/lablgtksourceview/test/test.lang b/helm/DEVEL/lablgtksourceview/test/test.lang
new file mode 100644 (file)
index 0000000..0478120
--- /dev/null
@@ -0,0 +1,128 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE language SYSTEM "language.dtd">
+<language _name="C" version="1.0" _section="Sources" mimetypes="text/x-c;text/x-chdr;text/x-csrc">
+       
+       <escape-char>\</escape-char>
+
+       <line-comment _name = "Line Comment" style= "Comment">
+               <start-regex>//</start-regex>
+       </line-comment>
+
+       <block-comment _name = "Block Comment" style = "Comment">
+               <start-regex>/\*</start-regex>
+               <end-regex>\*/</end-regex>
+       </block-comment>
+
+       <block-comment _name = "'#if 0' Comment" style = "Comment">
+               <start-regex>^[ \t]*#[ \t]*if[ \t]*0</start-regex>
+               <end-regex>[ \t]*#[ \t]*(endif|else)</end-regex>
+       </block-comment>
+
+       <string _name = "String" style = "String" end-at-line-end = "TRUE">
+               <start-regex>&quot;</start-regex>
+               <end-regex>&quot;</end-regex>
+       </string>
+
+       <syntax-item _name = "Include/Pragma" style = "Preprocessor">
+               <start-regex>^#[ \t]*(include|pragma)</start-regex>
+                <end-regex>\n</end-regex>
+       </syntax-item>
+
+       <keyword-list _name = "Keywords" style = "Keyword" case-sensitive="TRUE">
+               <keyword>asm</keyword>
+               <keyword>break</keyword>
+               <keyword>case</keyword>
+               <keyword>continue</keyword>
+               <keyword>default</keyword>
+               <keyword>do</keyword>
+               <keyword>else</keyword>
+               <keyword>for</keyword>
+               <keyword>fortran</keyword>
+               <keyword>goto</keyword>
+               <keyword>if</keyword>
+               <keyword>return</keyword>
+               <keyword>sizeof</keyword>
+               <keyword>switch</keyword>
+               <keyword>while</keyword>
+       </keyword-list>
+
+       <keyword-list _name = "Types" style = "Data Type" case-sensitive="TRUE">
+               <keyword>_Bool</keyword>
+               <keyword>_Complex</keyword>
+               <keyword>_Imaginary</keyword>
+               <keyword>auto</keyword>
+               <keyword>char</keyword>
+               <keyword>const</keyword>
+               <keyword>double</keyword>
+               <keyword>enum</keyword>
+               <keyword>extern</keyword>
+               <keyword>float</keyword>
+               <keyword>int</keyword>
+               <keyword>inline</keyword>
+               <keyword>long</keyword>
+               <keyword>register</keyword>
+               <keyword>restrict</keyword>
+               <keyword>short</keyword>
+               <keyword>signed</keyword>
+               <keyword>static</keyword>
+               <keyword>struct</keyword>
+               <keyword>typedef</keyword>
+               <keyword>union</keyword>
+               <keyword>unsigned</keyword>
+               <keyword>void</keyword>
+               <keyword>volatile</keyword>
+       </keyword-list>
+
+       <string _name = "Character Constant" style = "String" end-at-line-end = "TRUE">
+               <start-regex>&apos;</start-regex>
+               <end-regex>&apos;</end-regex>
+       </string>
+
+       <pattern-item _name = "Decimal" style = "Decimal">
+               <regex>\b([1-9][0-9]*|0)([Uu]([Ll]|LL|ll)?|([Ll]|LL|ll)[Uu]?)?\b</regex>
+       </pattern-item>
+
+       <pattern-item _name = "Floating Point Number" style = "Floating Point">
+               <regex>\b([0-9]+[Ee][-]?[0-9]+|([0-9]*\.[0-9]+|[0-9]+\.)([Ee][-]?[0-9]+)?)[fFlL]?</regex>
+       </pattern-item>
+
+       <pattern-item _name = "Octal Number" style = "Base-N Integer">
+               <regex>\b0[0-7]+([Uu]([Ll]|LL|ll)?|([Ll]|LL|ll)[Uu]?)?\b</regex>
+       </pattern-item>
+
+       <pattern-item _name = "Hex Number" style = "Base-N Integer">
+               <regex>\b0[xX][0-9a-fA-F]+([Uu]([Ll]|LL|ll)?|([Ll]|LL|ll)[Uu]?)?\b</regex>
+       </pattern-item>
+
+       <keyword-list _name = "Common Macro" style = "Preprocessor" case-sensitive="TRUE">
+               <keyword>NULL</keyword>
+               <keyword>TRUE</keyword>
+               <keyword>FALSE</keyword>
+               <keyword>MAX</keyword>
+               <keyword>MIN</keyword>
+               <keyword>__LINE__</keyword>
+               <keyword>__DATA__</keyword>
+               <keyword>__FILE__</keyword>
+               <keyword>__func__</keyword>
+               <keyword>__TIME__</keyword>
+               <keyword>__STDC__</keyword>
+       </keyword-list>
+
+       <keyword-list _name = "Preprocessor Definitions" style = "Preprocessor" case-sensitive="TRUE"
+               match-empty-string-at-beginning = "FALSE"
+               match-empty-string-at-end = "TRUE"
+               beginning-regex = "^[ \t]*#[ \t]*">
+               <keyword>if</keyword>
+               <keyword>ifdef</keyword>
+               <keyword>ifndef</keyword>
+               <keyword>else</keyword>
+               <keyword>elif</keyword>
+               <keyword>define</keyword>
+               <keyword>endif</keyword>
+               <keyword>undef</keyword>
+               <keyword>error</keyword>
+               <keyword>pragma</keyword>
+               <keyword>line</keyword>
+       </keyword-list>
+
+</language>
index ed9622af19519874b19118c0e54ef0876e6302dd..d0e140249b0ca9af99e1d6d009543c2e188e8124 100644 (file)
@@ -1,26 +1,22 @@
-(* Copyright (C) 2005:
- *     Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>,
- *     Stefano Zacchiroli     <zack@cs.unibo.it>
+(*
+ * lablgtksourceview, OCaml binding for the GtkSourceView text widget
  *
- * This file is part of lablgtksourceview, the OCaml binding for the
- * GtkSourceView widget.
+ * Copyright (C) 2005  Stefano Zacchiroli <zack@cs.unibo.it>
  * 
- * lablgtksourceview is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of the
  * License, or (at your option) any later version.
- *
- * lablgtksourceview is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * 
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with lablgtksourceview; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
+ * Lesser General Public License for more details.
  * 
- * For details, send a mail to the authors.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
  *)
 
 open Printf
@@ -28,6 +24,7 @@ open Printf
 let lang_mime_type = "text/x-c"
 let lang_file = "test.lang"
 let use_mime_type = false
+let font_name = "Monospace 10"
 
 let print_lang lang = prerr_endline (sprintf "language: %s" lang#get_name)
 
@@ -39,7 +36,10 @@ let print_lang_dirs languages_manager =
     languages_manager#lang_files_dirs
 
 let win = GWindow.window ~title:"LablGtkSourceView test" ()
-let scrolled_win = GBin.scrolled_window ~packing:win#add ()
+let vbox = GPack.vbox ~packing:win#add ()
+let hbox = GPack.hbox ~packing:vbox#add ()
+let bracket_button = GButton.button ~label:"( ... )" ~packing:hbox#add ()
+let scrolled_win = GBin.scrolled_window ~packing:vbox#add ()
 let source_view =
   GSourceView.source_view
     ~auto_indent:true
@@ -52,6 +52,7 @@ let source_view =
 (* let languages_manager =
   GSourceView.source_languages_manager ~lang_files_dirs:["/etc"] () *)
 let languages_manager = GSourceView.source_languages_manager ()
+
 let lang =
   if use_mime_type then
     match languages_manager#get_language_from_mime_type lang_mime_type with 
@@ -63,6 +64,15 @@ let lang =
     with
     | None -> failwith (sprintf "can't load %s" lang_file)
     | Some lang -> lang
+
+let matching_bracket () =
+  let iter = source_view#source_buffer#get_iter_at_mark `INSERT in
+  match GSourceView.find_matching_bracket iter with
+  | None -> prerr_endline "no matching bracket"
+  | Some iter ->
+      source_view#source_buffer#place_cursor iter;
+      source_view#misc#grab_focus ()
+
 let _ =
   let text =
     let ic = open_in "test.txt" in
@@ -73,13 +83,14 @@ let _ =
     buf
   in
   win#set_allow_shrink true;
-  source_view#misc#modify_font_by_name "Monospace 10";
+  source_view#misc#modify_font_by_name font_name;
   print_lang_dirs languages_manager;
   print_lang lang;
   source_view#source_buffer#set_language lang;
   source_view#source_buffer#set_highlight true;
   source_view#source_buffer#set_text text;
   ignore (win#connect#destroy (fun _ -> GMain.quit ()));
+  ignore (bracket_button#connect#clicked matching_bracket);
 (*   ignore (source_view#connect#move_cursor (fun _ _ ~extend ->
     prerr_endline "move_cursor"));
   ignore (source_view#connect#undo (fun _ -> prerr_endline "undo")); *)