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