From d3c7739ba9e518b5fced9914872f11c50aba1311 Mon Sep 17 00:00:00 2001 From: malc Date: Sat, 12 Jul 2014 04:05:31 +0400 Subject: [PATCH] History sorting (WIP) --- config.ml | 3 +++ main.ml | 43 +++++++++++++++++++++++++------------------ 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/config.ml b/config.ml index 1cbb97b..b114c46 100644 --- a/config.ml +++ b/config.ml @@ -937,6 +937,9 @@ let getanchor () = let fontpath = ref E.s;; +type historder = [ `lastvisit | `title | `path | `file ];; +let historder : historder ref = ref `lastvisit;; + module KeyMap = Map.Make (struct type t = (int * int) let compare = compare end);; diff --git a/main.ml b/main.ml index 300a19a..e606057 100644 --- a/main.ml +++ b/main.ml @@ -3395,22 +3395,29 @@ let gotooutline (_, _, kind) = | Oremotedest remotedest -> gotounder (Uremotedest remotedest) ;; -let genhistoutlines () = - let list = ref [] in - if Config.gethist list - then - let order (path1, c1, _, _, _) (path2, c2, _, _, _) = - -(compare (c1.lastvisit, path1) (c2.lastvisit, path2)) - in - let ol = - List.fold_left (fun accu (path, c, b, x, a) -> - let hist = (path, (c, b, x, a)) in - let base = mbtoutf8 (Filename.basename path) in - (base ^ "\000" ^ c.title, 0, Ohistory hist) :: accu - ) [] (List.sort order !list) - in - Array.of_list ol - else E.a; +let genhistoutlines = + let order ty (p1, c1, _, _, _) (p2, c2, _, _, _) = + - match ty with + | `lastvisit -> compare c1.lastvisit c2.lastvisit + | `path -> compare p1 p2 + | `file -> compare (Filename.basename p1) (Filename.basename p2) + | `title -> compare c1.title c2.title + in + fun orderty -> + let list = ref [] in + if Config.gethist list + then + let ol = + List.fold_left + (fun accu (path, c, b, x, a) -> + let hist = (path, (c, b, x, a)) in + let base = mbtoutf8 (Filename.basename path) in + (base ^ "\000" ^ c.title, 1, Ohistory hist) :: accu + ) + [] (List.sort (order orderty) !list) + in + Array.of_list ol + else E.a; ;; let outlinesource sourcetype = @@ -3517,7 +3524,7 @@ let outlinesource sourcetype = match sourcetype with | `bookmarks -> Array.of_list state.bookmarks | `outlines -> state.outlines - | `history -> genhistoutlines () + | `history -> genhistoutlines !Config.historder ); m_minfo <- m_orig_minfo; m_items <- m_orig_items @@ -3604,7 +3611,7 @@ let enterselector sourcetype = match sourcetype with | `bookmarks -> Array.of_list state.bookmarks | `outlines -> state.outlines - | `history -> genhistoutlines () + | `history -> genhistoutlines !Config.historder in if Array.length outlines = 0 then ( -- 2.11.4.GIT