From 607c51131a5afaf4fbe35b70cd939a9882e0298e Mon Sep 17 00:00:00 2001 From: malc Date: Thu, 6 Aug 2015 15:08:44 +0300 Subject: [PATCH] Be less ugly --- config.ml | 58 +++++++++++++++++++++++++++------------------------------- main.ml | 9 ++++----- 2 files changed, 31 insertions(+), 36 deletions(-) diff --git a/config.ml b/config.ml index eb66173..6a71e0d 100644 --- a/config.ml +++ b/config.ml @@ -1459,32 +1459,30 @@ let defconfpath = let confpath = ref defconfpath;; -let load1 f = - if Sys.file_exists !confpath - then - match open_in_bin !confpath with - | ic -> - let success = - try - f (do_load get ic) - with exn -> - prerr_endline - ("Error loading configuration from `" ^ !confpath ^ "': " ^ - exntos exn); - false - in - close_in ic; - success - - | (exception exn) -> - prerr_endline - ("Error opening configuration file `" ^ !confpath ^ "': " ^ - exntos exn); - false - else - f (Hashtbl.create 0, defconf) +let load2 f default = + match open_in_bin !confpath with + | ic -> + let res = + try + f (do_load get ic) + with exn -> + prerr_endline + ("Error loading configuration from `" ^ !confpath ^ "': " ^ + exntos exn); + default + in + close_in ic; + res + + | (exception exn) -> + prerr_endline + ("Error opening configuration file `" ^ !confpath ^ "': " ^ + exntos exn); + default ;; +let load1 f = load2 f false;; + let load openlast = let f (h, dc) = if openlast @@ -1519,15 +1517,13 @@ let load openlast = load1 f ;; -let gethist listref = +let gethist () = let f (h, _) = - listref := - Hashtbl.fold (fun path (pc, pb, px, pa, po) accu -> - (path, pc, pb, px, pa, po) :: accu) - h []; - true + Hashtbl.fold (fun path (pc, pb, px, pa, po) accu -> + (path, pc, pb, px, pa, po) :: accu) + h []; in - load1 f + load2 f [] ;; let add_attrs bb always dc c time = diff --git a/main.ml b/main.ml index 7602ad0..4e93515 100644 --- a/main.ml +++ b/main.ml @@ -3376,9 +3376,9 @@ let genhistoutlines = let s = if orderty = t then "[@Uradical] " ^ s else "[ ] " ^ s in s, 0, Oaction (fun () -> Config.historder := t; reeenterhist := true) in - let list = ref [] in - if Config.gethist list - then + match Config.gethist () with + | [] -> E.a + | list -> let ol = List.fold_left (fun accu (path, c, b, x, a, o) -> @@ -3400,10 +3400,9 @@ let genhistoutlines = (if !showorigin then "@Uradical " else " ") ^ "Show origin", 0, Oaction (fun () -> showorigin := not !showorigin; reeenterhist := true) - ] (List.sort (order orderty) !list) + ] (List.sort (order orderty) list) in Array.of_list ol - else E.a; ;; let gotohist (path, (c, bookmarks, x, anchor, origin)) = -- 2.11.4.GIT