src/Pure/Thy/present.ML
changeset 59446 4427f04fca57
parent 59445 2c27c3d1fd3b
child 59448 149d2bc5ddb6
equal deleted inserted replaced
59445:2c27c3d1fd3b 59446:4427f04fca57
     7 signature PRESENT =
     7 signature PRESENT =
     8 sig
     8 sig
     9   val session_name: theory -> string
     9   val session_name: theory -> string
    10   val document_enabled: string -> bool
    10   val document_enabled: string -> bool
    11   val document_variants: string -> (string * string) list
    11   val document_variants: string -> (string * string) list
    12   val init: bool -> bool -> Path.T -> string -> bool -> string -> (string * string) list ->
    12   val init: bool -> bool -> Path.T -> string -> string -> (string * string) list ->
    13     (Path.T * Path.T) list -> Path.T -> string * string -> bool -> theory list -> unit
    13     (Path.T * Path.T) list -> Path.T -> string * string -> bool -> theory list -> unit
    14   val finish: unit -> unit
    14   val finish: unit -> unit
    15   val theory_output: string -> string -> unit
    15   val theory_output: string -> string -> unit
    16   val begin_theory: int -> (unit -> HTML.text) -> theory -> theory
    16   val begin_theory: int -> (unit -> HTML.text) -> theory -> theory
    17   val display_drafts: Path.T list -> int
    17   val display_drafts: Path.T list -> int
   158 (** global session state **)
   158 (** global session state **)
   159 
   159 
   160 (* session_info *)
   160 (* session_info *)
   161 
   161 
   162 type session_info =
   162 type session_info =
   163   {name: string, chapter: string, info_path: Path.T, info: bool,
   163   {name: string, chapter: string, info_path: Path.T, info: bool, doc_format: string,
   164     doc_format: string, doc_graph: bool, doc_output: Path.T option,
   164     doc_output: Path.T option, doc_files: (Path.T * Path.T) list, graph_file: Path.T,
   165     doc_files: (Path.T * Path.T) list, graph_file: Path.T, documents: (string * string) list,
   165     documents: (string * string) list, verbose: bool, readme: Path.T option};
   166     verbose: bool, readme: Path.T option};
       
   167 
   166 
   168 fun make_session_info
   167 fun make_session_info
   169   (name, chapter, info_path, info, doc_format, doc_graph, doc_output,
   168   (name, chapter, info_path, info, doc_format, doc_output, doc_files,
   170     doc_files, graph_file, documents, verbose, readme) =
   169     graph_file, documents, verbose, readme) =
   171   {name = name, chapter = chapter, info_path = info_path, info = info,
   170   {name = name, chapter = chapter, info_path = info_path, info = info, doc_format = doc_format,
   172     doc_format = doc_format, doc_graph = doc_graph, doc_output = doc_output,
   171     doc_output = doc_output, doc_files = doc_files, graph_file = graph_file,
   173     doc_files = doc_files, graph_file = graph_file, documents = documents,
   172     documents = documents, verbose = verbose, readme = readme}: session_info;
   174     verbose = verbose, readme = readme}: session_info;
       
   175 
   173 
   176 
   174 
   177 (* state *)
   175 (* state *)
   178 
   176 
   179 val session_info = Unsynchronized.ref (NONE: session_info option);
   177 val session_info = Unsynchronized.ref (NONE: session_info option);
   203   in variants end;
   201   in variants end;
   204 
   202 
   205 
   203 
   206 (* init session *)
   204 (* init session *)
   207 
   205 
   208 fun init build info info_path doc doc_graph document_output doc_variants doc_files graph_file
   206 fun init build info info_path doc document_output doc_variants doc_files graph_file
   209     (chapter, name) verbose thys =
   207     (chapter, name) verbose thys =
   210   if not build andalso not info andalso doc = "" then
   208   if not build andalso not info andalso doc = "" then
   211     (Synchronized.change browser_info (K empty_browser_info); session_info := NONE)
   209     (Synchronized.change browser_info (K empty_browser_info); session_info := NONE)
   212   else
   210   else
   213     let
   211     let
   227         (case readme of NONE => [] | SOME p => [(Url.File p, "README")]) @
   225         (case readme of NONE => [] | SOME p => [(Url.File p, "README")]) @
   228           map (fn (name, _) => (Url.File (Path.ext doc (Path.basic name)), name)) documents;
   226           map (fn (name, _) => (Url.File (Path.ext doc (Path.basic name)), name)) documents;
   229     in
   227     in
   230       session_info :=
   228       session_info :=
   231         SOME (make_session_info (name, chapter, info_path, info, doc,
   229         SOME (make_session_info (name, chapter, info_path, info, doc,
   232           doc_graph, doc_output, doc_files, graph_file, documents, verbose, readme));
   230           doc_output, doc_files, graph_file, documents, verbose, readme));
   233       Synchronized.change browser_info (K (init_browser_info (chapter, name) thys));
   231       Synchronized.change browser_info (K (init_browser_info (chapter, name) thys));
   234       add_html_index (0, HTML.begin_session_index name docs (Url.explode "medium.html"))
   232       add_html_index (0, HTML.begin_session_index name docs (Url.explode "medium.html"))
   235     end;
   233     end;
   236 
   234 
   237 
   235 
   262 
   260 
   263 fun write_tex_index tex_index path =
   261 fun write_tex_index tex_index path =
   264   write_tex (index_buffer tex_index |> Buffer.add Latex.tex_trailer) doc_indexN path;
   262   write_tex (index_buffer tex_index |> Buffer.add Latex.tex_trailer) doc_indexN path;
   265 
   263 
   266 fun finish () =
   264 fun finish () =
   267   with_session_info () (fn {name, chapter, info, info_path, doc_format, doc_graph,
   265   with_session_info () (fn {name, chapter, info, info_path, doc_format,
   268     doc_output, doc_files, graph_file, documents, verbose, readme, ...} =>
   266     doc_output, doc_files, graph_file, documents, verbose, readme, ...} =>
   269   let
   267   let
   270     val {theories, tex_index, html_index, graph} = Synchronized.value browser_info;
   268     val {theories, tex_index, html_index, graph} = Synchronized.value browser_info;
   271     val thys = Symtab.dest theories;
   269     val thys = Symtab.dest theories;
   272     val sorted_graph = Graph_Display.sort_graph graph;
   270     val sorted_graph = Graph_Display.sort_graph graph;