| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
let lang_manager = GSourceView3.source_language_manager ~default:true |
| 12 |
let () = lang_manager#set_search_path |
| 13 |
((Minilib.rocqide_data_dirs ())@lang_manager#search_path) |
| 14 |
let style_manager = GSourceView3.source_style_scheme_manager ~default:true |
| 15 |
let () = style_manager#set_search_path |
| 16 |
((Minilib.rocqide_data_dirs ())@style_manager#search_path) |
| 17 |
|
| 18 |
type tag = { |
| 19 |
tag_fg_color : string option; |
| 20 |
tag_bg_color : string option; |
| 21 |
tag_bold : bool; |
| 22 |
tag_italic : bool; |
| 23 |
tag_underline : bool; |
| 24 |
tag_strikethrough : bool; |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
type obj = { |
| 31 |
set : string list -> unit; |
| 32 |
get : unit -> string list; |
| 33 |
} |
| 34 |
|
| 35 |
let preferences : obj Util.String.Map.t ref = ref Util.String.Map.empty |
| 36 |
let unknown_preferences : string list Util.String.Map.t ref = ref Util.String.Map.empty |
| 37 |
|
| 38 |
class virtual ['a] repr = |
| 39 |
object(self) |
| 40 |
method raw_into v = Option.get (self#into [v]) |
| 41 |
method raw_from s = List.hd (self#from s) |
| 42 |
method virtual into : string list -> 'a option |
| 43 |
method virtual from : 'a -> string list |
| 44 |
end |
| 45 |
|
| 46 |
class ['a] preference_signals ~(changed : 'a GUtil.signal) = |
| 47 |
object |
| 48 |
inherit GUtil.ml_signals [changed#disconnect] |
| 49 |
method changed = changed#connect ~after |
| 50 |
end |
| 51 |
|
| 52 |
class ['a] preference ~(name : string list) ~(init : 'a) ~(repr : 'a repr) = |
| 53 |
object (self) |
| 54 |
initializer |
| 55 |
let set v = match repr#into v with None -> () | Some s -> self#set s in |
| 56 |
let get () = repr#from self#get in |
| 57 |
let obj = { set; get } in |
| 58 |
let name = String.concat "." name in |
| 59 |
if Util.String.Map.mem name !preferences then |
| 60 |
invalid_arg ("Preference " ^ name ^ " already exists") |
| 61 |
else |
| 62 |
preferences := Util.String.Map.add name obj !preferences |
| 63 |
|
| 64 |
val default = init |
| 65 |
val mutable data = init |
| 66 |
val changed : 'a GUtil.signal = new GUtil.signal () |
| 67 |
val name : string list = name |
| 68 |
method connect = new preference_signals ~changed |
| 69 |
method get = data |
| 70 |
method set (n : 'a) = data <- n; changed#call n |
| 71 |
method reset () = self#set default |
| 72 |
method default = default |
| 73 |
method repr = repr |
| 74 |
end |
| 75 |
|
| 76 |
let stick (pref : 'a preference) (obj : < connect : #GObj.widget_signals ; .. >) |
| 77 |
(cb : 'a -> unit) = |
| 78 |
let _ = cb pref#get in |
| 79 |
let p_id = pref#connect#changed ~callback:(fun v -> cb v) in |
| 80 |
let _ = obj#connect#destroy ~callback:(fun () -> pref#connect#disconnect p_id) in |
| 81 |
() |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
let mod_to_str = function |
| 86 |
| `MOD1 -> "<Alt>" |
| 87 |
| `MOD2 -> "<Mod2>" |
| 88 |
| `MOD3 -> "<Mod3>" |
| 89 |
| `MOD4 -> "<Mod4>" |
| 90 |
| `MOD5 -> "<Mod5>" |
| 91 |
| `CONTROL -> "<Control>" |
| 92 |
| `SHIFT -> "<Shift>" |
| 93 |
| `HYPER -> "<Hyper>" |
| 94 |
| `META -> "<Meta>" |
| 95 |
| `SUPER -> "<Super>" |
| 96 |
| `RELEASE | `BUTTON1 | `BUTTON2 | `BUTTON3 | `BUTTON4 | `BUTTON5 | `LOCK -> "" |
| 97 |
|
| 98 |
let mod_list_to_str l = List.fold_left (fun s m -> (mod_to_str m)^s) "" l |
| 99 |
|
| 100 |
let str_to_mod_list s = snd (GtkData.AccelGroup.parse s) |
| 101 |
|
| 102 |
type project_behavior = Ignore_args | Append_args | Subst_args |
| 103 |
|
| 104 |
let string_of_project_behavior = function |
| 105 |
| Ignore_args -> "ignored" |
| 106 |
| Append_args -> "appended to arguments" |
| 107 |
| Subst_args -> "taken instead of arguments" |
| 108 |
|
| 109 |
let project_behavior_of_string = function |
| 110 |
| "taken instead of arguments" -> Subst_args |
| 111 |
| "appended to arguments" -> Append_args |
| 112 |
| _ -> Ignore_args |
| 113 |
|
| 114 |
type inputenc = Elocale | Eutf8 | Emanual of string |
| 115 |
|
| 116 |
let string_of_inputenc = function |
| 117 |
| Elocale -> "LOCALE" |
| 118 |
| Eutf8 -> "UTF-8" |
| 119 |
| Emanual s -> s |
| 120 |
|
| 121 |
let inputenc_of_string = function |
| 122 |
| "UTF-8" -> Eutf8 |
| 123 |
| "LOCALE" -> Elocale |
| 124 |
| s -> Emanual s |
| 125 |
|
| 126 |
type line_ending = [ `DEFAULT | `WINDOWS | `UNIX ] |
| 127 |
|
| 128 |
let line_end_of_string = function |
| 129 |
| "unix" -> `UNIX |
| 130 |
| "windows" -> `WINDOWS |
| 131 |
| _ -> `DEFAULT |
| 132 |
|
| 133 |
let line_end_to_string = function |
| 134 |
| `UNIX -> "unix" |
| 135 |
| `WINDOWS -> "windows" |
| 136 |
| `DEFAULT -> "default" |
| 137 |
|
| 138 |
let use_default_doc_url = "(automatic)" |
| 139 |
|
| 140 |
module Repr = |
| 141 |
struct |
| 142 |
|
| 143 |
let string : string repr = |
| 144 |
object |
| 145 |
inherit [string] repr |
| 146 |
method from s = [s] |
| 147 |
method into = function [s] -> Some s | _ -> None |
| 148 |
end |
| 149 |
|
| 150 |
let string_pair : (string * string) repr = |
| 151 |
object |
| 152 |
inherit [string * string] repr |
| 153 |
method from (s1, s2) = [s1; s2] |
| 154 |
method into = function [s1; s2] -> Some (s1, s2) | _ -> None |
| 155 |
end |
| 156 |
|
| 157 |
let string_list : string list repr = |
| 158 |
object |
| 159 |
inherit [string list] repr |
| 160 |
method from s = s |
| 161 |
method into s = Some s |
| 162 |
end |
| 163 |
|
| 164 |
let string_pair_list (sep : char) : (string * string) list repr = |
| 165 |
object |
| 166 |
inherit [(string * string) list] repr |
| 167 |
val sep' = String.make 1 sep |
| 168 |
method from = CList.map (fun (s1, s2) -> CString.concat sep' [s1; s2]) |
| 169 |
method into l = |
| 170 |
try |
| 171 |
Some (CList.map (fun s -> |
| 172 |
let split = String.split_on_char sep s in |
| 173 |
CList.nth split 0, CList.nth split 1) l) |
| 174 |
with Failure _ -> None |
| 175 |
end |
| 176 |
|
| 177 |
let bool : bool repr = |
| 178 |
object |
| 179 |
inherit [bool] repr |
| 180 |
method from s = [string_of_bool s] |
| 181 |
method into = function |
| 182 |
| ["true"] -> Some true |
| 183 |
| ["false"] -> Some false |
| 184 |
| _ -> None |
| 185 |
end |
| 186 |
|
| 187 |
let int : int repr = |
| 188 |
object |
| 189 |
inherit [int] repr |
| 190 |
method from s = [string_of_int s] |
| 191 |
method into = function |
| 192 |
| [i] -> (try Some (int_of_string i) with _ -> None) |
| 193 |
| _ -> None |
| 194 |
end |
| 195 |
|
| 196 |
let option (r : 'a repr) : 'a option repr = |
| 197 |
object |
| 198 |
inherit ['a option] repr |
| 199 |
method from = function None -> [] | Some v -> "" :: r#from v |
| 200 |
method into = function |
| 201 |
| [] -> Some None |
| 202 |
| "" :: s -> Some (r#into s) |
| 203 |
| _ -> None |
| 204 |
end |
| 205 |
|
| 206 |
let custom (from : 'a -> string) (into : string -> 'a) : 'a repr = |
| 207 |
object |
| 208 |
inherit ['a] repr |
| 209 |
method! raw_from = from |
| 210 |
method! raw_into = into |
| 211 |
method from x = try [from x] with _ -> [] |
| 212 |
method into = function |
| 213 |
| [s] -> (try Some (into s) with _ -> None) |
| 214 |
| _ -> None |
| 215 |
end |
| 216 |
|
| 217 |
let tag : tag repr = |
| 218 |
let _to s = if s = "" then None else Some s in |
| 219 |
let _of = function None -> "" | Some s -> s in |
| 220 |
object |
| 221 |
inherit [tag] repr |
| 222 |
method from tag = [ |
| 223 |
_of tag.tag_fg_color; |
| 224 |
_of tag.tag_bg_color; |
| 225 |
string_of_bool tag.tag_bold; |
| 226 |
string_of_bool tag.tag_italic; |
| 227 |
string_of_bool tag.tag_underline; |
| 228 |
string_of_bool tag.tag_strikethrough; |
| 229 |
] |
| 230 |
method into = function |
| 231 |
| [fg; bg; bd; it; ul; st] -> |
| 232 |
(try Some { |
| 233 |
tag_fg_color = _to fg; |
| 234 |
tag_bg_color = _to bg; |
| 235 |
tag_bold = bool_of_string bd; |
| 236 |
tag_italic = bool_of_string it; |
| 237 |
tag_underline = bool_of_string ul; |
| 238 |
tag_strikethrough = bool_of_string st; |
| 239 |
} |
| 240 |
with _ -> None) |
| 241 |
| _ -> None |
| 242 |
end |
| 243 |
|
| 244 |
end |
| 245 |
|
| 246 |
let get_config_file dirs name = |
| 247 |
let find_config dir = Sys.file_exists (Filename.concat dir name) in |
| 248 |
let config_dir = List.find find_config dirs in |
| 249 |
Filename.concat config_dir name |
| 250 |
|
| 251 |
let get_unicode_bindings_local_file () = |
| 252 |
try Some (get_config_file [Minilib.rocqide_config_home ()] "coqide.bindings") |
| 253 |
with Not_found -> None |
| 254 |
|
| 255 |
let get_unicode_bindings_default_file () = |
| 256 |
let name = "default.bindings" in |
| 257 |
let chk d = Sys.file_exists (Filename.concat d name) in |
| 258 |
try |
| 259 |
let dir = List.find chk (Minilib.rocqide_data_dirs ()) in |
| 260 |
Some (Filename.concat dir name) |
| 261 |
with Not_found -> None |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
let cmd_rocqtop = |
| 266 |
new preference ~name:["cmd_coqtop"] ~init:None ~repr:Repr.(option string) |
| 267 |
|
| 268 |
let cmd_rocqc = |
| 269 |
new preference ~name:["cmd_coqc"] ~init:"coqc" ~repr:Repr.(string) |
| 270 |
|
| 271 |
let cmd_make = |
| 272 |
new preference ~name:["cmd_make"] ~init:"make" ~repr:Repr.(string) |
| 273 |
|
| 274 |
let cmd_rocqmakefile = |
| 275 |
new preference ~name:["cmd_coqmakefile"] ~init:"coq_makefile -o makefile *.v" ~repr:Repr.(string) |
| 276 |
|
| 277 |
let cmd_rocqdoc = |
| 278 |
new preference ~name:["cmd_coqdoc"] ~init:"coqdoc -q -g" ~repr:Repr.(string) |
| 279 |
|
| 280 |
let source_language = |
| 281 |
new preference ~name:["source_language"] ~init:"coq" ~repr:Repr.(string) |
| 282 |
|
| 283 |
let source_style = |
| 284 |
new preference ~name:["source_style"] ~init:"coq_style" ~repr:Repr.(string) |
| 285 |
|
| 286 |
let global_auto_reload = |
| 287 |
new preference ~name:["global_auto_reload"] ~init:false ~repr:Repr.(bool) |
| 288 |
|
| 289 |
let global_auto_reload_delay = |
| 290 |
new preference ~name:["global_auto_reload_delay"] ~init:10000 ~repr:Repr.(int) |
| 291 |
|
| 292 |
let auto_save = |
| 293 |
new preference ~name:["auto_save"] ~init:true ~repr:Repr.(bool) |
| 294 |
|
| 295 |
let auto_save_delay = |
| 296 |
new preference ~name:["auto_save_delay"] ~init:10000 ~repr:Repr.(int) |
| 297 |
|
| 298 |
let auto_save_name = |
| 299 |
new preference ~name:["auto_save_name"] ~init:("#","#") ~repr:Repr.(string_pair) |
| 300 |
|
| 301 |
let read_project = |
| 302 |
let repr = Repr.custom string_of_project_behavior project_behavior_of_string in |
| 303 |
new preference ~name:["read_project"] ~init:Append_args ~repr |
| 304 |
|
| 305 |
let project_file_name = |
| 306 |
new preference ~name:["project_file_name"] ~init:"_CoqProject" ~repr:Repr.(string) |
| 307 |
|
| 308 |
let project_path = |
| 309 |
new preference ~name:["project_path"] ~init:None ~repr:Repr.(option string) |
| 310 |
|
| 311 |
let encoding = |
| 312 |
let repr = Repr.custom string_of_inputenc inputenc_of_string in |
| 313 |
let init = Eutf8 in |
| 314 |
new preference ~name:["encoding"] ~init ~repr |
| 315 |
|
| 316 |
let automatic_tactics = |
| 317 |
let init = ["trivial"; "tauto"; "auto"; "auto with *"; "intuition" ] in |
| 318 |
new preference ~name:["automatic_tactics"] ~init ~repr:Repr.(string_list) |
| 319 |
|
| 320 |
let cmd_print = |
| 321 |
new preference ~name:["cmd_print"] ~init:"lpr" ~repr:Repr.(string) |
| 322 |
|
| 323 |
let attach_modifiers (pref : string preference) ?(filter = Fun.const true) prefix = |
| 324 |
let cb mds = |
| 325 |
let mds = str_to_mod_list mds in |
| 326 |
let change ~path ~key ~modi ~changed = |
| 327 |
if CString.is_prefix prefix path && filter path then |
| 328 |
ignore (GtkData.AccelMap.change_entry ~key ~modi:mds ~replace:true path) |
| 329 |
in |
| 330 |
GtkData.AccelMap.foreach change |
| 331 |
in |
| 332 |
pref#connect#changed ~callback:cb |
| 333 |
|
| 334 |
let select_arch m m_mac = |
| 335 |
|
| 336 |
|
| 337 |
if Coq_config.arch = "Darwin" then m_mac else m |
| 338 |
|
| 339 |
let modifier_for_navigation = |
| 340 |
new preference ~name:["modifier_for_navigation"] |
| 341 |
~init:(select_arch "<Alt>" "<Control><Primary>") ~repr:Repr.(string) |
| 342 |
|
| 343 |
let modifier_for_templates = |
| 344 |
new preference ~name:["modifier_for_templates"] ~init:"<Control><Shift>" ~repr:Repr.(string) |
| 345 |
|
| 346 |
let modifier_for_display = |
| 347 |
new preference ~name:["modifier_for_display"] |
| 348 |
~init:(select_arch "<Alt><Shift>" "<Primary><Shift>")~repr:Repr.(string) |
| 349 |
|
| 350 |
let modifier_for_queries = |
| 351 |
new preference ~name:["modifier_for_queries"] ~init:"<Control><Shift>" ~repr:Repr.(string) |
| 352 |
|
| 353 |
let printopts_item_names = ref [] |
| 354 |
|
| 355 |
let attach_modifiers_callback () = |
| 356 |
|
| 357 |
|
| 358 |
let printopts_filter path = |
| 359 |
let after_last_slash_pos = (String.rindex path '/') + 1 in |
| 360 |
let item_name = String.sub path after_last_slash_pos (String.length path - after_last_slash_pos) in |
| 361 |
List.mem item_name !printopts_item_names |
| 362 |
in |
| 363 |
let _ = attach_modifiers modifier_for_display "<Actions>/View/" ~filter:printopts_filter in |
| 364 |
let _ = attach_modifiers modifier_for_navigation "<Actions>/Navigation/" in |
| 365 |
let _ = attach_modifiers modifier_for_templates "<Actions>/Templates/" in |
| 366 |
let _ = attach_modifiers modifier_for_queries "<Actions>/Queries/" in |
| 367 |
() |
| 368 |
|
| 369 |
let modifiers_valid = |
| 370 |
new preference ~name:["modifiers_valid"] |
| 371 |
|
| 372 |
~init:"<Alt><Control><Shift><Primary>" ~repr:Repr.(string) |
| 373 |
|
| 374 |
let browser_cmd_fmt = Option.default Coq_config.browser (Boot.Util.getenv_rocq "REMOTEBROWSER") |
| 375 |
|
| 376 |
let cmd_browse = |
| 377 |
new preference ~name:["cmd_browse"] ~init:browser_cmd_fmt ~repr:Repr.(string) |
| 378 |
|
| 379 |
let cmd_editor = |
| 380 |
let init = if Sys.os_type = "Win32" then "NOTEPAD %s" else "emacs %s" in |
| 381 |
new preference ~name:["cmd_editor"] ~init ~repr:Repr.(string) |
| 382 |
|
| 383 |
let text_font = |
| 384 |
let init = match Config.gtk_platform with |
| 385 |
| `QUARTZ -> "Arial Unicode MS 11" |
| 386 |
| _ -> "Monospace 10" |
| 387 |
in |
| 388 |
new preference ~name:["text_font"] ~init ~repr:Repr.(string) |
| 389 |
|
| 390 |
let show_toolbar = |
| 391 |
new preference ~name:["show_toolbar"] ~init:true ~repr:Repr.(bool) |
| 392 |
|
| 393 |
let window_width = |
| 394 |
new preference ~name:["window_width"] ~init:800 ~repr:Repr.(int) |
| 395 |
|
| 396 |
let window_height = |
| 397 |
new preference ~name:["window_height"] ~init:600 ~repr:Repr.(int) |
| 398 |
|
| 399 |
let unicode_binding = |
| 400 |
new preference ~name:["unicode_binding"] ~init:true ~repr:Repr.(bool) |
| 401 |
|
| 402 |
let auto_complete = |
| 403 |
new preference ~name:["auto_complete"] ~init:false ~repr:Repr.(bool) |
| 404 |
|
| 405 |
let auto_complete_delay = |
| 406 |
new preference ~name:["auto_complete_delay"] ~init:250 ~repr:Repr.(int) |
| 407 |
|
| 408 |
let stop_before = |
| 409 |
new preference ~name:["stop_before"] ~init:true ~repr:Repr.(bool) |
| 410 |
|
| 411 |
let reset_on_tab_switch = |
| 412 |
new preference ~name:["reset_on_tab_switch"] ~init:false ~repr:Repr.(bool) |
| 413 |
|
| 414 |
let line_ending = |
| 415 |
let repr = Repr.custom line_end_to_string line_end_of_string in |
| 416 |
new preference ~name:["line_ending"] ~init:`DEFAULT ~repr |
| 417 |
|
| 418 |
let document_tabs_pos = |
| 419 |
new preference ~name:["document_tabs_pos"] ~init:"top" ~repr:Repr.(string) |
| 420 |
|
| 421 |
let message_tab_capped = |
| 422 |
new preference ~name:["message_tab_capped"] ~init:true ~repr:Repr.(bool) |
| 423 |
|
| 424 |
let message_tab_length = |
| 425 |
new preference ~name:["message_tab_length"] ~init:1000 ~repr:Repr.(int) |
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
let attach_tag (pref : string preference) (tag : GText.tag) f = |
| 431 |
tag#set_property (f pref#get); |
| 432 |
pref#connect#changed ~callback:(fun c -> tag#set_property (f c)) |
| 433 |
|
| 434 |
let attach_bg (pref : string preference) (tag : GText.tag) = |
| 435 |
attach_tag pref tag (fun c -> `BACKGROUND c) |
| 436 |
|
| 437 |
let attach_fg (pref : string preference) (tag : GText.tag) = |
| 438 |
attach_tag pref tag (fun c -> `FOREGROUND c) |
| 439 |
|
| 440 |
let tags = ref Util.String.Map.empty |
| 441 |
|
| 442 |
let list_tags () = !tags |
| 443 |
|
| 444 |
let make_tag ?fg ?bg ?(bold = false) ?(italic = false) ?(underline = false) ?(strikethrough = false) () = { |
| 445 |
tag_fg_color = fg; |
| 446 |
tag_bg_color = bg; |
| 447 |
tag_bold = bold; |
| 448 |
tag_italic = italic; |
| 449 |
tag_underline = underline; |
| 450 |
tag_strikethrough = strikethrough; |
| 451 |
} |
| 452 |
|
| 453 |
let create_tag name default = |
| 454 |
let pref = new preference ~name:[name] ~init:default ~repr:Repr.(tag) in |
| 455 |
let set_tag tag = |
| 456 |
begin match pref#get.tag_bg_color with |
| 457 |
| None -> tag#set_property (`BACKGROUND_SET false) |
| 458 |
| Some c -> |
| 459 |
tag#set_property (`BACKGROUND_SET true); |
| 460 |
tag#set_property (`BACKGROUND c) |
| 461 |
end; |
| 462 |
begin match pref#get.tag_fg_color with |
| 463 |
| None -> tag#set_property (`FOREGROUND_SET false) |
| 464 |
| Some c -> |
| 465 |
tag#set_property (`FOREGROUND_SET true); |
| 466 |
tag#set_property (`FOREGROUND c) |
| 467 |
end; |
| 468 |
begin match pref#get.tag_bold with |
| 469 |
| false -> tag#set_property (`WEIGHT_SET false) |
| 470 |
| true -> |
| 471 |
tag#set_property (`WEIGHT_SET true); |
| 472 |
tag#set_property (`WEIGHT `BOLD) |
| 473 |
end; |
| 474 |
begin match pref#get.tag_italic with |
| 475 |
| false -> tag#set_property (`STYLE_SET false) |
| 476 |
| true -> |
| 477 |
tag#set_property (`STYLE_SET true); |
| 478 |
tag#set_property (`STYLE `ITALIC) |
| 479 |
end; |
| 480 |
begin match pref#get.tag_underline with |
| 481 |
| false -> tag#set_property (`UNDERLINE_SET false) |
| 482 |
| true -> |
| 483 |
tag#set_property (`UNDERLINE_SET true); |
| 484 |
tag#set_property (`UNDERLINE `SINGLE) |
| 485 |
end; |
| 486 |
begin match pref#get.tag_strikethrough with |
| 487 |
| false -> tag#set_property (`STRIKETHROUGH_SET false) |
| 488 |
| true -> |
| 489 |
tag#set_property (`STRIKETHROUGH_SET true); |
| 490 |
tag#set_property (`STRIKETHROUGH true) |
| 491 |
end; |
| 492 |
in |
| 493 |
let iter table = |
| 494 |
let tag = GText.tag ~name () in |
| 495 |
table#add tag#as_tag; |
| 496 |
ignore (pref#connect#changed ~callback:(fun _ -> set_tag tag)); |
| 497 |
set_tag tag; |
| 498 |
in |
| 499 |
List.iter iter [Tags.Script.table; Tags.Proof.table; Tags.Message.table]; |
| 500 |
tags := Util.String.Map.add name pref !tags |
| 501 |
|
| 502 |
let () = |
| 503 |
let iter (name, tag) = create_tag name tag in |
| 504 |
List.iter iter [ |
| 505 |
("constr.evar", make_tag ()); |
| 506 |
("constr.keyword", make_tag ~fg:"dark green" ()); |
| 507 |
("constr.notation", make_tag ()); |
| 508 |
("constr.path", make_tag ()); |
| 509 |
("constr.reference", make_tag ~fg:"navy"()); |
| 510 |
("constr.type", make_tag ~fg:"#008080" ()); |
| 511 |
("constr.variable", make_tag ()); |
| 512 |
("message.debug", make_tag ()); |
| 513 |
("message.error", make_tag ()); |
| 514 |
("message.warning", make_tag ()); |
| 515 |
("message.prompt", make_tag ~fg:"green" ()); |
| 516 |
("module.definition", make_tag ~fg:"orange red" ~bold:true ()); |
| 517 |
("module.keyword", make_tag ()); |
| 518 |
("tactic.keyword", make_tag ()); |
| 519 |
("tactic.primitive", make_tag ()); |
| 520 |
("tactic.string", make_tag ()); |
| 521 |
("diff.added", make_tag ~bg:"#b6f1c0" ~underline:true ()); |
| 522 |
("diff.removed", make_tag ~bg:"#f6b9c1" ~strikethrough:true ()); |
| 523 |
("diff.added.bg", make_tag ~bg:"#e9feee" ()); |
| 524 |
("diff.removed.bg", make_tag ~bg:"#fce9eb" ()); |
| 525 |
] |
| 526 |
|
| 527 |
let processed_color = |
| 528 |
new preference ~name:["processed_color"] ~init:"light green" ~repr:Repr.(string) |
| 529 |
|
| 530 |
let _ = attach_bg processed_color Tags.Script.processed |
| 531 |
let _ = attach_bg processed_color Tags.Proof.highlight |
| 532 |
|
| 533 |
let processing_color = |
| 534 |
new preference ~name:["processing_color"] ~init:"light blue" ~repr:Repr.(string) |
| 535 |
|
| 536 |
let incompletely_processed_color = |
| 537 |
new preference ~name:["incompletely_processed_color"] ~init:"light sky blue" ~repr:Repr.(string) |
| 538 |
|
| 539 |
let unjustified_conclusion_color = |
| 540 |
new preference ~name:["unjustified_conclusion_color"] ~init:"gold" ~repr:Repr.(string) |
| 541 |
|
| 542 |
let _ = attach_bg processing_color Tags.Script.to_process |
| 543 |
let _ = attach_bg incompletely_processed_color Tags.Script.incomplete |
| 544 |
let _ = attach_bg unjustified_conclusion_color Tags.Script.unjustified |
| 545 |
|
| 546 |
let breakpoint_color = |
| 547 |
new preference ~name:["breakpoint_color"] ~init:"#db5860" ~repr:Repr.(string) |
| 548 |
let white = |
| 549 |
new preference ~name:["white"] ~init:"white" ~repr:Repr.(string) |
| 550 |
|
| 551 |
let _ = attach_bg breakpoint_color Tags.Script.breakpoint |
| 552 |
let _ = attach_fg white Tags.Script.breakpoint |
| 553 |
|
| 554 |
let db_stopping_point_color = |
| 555 |
new preference ~name:["db_stopping_point_color"] ~init:"#2154a6" ~repr:Repr.(string) |
| 556 |
|
| 557 |
let _ = attach_bg db_stopping_point_color Tags.Script.debugging |
| 558 |
let _ = attach_fg white Tags.Script.debugging |
| 559 |
|
| 560 |
let error_color = |
| 561 |
new preference ~name:["error_color"] ~init:"#FFCCCC" ~repr:Repr.(string) |
| 562 |
|
| 563 |
let _ = attach_bg error_color Tags.Script.error_bg |
| 564 |
|
| 565 |
let error_fg_color = |
| 566 |
new preference ~name:["error_fg_color"] ~init:"red" ~repr:Repr.(string) |
| 567 |
|
| 568 |
let _ = attach_fg error_fg_color Tags.Script.error |
| 569 |
|
| 570 |
let dynamic_word_wrap = |
| 571 |
new preference ~name:["dynamic_word_wrap"] ~init:false ~repr:Repr.(bool) |
| 572 |
|
| 573 |
let show_line_number = |
| 574 |
new preference ~name:["show_line_number"] ~init:false ~repr:Repr.(bool) |
| 575 |
|
| 576 |
let auto_indent = |
| 577 |
new preference ~name:["auto_indent"] ~init:true ~repr:Repr.(bool) |
| 578 |
|
| 579 |
let show_spaces = |
| 580 |
new preference ~name:["show_spaces"] ~init:true ~repr:Repr.(bool) |
| 581 |
|
| 582 |
let show_right_margin = |
| 583 |
new preference ~name:["show_right_margin"] ~init:false ~repr:Repr.(bool) |
| 584 |
|
| 585 |
let show_progress_bar = |
| 586 |
new preference ~name:["show_progress_bar"] ~init:true ~repr:Repr.(bool) |
| 587 |
|
| 588 |
let spaces_instead_of_tabs = |
| 589 |
new preference ~name:["spaces_instead_of_tabs"] ~init:true ~repr:Repr.(bool) |
| 590 |
|
| 591 |
let tab_length = |
| 592 |
new preference ~name:["tab_length"] ~init:2 ~repr:Repr.(int) |
| 593 |
|
| 594 |
let highlight_current_line = |
| 595 |
new preference ~name:["highlight_current_line"] ~init:true ~repr:Repr.(bool) |
| 596 |
|
| 597 |
let microPG = |
| 598 |
|
| 599 |
new preference ~name:["nanoPG"] ~init:false ~repr:Repr.(bool) |
| 600 |
|
| 601 |
let user_queries = |
| 602 |
new preference ~name:["user_queries"] ~init:[] ~repr:Repr.(string_pair_list '$') |
| 603 |
|
| 604 |
let diffs = |
| 605 |
new preference ~name:["diffs"] ~init:"off" ~repr:Repr.(string) |
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
let pref_file = Filename.concat (Minilib.rocqide_config_home ()) "coqiderc" |
| 610 |
let accel_file = Filename.concat (Minilib.rocqide_config_home ()) "coqide.keys" |
| 611 |
|
| 612 |
let accel_regex = Str.regexp {|\(; \|\)(gtk_accel_path "\([^""]*\)"|} |
| 613 |
|
| 614 |
exception UnknownFormat |
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
let rec mkdir_p path perms = |
| 619 |
if not (Sys.file_exists path) |
| 620 |
then |
| 621 |
let parent = Filename.dirname path in |
| 622 |
if not (Sys.file_exists parent) && parent<>path |
| 623 |
then mkdir_p parent perms |
| 624 |
else Unix.mkdir path perms |
| 625 |
else () |
| 626 |
|
| 627 |
let save_accel_pref () = |
| 628 |
mkdir_p (Minilib.rocqide_config_home ()) 0o700; |
| 629 |
let tmp_file, fd = Filename.open_temp_file ?perms:(Some 0o644) |
| 630 |
?temp_dir:(Some (Filename.dirname accel_file)) |
| 631 |
"coqide.keys_" "" in |
| 632 |
close_out fd; |
| 633 |
GtkData.AccelMap.save tmp_file; |
| 634 |
|
| 635 |
let fd = open_in tmp_file in |
| 636 |
let map = ref CString.Map.empty in |
| 637 |
let top_lines = ref [] in |
| 638 |
begin |
| 639 |
try |
| 640 |
while true do |
| 641 |
let line = input_line fd in |
| 642 |
if Str.string_match accel_regex line 0 then |
| 643 |
let key = Str.matched_group 2 line in |
| 644 |
map := CString.Map.add key line !map |
| 645 |
else begin |
| 646 |
if not (CString.Map.is_empty !map) then begin |
| 647 |
Minilib.log ("Unknown format for coqide.keys; sorting skipped"); |
| 648 |
raise UnknownFormat |
| 649 |
end; |
| 650 |
top_lines := line :: !top_lines |
| 651 |
end |
| 652 |
done |
| 653 |
with |
| 654 |
| UnknownFormat -> close_in fd |
| 655 |
| End_of_file -> |
| 656 |
close_in fd; |
| 657 |
let fd = open_out tmp_file in |
| 658 |
List.iter (fun l -> Printf.fprintf fd "%s\n" l) (List.rev !top_lines); |
| 659 |
CString.Map.iter (fun k l -> Printf.fprintf fd "%s\n" l) !map; |
| 660 |
close_out fd |
| 661 |
end; |
| 662 |
Sys.rename tmp_file accel_file |
| 663 |
|
| 664 |
let save_rc_pref () = |
| 665 |
mkdir_p (Minilib.rocqide_config_home ()) 0o700; |
| 666 |
let add = Util.String.Map.add in |
| 667 |
let fold key obj accu = add key (obj.get ()) accu in |
| 668 |
let prefs = Util.String.Map.fold fold !preferences Util.String.Map.empty in |
| 669 |
let prefs = Util.String.Map.fold Util.String.Map.add !unknown_preferences prefs in |
| 670 |
Config_lexer.print_file pref_file prefs |
| 671 |
|
| 672 |
let save_pref () = |
| 673 |
save_accel_pref (); |
| 674 |
save_rc_pref () |
| 675 |
|
| 676 |
let try_load_pref_file loader warn file = |
| 677 |
try |
| 678 |
loader file |
| 679 |
with |
| 680 |
e -> warn ~delay:5000 ("Could not load " ^ file ^ " ("^Printexc.to_string e^")") |
| 681 |
|
| 682 |
let load_pref_file loader warn name = |
| 683 |
try |
| 684 |
let user_file = get_config_file [Minilib.rocqide_config_home ()] name in |
| 685 |
warn ~delay:2000 ("Loading " ^ user_file); |
| 686 |
try_load_pref_file loader warn user_file |
| 687 |
with Not_found -> |
| 688 |
try |
| 689 |
let system_wide_file = get_config_file (Minilib.rocqide_system_config_dirs ()) name in |
| 690 |
warn ~delay:5000 ("No user " ^ name ^ ", using system wide configuration"); |
| 691 |
try_load_pref_file loader warn system_wide_file |
| 692 |
with Not_found -> |
| 693 |
|
| 694 |
try |
| 695 |
let old_user_file = get_config_file [Option.default "" (Glib.get_home_dir ())] ("."^name) in |
| 696 |
warn ~delay:5000 ("No " ^ name ^ ", trying to recover from an older version of RocqIDE"); |
| 697 |
try_load_pref_file loader warn old_user_file |
| 698 |
with Not_found -> |
| 699 |
|
| 700 |
warn ~delay:5000 ("No " ^ name ^ ", using default internal configuration") |
| 701 |
|
| 702 |
let load_accel_pref ~warn = |
| 703 |
load_pref_file GtkData.AccelMap.load warn "coqide.keys" |
| 704 |
|
| 705 |
let load_rc_pref ~warn = |
| 706 |
let loader file = |
| 707 |
let m = Config_lexer.load_file file in |
| 708 |
let iter name v = |
| 709 |
if Util.String.Map.mem name !preferences then |
| 710 |
try (Util.String.Map.find name !preferences).set v with _ -> () |
| 711 |
else unknown_preferences := Util.String.Map.add name v !unknown_preferences |
| 712 |
in |
| 713 |
Util.String.Map.iter iter m in |
| 714 |
load_pref_file loader warn "coqiderc"; |
| 715 |
attach_modifiers_callback () |
| 716 |
|
| 717 |
let load_pref ~warn = |
| 718 |
load_rc_pref ~warn; |
| 719 |
load_accel_pref ~warn |