src/Pure/Tools/jedit.ML
author wenzelm
Thu, 04 Apr 2019 15:26:18 +0200
changeset 70053 997f256c98e3
parent 69592 a80d8ec6c998
child 71513 a403942212f2
permissions -rw-r--r--
proper .exe path for export;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
61617
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Tools/jedit.ML
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
     3
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
     4
jEdit support.
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
     5
*)
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
     6
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
     7
signature JEDIT =
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
     8
sig
61620
01db1bed4487 tuned signature;
wenzelm
parents: 61617
diff changeset
     9
  val check_action: string * Position.T -> string
61617
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    10
end;
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    11
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    12
structure JEdit: JEDIT =
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    13
struct
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    14
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    15
(* jEdit actions *)
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    16
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    17
local
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    18
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    19
fun parse_named a (XML.Elem ((b, props), _)) =
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    20
      (case Properties.get props "NAME" of
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    21
        SOME name => if a = b then [name] else []
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    22
      | NONE => [])
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    23
  | parse_named _ _ = [];
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    24
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    25
val isabelle_jedit_actions =
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    26
  Lazy.lazy (fn () =>
63680
6e1e8b5abbfa more symbols;
wenzelm
parents: 63669
diff changeset
    27
    (case XML.parse (File.read \<^file>\<open>~~/src/Tools/jEdit/src/actions.xml\<close>) of
61617
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    28
      XML.Elem (("ACTIONS", _), body) => maps (parse_named "ACTION") body
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    29
    | _ => []));
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    30
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    31
val isabelle_jedit_dockables =
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    32
  Lazy.lazy (fn () =>
63680
6e1e8b5abbfa more symbols;
wenzelm
parents: 63669
diff changeset
    33
    (case XML.parse (File.read \<^file>\<open>~~/src/Tools/jEdit/src/dockables.xml\<close>) of
61617
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    34
      XML.Elem (("DOCKABLES", _), body) => maps (parse_named "DOCKABLE") body
66670
e5188cb1c3d8 more derived actions, according to jEdit/org/gjt/sp/jedit/gui/DockableWindowFactory.java;
wenzelm
parents: 63681
diff changeset
    35
    | _ => [])
e5188cb1c3d8 more derived actions, according to jEdit/org/gjt/sp/jedit/gui/DockableWindowFactory.java;
wenzelm
parents: 63681
diff changeset
    36
    |> maps (fn a => [a, a ^ "-toggle", a ^ "-float"]));
61617
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    37
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    38
val jedit_actions =
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    39
  Lazy.lazy (fn () =>
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    40
    (case Isabelle_System.bash_output
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    41
      "unzip -p \"$JEDIT_HOME/dist/jedit.jar\" org/gjt/sp/jedit/actions.xml" of
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    42
      (txt, 0) =>
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    43
        (case XML.parse txt of
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    44
          XML.Elem (("ACTIONS", _), body) => maps (parse_named "ACTION") body
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    45
        | _ => [])
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    46
    | (_, rc) => error ("Cannot unzip jedit.jar\nreturn code = " ^ string_of_int rc)));
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    47
61621
70b8085f51b4 more thorough check_action, including completion;
wenzelm
parents: 61620
diff changeset
    48
val all_actions =
70b8085f51b4 more thorough check_action, including completion;
wenzelm
parents: 61620
diff changeset
    49
  Lazy.lazy (fn () =>
70b8085f51b4 more thorough check_action, including completion;
wenzelm
parents: 61620
diff changeset
    50
    Lazy.force isabelle_jedit_actions @
70b8085f51b4 more thorough check_action, including completion;
wenzelm
parents: 61620
diff changeset
    51
    Lazy.force isabelle_jedit_dockables @
70b8085f51b4 more thorough check_action, including completion;
wenzelm
parents: 61620
diff changeset
    52
    Lazy.force jedit_actions);
61617
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    53
61620
01db1bed4487 tuned signature;
wenzelm
parents: 61617
diff changeset
    54
