aboutsummaryrefslogtreecommitdiff
path: root/toplevel/coqloop.ml
diff options
context:
space:
mode:
authorJim Fehrle2019-07-06 19:25:39 -0700
committerJim Fehrle2019-10-29 11:25:01 -0700
commit5ec7eca640a6ee495eb2c0fb8d8a4076256ff96d (patch)
tree31fa1c193537525928905d9f22b93b91b4ed1a00 /toplevel/coqloop.ml
parentf508ddcd2cfff152b8d6291d96e4b87ef9fe2ff9 (diff)
Show diffs in "Show Proof."
Add experimental "Show Proof" command to the toplevel that shadows the current command in the parser (in coqtop and PG only). Apply existing code to highlight diffs in the output
Diffstat (limited to 'toplevel/coqloop.ml')
-rw-r--r--toplevel/coqloop.ml44
1 files changed, 44 insertions, 0 deletions
diff --git a/toplevel/coqloop.ml b/toplevel/coqloop.ml
index 1f319d2bfd..97f0e57d2e 100644
--- a/toplevel/coqloop.ml
+++ b/toplevel/coqloop.ml
@@ -418,6 +418,50 @@ let rec vernac_loop ~state =
Feedback.msg_notice (v 0 (goal ++ evars));
vernac_loop ~state
+ | Some VernacShowProofDiffs removed ->
+ (* extension of Vernacentries.show_proof *)
+ let to_pp pstate =
+ let p = Option.get pstate in
+ let sigma, env = Pfedit.get_proof_context p in
+ let pprf = Proof.partial_proof p in
+ Pp.prlist_with_sep Pp.fnl (Printer.pr_econstr_env env sigma) pprf
+ (* We print nothing if there are no goals left *)
+ in
+
+ if not (Proof_diffs.color_enabled ()) then
+ CErrors.user_err Pp.(str "Show Proof Diffs requires setting the \"-color\" command line argument to \"on\" or \"auto\".")
+ else begin
+ let out =
+ try
+ let n_pp = to_pp state.proof in
+ if true (*Proof_diffs.show_diffs ()*) then
+ let doc = state.doc in
+ let oproof = Stm.get_prev_proof ~doc (Stm.get_current_state ~doc) in
+ try
+ let o_pp = to_pp oproof in
+ let tokenize_string = Proof_diffs.tokenize_string in
+ let show_removed = Some removed in
+ Pp_diff.diff_pp_combined ~tokenize_string ?show_removed o_pp n_pp
+ with
+ | Pfedit.NoSuchGoal
+ | Option.IsNone -> n_pp
+ | Pp_diff.Diff_Failure msg -> begin
+ (* todo: print the unparsable string (if we know it) *)
+ Feedback.msg_warning Pp.(str ("Diff failure: " ^ msg) ++ cut()
+ ++ str "Showing results without diff highlighting" );
+ n_pp
+ end
+ else
+ n_pp
+ with
+ | Pfedit.NoSuchGoal
+ | Option.IsNone ->
+ CErrors.user_err (str "No goals to show.")
+ in
+ Feedback.msg_notice out;
+ end;
+ vernac_loop ~state
+
| None ->
top_stderr (fnl ()); exit 0