download auxiliary files via "curl";
authorwenzelm
Sat, 19 Dec 2020 00:08:14 +0100
changeset 72950 ac6457a70db5
parent 72949 854ebb9e4eb3
child 72951 74339f1a5dd7
download auxiliary files via "curl";
NEWS
src/Pure/PIDE/command.ML
--- a/NEWS	Sat Dec 19 00:04:32 2020 +0100
+++ b/NEWS	Sat Dec 19 00:08:14 2020 +0100
@@ -19,6 +19,9 @@
 * Improved markup for theory header imports: hyperlinks for theory files
 work without formal checking of content.
 
+* The prover process can download auxiliary files (e.g. 'ML_file') for
+theories with remote URL. This requires the external "curl" program.
+
 * Action "isabelle.goto-entity" (shortcut CS+d) jumps to the definition
 of the formal entity at the caret position.
 
--- a/src/Pure/PIDE/command.ML	Sat Dec 19 00:04:32 2020 +0100
+++ b/src/Pure/PIDE/command.ML	Sat Dec 19 00:08:14 2020 +0100
@@ -60,19 +60,29 @@
     val _ =
       if Context_Position.pide_reports ()
       then Position.report pos (Markup.language_path delimited) else ();
-    val _ =
+
+    fun read_file () =
+      let
+        val path = File.check_file (File.full_path master_dir src_path);
+        val text = File.read path;
+        val file_pos = Path.position path;
+      in (text, file_pos) end;
+
+    fun read_url () =
+      let
+        val text = Isabelle_System.download file_node;
+        val file_pos = Position.file file_node;
+      in (text, file_pos) end;
+
+    val (text, file_pos) =
       (case try Url.explode file_node of
-        NONE => ()
-      | SOME (Url.File _) => ()
-      | _ =>
-          error ("Prover cannot load remote file " ^
-            Markup.markup (Markup.url file_node) (quote file_node)));
-    val full_path = File.check_file (File.full_path master_dir src_path);
-    val text = File.read full_path;
+        NONE => read_file ()
+      | SOME (Url.File _) => read_file ()
+      | _ => read_url ());
+
     val lines = split_lines text;
     val digest = SHA1.digest text;
-    val file_pos = Position.copy_id pos (Path.position full_path);
-  in {src_path = src_path, lines = lines, digest = digest, pos = file_pos} end
+  in {src_path = src_path, lines = lines, digest = digest, pos = Position.copy_id pos file_pos} end
   handle ERROR msg => error (msg ^ Position.here pos);
 
 val read_file = read_file_node "";