]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/matita/matitaGui.ml
Ok, even if not stated formally, now we know that the map from REL to OA is
[helm.git] / helm / software / matita / matitaGui.ml
index f0bd8acc027f42e076eb143a8b155ae2f7150fee..ded9c83aa46dee4136af781f481d0a469321841c 100644 (file)
@@ -201,6 +201,7 @@ class interpErrorModel =
         tree_store#get ~row:iter ~column:interp_no_col
     end
 
+exception UseLibrary;;
 
 let rec interactive_error_interp ~all_passes
   (source_buffer:GSourceView.source_buffer) notify_exn offset errorll filename
@@ -347,9 +348,7 @@ let rec interactive_error_interp ~all_passes
             return ()
         );
        connect_button dialog#disambiguationErrorsMoreErrors
-        (fun _ -> return () ;
-          interactive_error_interp ~all_passes:true source_buffer
-           notify_exn offset errorll filename);
+        (fun _ -> return () ; raise UseLibrary);
        connect_button dialog#disambiguationErrorsCancelButton fail;
        dialog#disambiguationErrors#show ();
        GtkThread.main ()
@@ -396,11 +395,13 @@ class gui () =
     val mutable _only_directory = false
     val mutable font_size = default_font_size
     val mutable similarsymbols = []
+    val mutable similarsymbols_orig = []
     val clipboard = GData.clipboard Gdk.Atom.clipboard
     val primary = GData.clipboard Gdk.Atom.primary
       
     method private reset_similarsymbols =
       similarsymbols <- []; 
+      similarsymbols_orig <- []; 
       try source_buffer#delete_mark similarsymbols_tag
       with GText.No_such_mark _ -> ()
    
@@ -651,7 +652,8 @@ class gui () =
       connect_menu_item main#ligatureButton self#nextSimilarSymbol;
       ignore(source_buffer#connect#after#insert_text 
        ~callback:(fun iter str -> 
-          if false && str = " " then self#expand_virtual_if_any iter " "));
+          if main#menuitemAutoAltL#active && (str = " " || str = "\n") then 
+            ignore(self#expand_virtual_if_any iter str)));
       ignore (findRepl#findEntry#connect#activate find_forward);
         (* interface lockers *)
       let lock_world _ =
@@ -701,8 +703,11 @@ class gui () =
        let thread_main =
         fun () -> 
           lock_world ();
+          let saved_use_library= !MultiPassDisambiguator.use_library in
           try
+           MultiPassDisambiguator.use_library := !all_disambiguation_passes;
            f ();
+           MultiPassDisambiguator.use_library := saved_use_library;
            unlock_world ()
           with
            | MultiPassDisambiguator.DisambiguationError (offset,errorll) ->
@@ -711,7 +716,17 @@ class gui () =
                  ~all_passes:!all_disambiguation_passes source_buffer
                  notify_exn offset errorll (s())#filename
                with
-                exc -> notify_exn exc);
+                | UseLibrary ->
+                   MultiPassDisambiguator.use_library := true;
+                   (try f ()
+                    with
+                    | MultiPassDisambiguator.DisambiguationError (offset,errorll) ->
+                       interactive_error_interp ~all_passes:true source_buffer
+                        notify_exn offset errorll (s())#filename
+                    | exc ->
+                       notify_exn exc);
+                | exc -> notify_exn exc);
+              MultiPassDisambiguator.use_library := saved_use_library;
               unlock_world ()
            | exc ->
               notify_exn exc;
@@ -1107,9 +1122,12 @@ class gui () =
          ~stop:(iter#copy#backward_chars
            (MatitaGtkMisc.utf8_string_length inplaceof + len));
        source_buffer#insert ~iter:(source_buffer#get_iter_at_mark `INSERT) 
-         (if inplaceof.[0] = '\\' then s else (s ^ tok))
-      with Virtuals.Not_a_virtual -> ()
+         (if inplaceof.[0] = '\\' then s else (s ^ tok));
+       true
+      with Virtuals.Not_a_virtual -> false
          
+    val similar_memory = Hashtbl.create 97
+
     method private nextSimilarSymbol () = 
       let write_similarsymbol s =
         let s = Glib.Utf8.from_unichar s in
@@ -1130,25 +1148,31 @@ class gui () =
         with GText.No_such_mark _ -> true
       in
       if new_similarsymbol then
+        (if not(self#expand_virtual_if_any (source_buffer#get_iter_at_mark `INSERT) "")then
           let last_symbol = 
             let i = source_buffer#get_iter_at_mark `INSERT in
             Glib.Utf8.first_char (i#get_slice ~stop:(i#copy#backward_chars 1))
           in
           (match Virtuals.similar_symbols last_symbol with
-          | [] -> 
-              let i = source_buffer#get_iter_at_mark `INSERT in
-              self#expand_virtual_if_any i ""
-          | hd :: next ::tl ->
+          | [] ->  ()
+          | eqclass ->
+              similarsymbols_orig <- eqclass;
+              let hd, next, tl = 
+                match 
+                  try Hashtbl.find similar_memory similarsymbols_orig  
+                  with Not_found -> Hashtbl.add similar_memory eqclass eqclass; eqclass
+                with a::b::c -> a,b,c | _ -> assert false
+              in
               let hd, tl = 
                 if hd = last_symbol then next, tl @ [hd] else hd, (next::tl)
               in
               write_similarsymbol hd;
-              similarsymbols <- tl @ [ hd ]
-          | _ -> assert false) (* singleton eq classes are a non sense *)
+              similarsymbols <- tl @ [ hd ]))
       else 
         match similarsymbols with
         | [] -> ()
         | hd :: tl ->
+            Hashtbl.replace similar_memory similarsymbols_orig similarsymbols;
             similarsymbols <- tl @ [ hd ];
             write_similarsymbol hd