in
01db1bed4487 tuned signature;
wenzelm
parents: 61617
diff changeset
    55
61621
70b8085f51b4 more thorough check_action, including completion;
wenzelm
parents: 61620
diff changeset
    56
fun check_action (name, pos) =
63681
d2448471ffba active jEdit actions;
wenzelm
parents: 63680
diff changeset
    57
  if member (op =) (Lazy.force all_actions) name then
d2448471ffba active jEdit actions;
wenzelm
parents: 63680
diff changeset
    58
    let
d2448471ffba active jEdit actions;
wenzelm
parents: 63680
diff changeset
    59
      val ((bg1, bg2), en) =
d2448471ffba active jEdit actions;
wenzelm
parents: 63680
diff changeset
    60
        YXML.output_markup_elem
d2448471ffba active jEdit actions;
wenzelm
parents: 63680
diff changeset
    61
          (Active.make_markup Markup.jedit_actionN {implicit = false, properties = []});
d2448471ffba active jEdit actions;
wenzelm
parents: 63680
diff changeset
    62
      val msg = "Invoke " ^ bg1 ^ name ^ bg2 ^ name ^ en ^ " jEdit action";
d2448471ffba active jEdit actions;
wenzelm
parents: 63680
diff changeset
    63
    in writeln (msg ^ Position.here pos); name end
61621
70b8085f51b4 more thorough check_action, including completion;
wenzelm
parents: 61620
diff changeset
    64
  else
70b8085f51b4 more thorough check_action, including completion;
wenzelm
parents: 61620
diff changeset
    65
    let
69289
bf6937af7fe8 clarified signature;
wenzelm
parents: 67463
diff changeset
    66
      val completion_report =
bf6937af7fe8 clarified signature;
wenzelm
parents: 67463
diff changeset
    67
        Completion.make_report (name, pos)
61621
70b8085f51b4 more thorough check_action, including completion;
wenzelm
parents: 61620
diff changeset
    68
          (fn completed =>
70b8085f51b4 more thorough check_action, including completion;
wenzelm
parents: 61620
diff changeset
    69
            Lazy.force all_actions
70b8085f51b4 more thorough check_action, including completion;
wenzelm
parents: 61620
diff changeset
    70
            |> filter completed
70b8085f51b4 more thorough check_action, including completion;
wenzelm
parents: 61620
diff changeset
    71
            |> sort_strings
70b8085f51b4 more thorough check_action, including completion;
wenzelm
parents: 61620
diff changeset
    72
            |> map (fn a => (a, ("action", a))));
69289
bf6937af7fe8 clarified signature;
wenzelm
parents: 67463
diff changeset
    73
    in error ("Bad jEdit action " ^ quote name ^ Position.here pos ^ completion_report) end
61620
01db1bed4487 tuned signature;
wenzelm
parents: 61617
diff changeset
    74
63681
d2448471ffba active jEdit actions;
wenzelm
parents: 63680
diff changeset
    75
val _ =
d2448471ffba active jEdit actions;
wenzelm
parents: 63680
diff changeset
    76
  Theory.setup
69592
a80d8ec6c998 support for isabelle update -u control_cartouches;
wenzelm
parents: 69349
diff changeset
    77
    (Thy_Output.antiquotation_verbatim_embedded \<^binding>\<open>action\<close> (Scan.lift Args.embedded_position)
67463
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
    78
      (fn ctxt => fn (name, pos) =>
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
    79
        let
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
    80
          val _ =
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
    81
            if Context_Position.is_reported ctxt pos
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
    82
            then ignore (check_action (name, pos))
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
    83
            else ();
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
    84
        in name end));
63681
d2448471ffba active jEdit actions;
wenzelm
parents: 63680
diff changeset
    85
61617
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    86
end;
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    87
cd7549cd5fe7 clarified modules;
wenzelm
parents:
diff changeset
    88
end;