aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--ide/ideutils.ml68
-rw-r--r--ide/preferences.ml50
-rw-r--r--ide/preferences.mli5
3 files changed, 58 insertions, 65 deletions
diff --git a/ide/ideutils.ml b/ide/ideutils.ml
index 86045ee19..db7dcc9f5 100644
--- a/ide/ideutils.ml
+++ b/ide/ideutils.ml
@@ -63,28 +63,25 @@ let print_id id =
let do_convert s =
Utf8_convert.f
(if Glib.Utf8.validate s then begin
- prerr_endline "Input is UTF-8";s
- end else
- let from_loc () =
- let _,char_set = Glib.Convert.get_charset () in
- flash_info
- ("Converting from locale ("^char_set^")");
- Glib.Convert.convert_with_fallback ~to_codeset:"UTF-8" ~from_codeset:char_set s
- in
- let from_manual () =
- flash_info
- ("Converting from "^ !current.encoding_manual);
- Glib.Convert.convert s ~to_codeset:"UTF-8" ~from_codeset:!current.encoding_manual
- in
- if !current.encoding_use_utf8 || !current.encoding_use_locale then begin
- try
- from_loc ()
- with _ -> from_manual ()
- end else begin
- try
- from_manual ()
- with _ -> from_loc ()
- end)
+ prerr_endline "Input is UTF-8";s
+ end else
+ let from_loc () =
+ let _,char_set = Glib.Convert.get_charset () in
+ flash_info
+ ("Converting from locale ("^char_set^")");
+ Glib.Convert.convert_with_fallback ~to_codeset:"UTF-8" ~from_codeset:char_set s
+ in
+ let from_manual enc =
+ flash_info
+ ("Converting from "^ enc);
+ Glib.Convert.convert s ~to_codeset:"UTF-8" ~from_codeset:enc
+ in
+ match !current.encoding with
+ |Preferences.Eutf8 | Preferences.Elocale -> from_loc ()
+ |Emanual enc ->
+ try
+ from_manual enc
+ with _ -> from_loc ())
let try_convert s =
try
@@ -96,18 +93,21 @@ Please choose a correct encoding in the preference panel.*)";;
let try_export file_name s =
try let s =
- try if !current.encoding_use_utf8 then begin
- (prerr_endline "UTF-8 is enforced" ;s)
- end else if !current.encoding_use_locale then begin
- let is_unicode,char_set = Glib.Convert.get_charset () in
- if is_unicode then
- (prerr_endline "Locale is UTF-8" ;s)
- else
- (prerr_endline ("Locale is "^char_set);
- Glib.Convert.convert_with_fallback ~from_codeset:"UTF-8" ~to_codeset:char_set s)
- end else
- (prerr_endline ("Manual charset is "^ !current.encoding_manual);
- Glib.Convert.convert_with_fallback ~from_codeset:"UTF-8" ~to_codeset:!current.encoding_manual s)
+ try match !current.encoding with
+ |Eutf8 -> begin
+ (prerr_endline "UTF-8 is enforced" ;s)
+ end
+ |Elocale -> begin
+ let is_unicode,char_set = Glib.Convert.get_charset () in
+ if is_unicode then
+ (prerr_endline "Locale is UTF-8" ;s)
+ else
+ (prerr_endline ("Locale is "^char_set);
+ Glib.Convert.convert_with_fallback ~from_codeset:"UTF-8" ~to_codeset:char_set s)
+ end
+ |Emanual enc ->
+ (prerr_endline ("Manual charset is "^ enc);
+ Glib.Convert.convert_with_fallback ~from_codeset:"UTF-8" ~to_codeset:enc s)
with e -> (prerr_endline ("Error ("^(Printexc.to_string e)^") in transcoding: falling back to UTF-8") ;s)
in
let oc = open_out file_name in
diff --git a/ide/preferences.ml b/ide/preferences.ml
index 11228f5da..b3804003e 100644
--- a/ide/preferences.ml
+++ b/ide/preferences.ml
@@ -40,6 +40,18 @@ let project_behavior_of_string s =
else if s = "appended to arguments" then Append_args
else Ignore_args
+type inputenc = Elocale | Eutf8 | Emanual of string
+
+let string_of_inputenc = function
+ |Elocale -> "UTF-8"
+ |Eutf8 -> "LOCALE"
+ |Emanual s -> s
+
+let inputenc_of_string s =
+ (if s = "UTF-8" then Eutf8
+ else if s = "LOCALE" then Elocale
+ else Emanual s)
+
type pref =
{
mutable cmd_coqc : string;
@@ -57,9 +69,7 @@ type pref =
mutable read_project : project_behavior;
mutable project_file_name : string;
- mutable encoding_use_locale : bool;
- mutable encoding_use_utf8 : bool;
- mutable encoding_manual : string;
+ mutable encoding : inputenc;
mutable automatic_tactics : string list;
mutable cmd_print : string;
@@ -119,9 +129,7 @@ let (current:pref ref) =
read_project = Ignore_args;
project_file_name = "_CoqProject";
- encoding_use_locale = Sys.os_type <> "Win32" ;
- encoding_use_utf8 = Sys.os_type = "Win32" ;
- encoding_manual = "ISO_8859-1";
+ encoding = if Sys.os_type = "Win32" then Eutf8 else Elocale;
automatic_tactics = ["trivial"; "tauto"; "auto"; "omega";
"auto with *"; "intuition" ];
@@ -202,9 +210,7 @@ let save_pref () =
add "project_options" [string_of_project_behavior p.read_project] ++
add "project_file_name" [p.project_file_name] ++
- add "encoding_use_locale" [string_of_bool p.encoding_use_locale] ++
- add "encoding_use_utf8" [string_of_bool p.encoding_use_utf8] ++
- add "encoding_manual" [p.encoding_manual] ++
+ add "encoding" [string_of_inputenc p.encoding] ++
add "automatic_tactics" p.automatic_tactics ++
add "cmd_print" [p.cmd_print] ++
@@ -264,9 +270,7 @@ let load_pref () =
set_bool "auto_save" (fun v -> np.auto_save <- v);
set_int "auto_save_delay" (fun v -> np.auto_save_delay <- v);
set_pair "auto_save_name" (fun v1 v2 -> np.auto_save_name <- (v1,v2));
- set_bool "encoding_use_locale" (fun v -> np.encoding_use_locale <- v);
- set_bool "encoding_use_utf8" (fun v -> np.encoding_use_utf8 <- v);
- set_hd "encoding_manual" (fun v -> np.encoding_manual <- v);
+ set_hd "encoding_manual" (fun v -> np.encoding <- (inputenc_of_string v));
set_hd "project_options"
(fun v -> np.read_project <- (project_behavior_of_string v));
set_hd "project_file_name" (fun v -> np.project_file_name <- v);
@@ -513,23 +517,13 @@ let configure ?(apply=(fun () -> ())) () =
let encodings =
combo
"File charset encoding "
- ~f:(fun s ->
- match s with
- | "UTF-8" ->
- !current.encoding_use_utf8 <- true;
- !current.encoding_use_locale <- false
- | "LOCALE" ->
- !current.encoding_use_utf8 <- false;
- !current.encoding_use_locale <- true
- | _ ->
- !current.encoding_use_utf8 <- false;
- !current.encoding_use_locale <- false;
- !current.encoding_manual <- s;
- )
+ ~f:(fun s -> !current.encoding <- (inputenc_of_string s))
~new_allowed: true
- ["UTF-8";"LOCALE";!current.encoding_manual]
- (if !current.encoding_use_utf8 then "UTF-8"
- else if !current.encoding_use_locale then "LOCALE" else !current.encoding_manual)
+ ("UTF-8"::"LOCALE":: match !current.encoding with
+ |Emanual s -> [s]
+ |_ -> []
+ )
+ (string_of_inputenc !current.encoding)
in
let read_project =
combo
diff --git a/ide/preferences.mli b/ide/preferences.mli
index 292e43972..d4eb370f3 100644
--- a/ide/preferences.mli
+++ b/ide/preferences.mli
@@ -7,6 +7,7 @@
(************************************************************************)
type project_behavior = Ignore_args | Append_args | Subst_args
+type inputenc = Elocale | Eutf8 | Emanual of string
type pref =
{
@@ -25,9 +26,7 @@ type pref =
mutable read_project : project_behavior;
mutable project_file_name : string;
- mutable encoding_use_locale : bool;
- mutable encoding_use_utf8 : bool;
- mutable encoding_manual : string;
+ mutable encoding : inputenc;
mutable automatic_tactics : string list;
mutable cmd_print : string;