1 (* Copyright (C) 2004-2005, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://helm.cs.unibo.it/
29 module TA = GrafiteAst
32 let debug_print = if debug then prerr_endline else ignore
34 (** raised when one of the script margins (top or bottom) is reached *)
37 let safe_substring s i j =
38 try String.sub s i j with Invalid_argument _ -> assert false
40 let heading_nl_RE = Pcre.regexp "^\\s*\n\\s*"
41 let heading_nl_RE' = Pcre.regexp "^(\\s*\n\\s*)((.|\n)*)"
42 let only_dust_RE = Pcre.regexp "^(\\s|\n|%%[^\n]*\n)*$"
43 let multiline_RE = Pcre.regexp "^\n[^\n]+$"
44 let newline_RE = Pcre.regexp "\n"
47 if Pcre.pmatch ~rex:multiline_RE str then
48 "\n(** " ^ (Pcre.replace ~rex:newline_RE str) ^ " *)"
50 "\n(**\n" ^ str ^ "\n*)"
53 let s = Pcre.replace ~rex:heading_nl_RE s in
55 let nl_pos = String.index s '\n' in
59 (** creates a statement AST for the Goal tactic, e.g. "goal 7" *)
61 let module A = GrafiteAst in
62 let loc = DisambiguateTypes.dummy_floc in
63 A.Executable (loc, A.Tactical (loc,
64 A.Tactic (loc, A.Goal (loc, n)),
68 mathviewer:MatitaTypes.mathViewer;
69 urichooser: UriManager.uri list -> UriManager.uri list;
70 ask_confirmation: title:string -> message:string -> [`YES | `NO | `CANCEL];
71 develcreator: containing:string option -> unit;
72 mutable filenamedata: string option * MatitamakeLib.development option
75 let eval_with_engine guistuff status user_goal parsed_text st =
76 let module TAPp = GrafiteAstPp in
78 match guistuff.filenamedata with
80 | None,Some devel -> [MatitamakeLib.root_for_development devel ]
82 match MatitamakeLib.development_for_dir (Filename.dirname f) with
84 | Some devel -> [MatitamakeLib.root_for_development devel ]
86 let parsed_text_length = String.length parsed_text in
88 match st with TA.Executable (loc,ex) -> loc, ex | _ -> assert false in
89 let initial_space,parsed_text =
91 let pieces = Pcre.extract ~rex:heading_nl_RE' parsed_text in
92 pieces.(1), pieces.(2)
94 Not_found -> "", parsed_text in
95 (* we add the goal command if needed *)
96 let inital_space,new_status,new_status_and_text_list' =
97 match status.proof_status with
98 (* | Incomplete_proof { stack = stack }
99 when not (List.mem user_goal (Continuationals.head_goals stack)) ->
101 MatitaEngine.eval_ast ~include_paths:include_
102 ~do_heavy_checks:true status (goal_ast user_goal)
104 let initial_space = if initial_space = "" then "\n" else initial_space
108 initial_space ^ TAPp.pp_tactical (TA.Select (loc, [user_goal])) ] *)
109 | _ -> initial_space,status,[] in
111 GrafiteEngine.eval_ast
112 ~disambiguate_tactic:GrafiteDisambiguate.disambiguate_tactic
113 ~disambiguate_command:GrafiteDisambiguate.disambiguate_command
114 ~include_paths:include_ ~do_heavy_checks:true new_status st
118 | TA.Command (_, TA.Alias _)
119 | TA.Command (_, TA.Include _)
120 | TA.Command (_, TA.Interpretation _) -> []
121 | _ -> MatitaSync.alias_diff ~from:status new_status
123 (* we remove the defined object since we consider them "automatic aliases" *)
125 TA.Comment (DisambiguateTypes.dummy_floc,
126 TA.Note (DisambiguateTypes.dummy_floc, ""))
128 let initial_space,status,new_status_and_text_list_rev =
129 let module DTE = DisambiguateTypes.Environment in
130 let module UM = UriManager in
131 let baseuri = GrafiteTypes.get_string_option new_status "baseuri" in
133 fun (initial_space,status,acc) (k,((v,_) as value)) ->
136 UM.buri_of_uri (UM.uri_of_string v) = baseuri
138 UriManager.IllFormedUri _ -> false (* v is a description, not a URI *)
141 initial_space,status,acc
145 if initial_space = "" then "\n" else initial_space in
147 DisambiguatePp.pp_environment
148 (DisambiguateTypes.Environment.add k value
149 DisambiguateTypes.Environment.empty) in
151 MatitaSync.set_proof_aliases status [k,value]
153 "\n",new_status,((new_status, (new_text, dummy_st))::acc)
154 ) (initial_space,status,[]) new_aliases in
155 let parsed_text = initial_space ^ parsed_text in
157 List.rev new_status_and_text_list_rev @ new_status_and_text_list' @
158 [new_status, (parsed_text, st)]
160 res,parsed_text_length
162 let eval_with_engine guistuff status user_goal parsed_text st =
164 eval_with_engine guistuff status user_goal parsed_text st
166 | GrafiteEngine.UnableToInclude what
167 | GrafiteEngine.IncludedFileNotCompiled what as exc ->
168 let compile_needed_and_go_on d =
171 while Glib.Main.pending () do ignore(Glib.Main.iteration false); done
173 if not(MatitamakeLib.build_development_in_bg ~target refresh_cb d) then
176 eval_with_engine guistuff status user_goal parsed_text st
178 let do_nothing () = [], 0 in
179 let handle_with_devel d =
180 let name = MatitamakeLib.name_for_development d in
181 let title = "Unable to include " ^ what in
183 what ^ " is handled by development <b>" ^ name ^ "</b>.\n\n" ^
184 "<i>Should I compile it and Its dependencies?</i>"
186 (match guistuff.ask_confirmation ~title ~message with
187 | `YES -> compile_needed_and_go_on d
189 | `CANCEL -> do_nothing ())
191 let handle_without_devel filename =
192 let title = "Unable to include " ^ what in
194 what ^ " is <b>not</b> handled by a development.\n" ^
195 "All dependencies are automatically solved for a development.\n\n" ^
196 "<i>Do you want to set up a development?</i>"
198 (match guistuff.ask_confirmation ~title ~message with
202 guistuff.develcreator ~containing:(Some (Filename.dirname f))
203 | None -> guistuff.develcreator ~containing:None);
206 | `CANCEL -> do_nothing())
208 match guistuff.filenamedata with
209 | None,None -> handle_without_devel None
210 | None,Some d -> handle_with_devel d
212 match MatitamakeLib.development_for_dir (Filename.dirname f) with
213 | None -> handle_without_devel (Some f)
214 | Some d -> handle_with_devel d
217 let disambiguate_macro_term term status user_goal =
218 let module MD = MatitaDisambiguator in
219 let dbd = LibraryDb.instance () in
220 let metasenv = GrafiteTypes.get_proof_metasenv status in
221 let context = GrafiteTypes.get_proof_context status user_goal in
223 MD.disambiguate_term ~dbd ~context ~metasenv ~aliases:status.aliases
224 ~universe:(Some status.multi_aliases) term in
229 let eval_macro guistuff status user_goal unparsed_text parsed_text script mac =
230 let module TAPp = GrafiteAstPp in
231 let module MQ = MetadataQuery in
232 let module MDB = LibraryDb in
233 let module CTC = CicTypeChecker in
234 let module CU = CicUniv in
235 (* no idea why ocaml wants this *)
236 let parsed_text_length = String.length parsed_text in
237 let dbd = LibraryDb.instance () in
240 | TA.WMatch (loc, term) ->
241 let term = disambiguate_macro_term term status user_goal in
242 let l = Whelp.match_term ~dbd term in
244 MatitaMisc.strip_suffix ~suffix:"."
245 (HExtlib.trim_blanks unparsed_text)
247 let entry = `Whelp (query_url, l) in
248 guistuff.mathviewer#show_uri_list ~reuse:true ~entry l;
249 [], parsed_text_length
250 | TA.WInstance (loc, term) ->
251 let term = disambiguate_macro_term term status user_goal in
252 let l = Whelp.instance ~dbd term in
253 let entry = `Whelp (TAPp.pp_macro_cic (TA.WInstance (loc, term)), l) in
254 guistuff.mathviewer#show_uri_list ~reuse:true ~entry l;
255 [], parsed_text_length
256 | TA.WLocate (loc, s) ->
257 let l = Whelp.locate ~dbd s in
258 let entry = `Whelp (TAPp.pp_macro_cic (TA.WLocate (loc, s)), l) in
259 guistuff.mathviewer#show_uri_list ~reuse:true ~entry l;
260 [], parsed_text_length
261 | TA.WElim (loc, term) ->
262 let term = disambiguate_macro_term term status user_goal in
265 | Cic.MutInd (uri,n,_) -> UriManager.uri_of_uriref uri n None
266 | _ -> failwith "Not a MutInd"
268 let l = Whelp.elim ~dbd uri in
269 let entry = `Whelp (TAPp.pp_macro_cic (TA.WElim (loc, term)), l) in
270 guistuff.mathviewer#show_uri_list ~reuse:true ~entry l;
271 [], parsed_text_length
272 | TA.WHint (loc, term) ->
273 let term = disambiguate_macro_term term status user_goal in
274 let s = ((None,[0,[],term], Cic.Meta (0,[]) ,term),0) in
275 let l = List.map fst (MQ.experimental_hint ~dbd s) in
276 let entry = `Whelp (TAPp.pp_macro_cic (TA.WHint (loc, term)), l) in
277 guistuff.mathviewer#show_uri_list ~reuse:true ~entry l;
278 [], parsed_text_length
281 let proof = GrafiteTypes.get_current_proof status in
282 let proof_status = proof, user_goal in
283 let l = List.map fst (MQ.experimental_hint ~dbd proof_status) in
284 let selected = guistuff.urichooser l in
286 | [] -> [], parsed_text_length
288 let suri = UriManager.string_of_uri uri in
290 TA.Executable (loc, (TA.Tactical (loc,
292 TA.Apply (loc, CicNotationPt.Uri (suri, None))),
296 GrafiteEngine.eval_ast
297 ~disambiguate_tactic:GrafiteDisambiguate.disambiguate_tactic
298 ~disambiguate_command:GrafiteDisambiguate.disambiguate_command
301 comment parsed_text ^
302 "\n" ^ TAPp.pp_statement ast
304 [ new_status , (extra_text, ast) ], parsed_text_length
307 "The result of the urichooser should be only 1 uri, not:\n";
309 fun u -> HLog.error (UriManager.string_of_uri u ^ "\n")
312 | TA.Check (_,term) ->
313 let metasenv = GrafiteTypes.get_proof_metasenv status in
314 let context = GrafiteTypes.get_proof_context status user_goal in
316 MatitaDisambiguator.disambiguate_term ~dbd ~context ~metasenv
317 ~aliases:status.aliases ~universe:(Some status.multi_aliases) term
319 let _, metasenv , term, ugraph =
324 let ty,_ = CTC.type_of_aux' metasenv context term ugraph in
325 let t_and_ty = Cic.Cast (term,ty) in
326 guistuff.mathviewer#show_entry (`Cic (t_and_ty,metasenv));
327 [], parsed_text_length
330 let status = script#status.proof_status in
333 | _ -> script#retract ();go_back()
335 [], parsed_text_length, Some go_back
336 | TA.Redo (_, Some i) -> [], parsed_text_length,
337 Some (fun () -> for j = 1 to i do advance () done)
338 | TA.Redo (_, None) -> [], parsed_text_length,
339 Some (fun () -> advance ())
340 | TA.Undo (_, Some i) -> [], parsed_text_length,
341 Some (fun () -> for j = 1 to i do script#retract () done)
342 | TA.Undo (_, None) -> [], parsed_text_length,
343 Some (fun () -> script#retract ()) *)
345 | TA.Quit _ -> failwith "not implemented"
346 | TA.Print (_,kind) -> failwith "not implemented"
347 | TA.Search_pat (_, search_kind, str) -> failwith "not implemented"
348 | TA.Search_term (_, search_kind, term) -> failwith "not implemented"
350 let eval_executable guistuff status user_goal unparsed_text parsed_text script
353 let module TAPp = GrafiteAstPp in
354 let module MD = MatitaDisambiguator in
355 let module ML = MatitaMisc in
357 | TA.Command (loc, _) | TA.Tactical (loc, _, _) ->
359 (match GrafiteMisc.baseuri_of_baseuri_decl (TA.Executable (loc,ex)) with
362 if not (GrafiteMisc.is_empty u) then
364 guistuff.ask_confirmation
365 ~title:"Baseuri redefinition"
367 "Baseuri " ^ u ^ " already exists.\n" ^
368 "Do you want to redefine the corresponding "^
369 "part of the library?")
372 let basedir = Helm_registry.get "matita.basedir" in
373 LibraryClean.clean_baseuris ~basedir [u]
375 | `CANCEL -> raise MatitaTypes.Cancel);
377 guistuff status user_goal parsed_text (TA.Executable (loc, ex))
378 with MatitaTypes.Cancel -> [], 0)
379 | TA.Macro (_,mac) ->
380 eval_macro guistuff status user_goal unparsed_text parsed_text script mac
382 let rec eval_statement (buffer : GText.buffer) guistuff status user_goal
385 let st, unparsed_text =
388 if Pcre.pmatch ~rex:only_dust_RE text then raise Margin;
389 GrafiteParser.parse_statement (Ulexing.from_utf8_string text), text
390 | `Ast (st, text) -> st, text
392 let text_of_loc loc =
393 let parsed_text_length = snd (HExtlib.loc_of_floc loc) in
394 let parsed_text = safe_substring unparsed_text 0 parsed_text_length in
395 parsed_text, parsed_text_length
398 | GrafiteAst.Comment (loc, _) ->
399 let parsed_text, parsed_text_length = text_of_loc loc in
400 let remain_len = String.length unparsed_text - parsed_text_length in
401 let s = String.sub unparsed_text parsed_text_length remain_len in
404 eval_statement buffer guistuff status user_goal script
407 HExtlib.Localized (floc, exn) ->
408 HExtlib.raise_localized_exception ~offset:parsed_text_length floc exn
409 | MatitaDisambiguator.DisambiguationError (offset,errorll) ->
411 (MatitaDisambiguator.DisambiguationError
412 (offset+parsed_text_length, errorll))
415 | (status, (text, ast)) :: tl ->
416 ((status, (parsed_text ^ text, ast))::tl), (parsed_text_length + len)
418 | GrafiteAst.Executable (loc, ex) ->
419 let parsed_text, parsed_text_length = text_of_loc loc in
420 eval_executable guistuff status user_goal unparsed_text parsed_text
423 let fresh_script_id =
427 class script ~(source_view: GSourceView.source_view)
428 ~(init: GrafiteTypes.status)
429 ~(mathviewer: MatitaTypes.mathViewer)
435 let buffer = source_view#buffer in
436 let source_buffer = source_view#source_buffer in
438 val scriptId = fresh_script_id ()
441 mathviewer = mathviewer;
442 urichooser = urichooser;
443 ask_confirmation = ask_confirmation;
444 develcreator = develcreator;
445 filenamedata = (None, None)}
447 method private getFilename =
448 match guistuff.filenamedata with Some f,_ -> f | _ -> assert false
450 method filename = self#getFilename
452 method private ppFilename =
453 match guistuff.filenamedata with
455 | None,_ -> sprintf ".unnamed%d.ma" scriptId
458 ignore (GMain.Timeout.add ~ms:300000
459 ~callback:(fun _ -> self#_saveToBackupFile ();true));
460 ignore (buffer#connect#modified_changed
461 (fun _ -> set_star (Filename.basename self#ppFilename) buffer#modified))
463 val mutable statements = []; (** executed statements *)
464 val mutable history = [ init ];
465 (** list of states before having executed statements. Head element of this
466 * list is the current state, last element is the state at the beginning of
468 * Invariant: this list length is 1 + length of statements *)
470 (** goal as seen by the user (i.e. metano corresponding to current tab) *)
471 val mutable userGoal = ~-1
473 (** text mark and tag representing locked part of a script *)
475 buffer#create_mark ~name:"locked" ~left_gravity:true buffer#start_iter
476 val locked_tag = buffer#create_tag [`BACKGROUND "lightblue"; `EDITABLE false]
477 val error_tag = buffer#create_tag [`UNDERLINE `SINGLE; `FOREGROUND "red"]
479 method locked_mark = locked_mark
480 method locked_tag = locked_tag
481 method error_tag = error_tag
483 (* history can't be empty, the invariant above grant that it contains at
484 * least the init status *)
485 method status = match history with hd :: _ -> hd | _ -> assert false
487 method private _advance ?statement () =
489 let (entries, parsed_len) =
490 eval_statement buffer guistuff self#status userGoal self st
492 let (new_statuses, new_statements, new_asts) =
493 let statuses, statements = List.split entries in
494 let texts, asts = List.split statements in
495 statuses, texts, asts
497 history <- List.rev new_statuses @ history;
498 statements <- List.rev new_statements @ statements;
499 let start = buffer#get_iter_at_mark (`MARK locked_mark) in
500 let new_text = String.concat "" new_statements in
501 if statement <> None then
502 buffer#insert ~iter:start new_text
504 let s = match st with `Raw s | `Ast (_, s) -> s in
505 if new_text <> String.sub s 0 parsed_len then
507 let stop = start#copy#forward_chars parsed_len in
508 buffer#delete ~start ~stop;
509 buffer#insert ~iter:start new_text;
511 self#moveMark (String.length new_text);
513 (match List.rev new_asts with (* advance again on punctuation *)
514 | TA.Executable (_, TA.Tactical (_, tac, _)) :: _ ->
516 (buffer#get_iter_at_mark (`MARK locked_mark))#offset
518 let text = self#getFuture in
520 (match parse_statement baseoffset 0 buffer text with
521 | TA.Executable (loc, TA.Tactical (_, tac, None)) as st
522 when GrafiteAst.is_punctuation tac ->
523 let len = snd (CicNotationPt.loc_of_floc loc) in
524 aux (`Ast (st, String.sub text 0 len))
526 with CicNotationParser.Parse_error _ | End_of_file -> ())
530 let s = match statement with Some s -> s | None -> self#getFuture in
531 HLog.debug ("evaluating: " ^ first_line s ^ " ...");
532 (try aux (`Raw s) with End_of_file -> raise Margin)
534 method private _retract offset status new_statements new_history =
535 let cur_status = match history with s::_ -> s | [] -> assert false in
536 MatitaSync.time_travel ~present:cur_status ~past:status;
537 statements <- new_statements;
538 history <- new_history;
539 self#moveMark (- offset)
541 method advance ?statement () =
543 self#_advance ?statement ();
546 | Margin -> self#notify
547 | exc -> self#notify; raise exc
551 let cmp,new_statements,new_history,status =
552 match statements,history with
553 stat::statements, _::(status::_ as history) ->
554 String.length stat, statements, history, status
555 | [],[_] -> raise Margin
556 | _,_ -> assert false
558 self#_retract cmp status new_statements new_history;
561 | Margin -> self#notify
562 | exc -> self#notify; raise exc
564 method private getFuture =
565 buffer#get_text ~start:(buffer#get_iter_at_mark (`MARK locked_mark))
566 ~stop:buffer#end_iter ()
569 (** @param rel_offset relative offset from current position of locked_mark *)
570 method private moveMark rel_offset =
571 let mark = `MARK locked_mark in
572 let old_insert = buffer#get_iter_at_mark `INSERT in
573 buffer#remove_tag locked_tag ~start:buffer#start_iter ~stop:buffer#end_iter;
574 let current_mark_pos = buffer#get_iter_at_mark mark in
576 match rel_offset with
577 | 0 -> current_mark_pos
578 | n when n > 0 -> current_mark_pos#forward_chars n
579 | n (* when n < 0 *) -> current_mark_pos#backward_chars (abs n)
581 buffer#move_mark mark ~where:new_mark_pos;
582 buffer#apply_tag locked_tag ~start:buffer#start_iter ~stop:new_mark_pos;
583 buffer#move_mark `INSERT old_insert;
584 let mark_position = buffer#get_iter_at_mark mark in
585 if source_view#move_mark_onscreen mark then
587 buffer#move_mark mark mark_position;
588 source_view#scroll_to_mark ~use_align:true ~xalign:1.0 ~yalign:0.1 mark;
590 while Glib.Main.pending () do ignore(Glib.Main.iteration false); done
592 method clean_dirty_lock =
593 let lock_mark_iter = buffer#get_iter_at_mark (`MARK locked_mark) in
594 buffer#remove_tag locked_tag ~start:buffer#start_iter ~stop:buffer#end_iter;
595 buffer#apply_tag locked_tag ~start:buffer#start_iter ~stop:lock_mark_iter
597 val mutable observers = []
599 method addObserver (o: GrafiteTypes.status -> unit) =
600 observers <- o :: observers
602 method private notify =
603 let status = self#status in
604 List.iter (fun o -> o status) observers
606 method loadFromFile f =
607 buffer#set_text (HExtlib.input_file f);
609 buffer#set_modified false
611 method assignFileName file =
612 let abspath = MatitaMisc.absolute_path file in
613 let devel = MatitamakeLib.development_for_dir (Filename.dirname abspath) in
614 guistuff.filenamedata <- Some abspath, devel
616 method saveToFile () =
617 let oc = open_out self#getFilename in
618 output_string oc (buffer#get_text ~start:buffer#start_iter
619 ~stop:buffer#end_iter ());
621 buffer#set_modified false
623 method private _saveToBackupFile () =
624 if buffer#modified then
626 let f = self#ppFilename ^ "~" in
627 let oc = open_out f in
628 output_string oc (buffer#get_text ~start:buffer#start_iter
629 ~stop:buffer#end_iter ());
631 HLog.debug ("backup " ^ f ^ " saved")
634 method private goto_top =
635 MatitaSync.time_travel ~present:self#status ~past:init
637 method private reset_buffer =
642 buffer#remove_tag locked_tag ~start:buffer#start_iter ~stop:buffer#end_iter;
643 buffer#move_mark (`MARK locked_mark) ~where:buffer#start_iter
647 source_buffer#begin_not_undoable_action ();
648 buffer#delete ~start:buffer#start_iter ~stop:buffer#end_iter;
649 source_buffer#end_not_undoable_action ();
650 buffer#set_modified false
653 let template = HExtlib.input_file BuildTimeConf.script_template in
654 buffer#insert ~iter:(buffer#get_iter `START) template;
655 guistuff.filenamedata <-
656 (None,MatitamakeLib.development_for_dir (Unix.getcwd ()));
657 buffer#set_modified false;
658 set_star (Filename.basename self#ppFilename) false
660 method goto (pos: [`Top | `Bottom | `Cursor]) () =
661 let old_locked_mark =
663 (buffer#create_mark ~name:"old_locked_mark"
664 ~left_gravity:true (buffer#get_iter_at_mark (`MARK locked_mark))) in
665 let getpos _ = buffer#get_iter_at_mark (`MARK locked_mark) in
666 let getoldpos _ = buffer#get_iter_at_mark old_locked_mark in
667 let dispose_old_locked_mark () = buffer#delete_mark old_locked_mark in
670 dispose_old_locked_mark ();
678 let newpos = getpos () in
679 if (getoldpos ())#compare newpos < 0 then
681 buffer#move_mark old_locked_mark newpos;
686 dispose_old_locked_mark ();
689 | Margin -> dispose_old_locked_mark (); self#notify
690 | exc -> dispose_old_locked_mark (); self#notify; raise exc)
692 let locked_iter () = buffer#get_iter_at_mark (`NAME "locked") in
693 let cursor_iter () = buffer#get_iter_at_mark `INSERT in
696 (buffer#create_mark ~name:"initial_insert"
697 ~left_gravity:true (cursor_iter ())) in
698 let dispose_remember () = buffer#delete_mark remember in
699 let remember_iter () =
700 buffer#get_iter_at_mark (`NAME "initial_insert") in
701 let cmp () = (locked_iter ())#offset - (remember_iter ())#offset in
703 let forward_until_cursor () = (* go forward until locked > cursor *)
706 if cmp () < 0 && (getoldpos ())#compare (getpos ()) < 0
709 buffer#move_mark old_locked_mark (getpos ());
715 let rec back_until_cursor len = (* go backward until locked < cursor *)
717 statements, (status::_ as history) when len <= 0 ->
718 self#_retract (icmp - len) status statements history
719 | statement::tl1, _::tl2 ->
720 back_until_cursor (len - String.length statement) (tl1,tl2)
721 | _,_ -> assert false
725 if icmp < 0 then (* locked < cursor *)
726 (forward_until_cursor (); self#notify)
727 else if icmp > 0 then (* locked > cursor *)
728 (back_until_cursor icmp (statements,history); self#notify)
729 else (* cursor = locked *)
733 dispose_old_locked_mark ();
735 | Margin -> dispose_remember (); dispose_old_locked_mark (); self#notify
736 | exc -> dispose_remember (); dispose_old_locked_mark ();
737 self#notify; raise exc)
739 method onGoingProof () =
740 match self#status.proof_status with
741 | No_proof | Proof _ -> false
742 | Incomplete_proof _ -> true
743 | Intermediate _ -> assert false
745 (* method proofStatus = MatitaTypes.get_proof_status self#status *)
746 method proofMetasenv = GrafiteTypes.get_proof_metasenv self#status
747 method proofContext = GrafiteTypes.get_proof_context self#status userGoal
748 method proofConclusion= GrafiteTypes.get_proof_conclusion self#status userGoal
749 method stack = GrafiteTypes.get_stack self#status
750 method setGoal n = userGoal <- n
751 method goal = userGoal
754 let s = self#getFuture in
755 let rec is_there_and_executable s =
756 if Pcre.pmatch ~rex:only_dust_RE s then raise Margin;
757 let st = GrafiteParser.parse_statement (Ulexing.from_utf8_string s) in
759 | GrafiteAst.Comment (loc,_)->
760 let parsed_text_length = snd (HExtlib.loc_of_floc loc) in
761 let remain_len = String.length s - parsed_text_length in
762 let next = String.sub s parsed_text_length remain_len in
763 is_there_and_executable next
764 | GrafiteAst.Executable (loc, ex) -> false
767 is_there_and_executable s
769 | CicNotationParser.Parse_error _ -> false
770 | Margin | End_of_file -> true
774 HLog.debug "script status:";
775 HLog.debug ("history size: " ^ string_of_int (List.length history));
776 HLog.debug (sprintf "%d statements:" (List.length statements));
777 List.iter HLog.debug statements;
778 HLog.debug ("Current file name: " ^
779 (match guistuff.filenamedata with
780 |None,_ -> "[ no name ]"
785 let _script = ref None
787 let script ~source_view ~init ~mathviewer ~urichooser ~develcreator ~ask_confirmation ~set_star ()
790 ~source_view ~init ~mathviewer ~ask_confirmation ~urichooser ~develcreator ~set_star ()
795 let current () = match !_script with None -> assert false | Some s -> s