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
String.concat "\n"
("" ::
List.map
- (fun k,value ->
- DisambiguatePp.pp_environment
- (DisambiguateTypes.Environment.add k
- (value,(fun _ _ _ -> Cic.Implicit None))
- DisambiguateTypes.Environment.empty))
+ (fun k,desc ->
+ let alias =
+ match k with
+ | DisambiguateTypes.Id id ->
+ LexiconAst.Ident_alias (id, desc)
+ | DisambiguateTypes.Symbol (symb, i)->
+ LexiconAst.Symbol_alias (symb, i, desc)
+ | DisambiguateTypes.Num i ->
+ LexiconAst.Number_alias (i, desc)
+ in
+ LexiconAstPp.pp_alias alias)
diff) ^ "\n"
in
source_buffer#insert
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 ()
Helm_registry.get_opt_default Helm_registry.int
~default:BuildTimeConf.default_font_size "matita.font_size"
in
+ let similarsymbols_tag_name = "similarsymbolos" in
+ let similarsymbols_tag = `NAME similarsymbols_tag_name in
let source_buffer = source_view#source_buffer in
object (self)
val mutable chosen_file = None
val mutable _ok_not_exists = false
val mutable _only_directory = false
val mutable font_size = default_font_size
- val mutable next_ligatures = []
+ val mutable similarsymbols = []
val clipboard = GData.clipboard Gdk.Atom.clipboard
val primary = GData.clipboard Gdk.Atom.primary
+
+ method private reset_similarsymbols =
+ similarsymbols <- [];
+ try source_buffer#delete_mark similarsymbols_tag
+ with GText.No_such_mark _ -> ()
initializer
let s () = MatitaScript.current () in
source_buffer#move_mark `SEL_BOUND source_buffer#end_iter);
connect_menu_item main#findReplMenuItem show_find_Repl;
connect_menu_item main#externalEditorMenuItem self#externalEditor;
- connect_menu_item main#ligatureButton self#nextLigature;
+ connect_menu_item main#ligatureButton self#nextSimilarSymbol;
+ ignore(source_buffer#connect#after#insert_text
+ ~callback:(fun iter str ->
+ if main#menuitemAutoAltL#active && str = " " then
+ ignore(self#expand_virtual_if_any iter " ")));
ignore (findRepl#findEntry#connect#activate find_forward);
(* interface lockers *)
let lock_world _ =
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) ->
~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;
notify_exn exn
else raise exn);
(* script *)
- ignore (source_buffer#connect#mark_set (fun _ _ -> next_ligatures <- []));
let _ =
match GSourceView.source_language_from_file BuildTimeConf.lang_file with
| None ->
method pastePattern () =
source_view#buffer#insert (MatitaMathView.paste_clipboard `Pattern)
- method private nextLigature () =
- let iter = source_buffer#get_iter_at_mark `INSERT in
- let write_ligature len s =
+ method private expand_virtual_if_any iter tok =
+ try
+ let len = MatitaGtkMisc.utf8_string_length tok in
+ let last_word =
+ let prev = iter#copy#backward_chars len in
+ prev#get_slice ~stop:(prev#copy#backward_find_char
+ (fun x -> Glib.Unichar.isspace x || x = Glib.Utf8.first_char "\\"))
+ in
+ let inplaceof, symb = Virtuals.symbol_of_virtual last_word in
+ self#reset_similarsymbols;
+ let s = Glib.Utf8.from_unichar symb in
+ let iter = source_buffer#get_iter_at_mark `INSERT in
+ assert(Glib.Utf8.validate s);
+ source_buffer#delete ~start:iter
+ ~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));
+ true
+ with Virtuals.Not_a_virtual -> false
+
+ method private nextSimilarSymbol () =
+ let write_similarsymbol s =
+ let s = Glib.Utf8.from_unichar s in
+ let iter = source_buffer#get_iter_at_mark `INSERT in
assert(Glib.Utf8.validate s);
- source_buffer#delete ~start:iter ~stop:(iter#copy#backward_chars len);
- source_buffer#insert ~iter:(source_buffer#get_iter_at_mark `INSERT) s
+ source_buffer#delete ~start:iter ~stop:(iter#copy#backward_chars 1);
+ source_buffer#insert ~iter:(source_buffer#get_iter_at_mark `INSERT) s;
+ (try source_buffer#delete_mark similarsymbols_tag
+ with GText.No_such_mark _ -> ());
+ ignore(source_buffer#create_mark ~name:similarsymbols_tag_name
+ (source_buffer#get_iter_at_mark `INSERT));
in
- let get_ligature word =
- let len = String.length word in
- let aux_tex () =
- try
- for i = len - 1 downto 0 do
- if HExtlib.is_alpha word.[i] then ()
- else
- (if word.[i] = '\\' then raise (Found i) else raise (Found ~-1))
- done;
- None
- with Found i ->
- if i = ~-1 then None else Some (String.sub word i (len - i))
- in
- let aux_ligature () =
- try
- for i = len - 1 downto 0 do
- if CicNotationLexer.is_ligature_char word.[i] then ()
- else raise (Found (i+1))
- done;
- raise (Found 0)
- with
- | Found i ->
- (try
- Some (String.sub word i (len - i))
- with Invalid_argument _ -> None)
- in
- match aux_tex () with
- | Some macro -> macro
- | None -> (match aux_ligature () with Some l -> l | None -> word)
+ let new_similarsymbol =
+ try
+ let iter_ins = source_buffer#get_iter_at_mark `INSERT in
+ let iter_lig = source_buffer#get_iter_at_mark similarsymbols_tag in
+ not (iter_ins#equal iter_lig)
+ with GText.No_such_mark _ -> true
in
- (match next_ligatures with
- | [] -> (* find ligatures and fill next_ligatures, then try again *)
- let last_word =
- iter#get_slice
- ~stop:(iter#copy#backward_find_char Glib.Unichar.isspace)
+ 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
- let ligature = get_ligature last_word in
- (match CicNotationLexer.lookup_ligatures ligature with
- | [] -> ()
- | hd :: tl ->
- write_ligature (MatitaGtkMisc.utf8_string_length ligature) hd;
- next_ligatures <- tl @ [ hd ])
- | hd :: tl ->
- write_ligature 1 hd;
- next_ligatures <- tl @ [ hd ])
+ (match Virtuals.similar_symbols last_symbol with
+ | [] -> ()
+ | hd :: next ::tl ->
+ 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 *)
+ else
+ match similarsymbols with
+ | [] -> ()
+ | hd :: tl ->
+ similarsymbols <- tl @ [ hd ];
+ write_similarsymbol hd
method private externalEditor () =
let cmd = Helm_registry.get "matita.external_editor" in
let txt,_ = MatitaGtkMisc.utf8_parsed_text txt
(HExtlib.floc_of_loc (prefix_len,MatitaGtkMisc.utf8_string_length txt))
in
- prerr_endline ("txt:" ^ txt);
dialog#uriChoiceLabel#set_label txt;
List.iter model#easy_append uris;
let return v =
let _ =
(* disambiguator callbacks *)
- MultiPassDisambiguator.set_choose_uris_callback
+ Disambiguate.set_choose_uris_callback
(fun ~selection_mode ?ok ?(enable_button_for_non_vars=false) ~title ~msg ->
interactive_uri_choice ~selection_mode ?ok_label:ok ~title ~msg ());
- MultiPassDisambiguator.set_choose_interp_callback (interactive_interp_choice ());
+ Disambiguate.set_choose_interp_callback (interactive_interp_choice ());
(* gtk initialization *)
GtkMain.Rc.add_default_file BuildTimeConf.gtkrc_file; (* loads gtk rc *)
GMathView.add_configuration_path BuildTimeConf.gtkmathview_conf;