                            s/split-lines
                            first)]]))]]])))))
 
+(defn task-sorter
+  "Sorts tasks."
+  [x y]
+  (let [c (compare (get-in x [:task :priority] :X)
+                   (get-in y [:task :priority] :X))]
+    (if (not= c 0) c (compare (get-in x [:task :active-from])
+                              (get-in y [:task :active-from])))))
+
 (defn started-tasks-list
   "Renders table with open entries, such as started tasks and open habits."
   [tab-group local put-fn]

                 [:td [:strong story]]
                 [:td.time (u/duration-string v)]]))]])))))

(defn entry-compare
  "Compare by prio first, then by active-from."
  [k]
  (fn [x y]
    (let [prio-x (get-in x [k :priority] :X)
          prio-y (get-in y [k :priority] :X)
          c (compare prio-x prio-y)
          active-x (get-in x [k :active-from])
          active-y (get-in y [k :active-from])]
      (if (not= c 0) c (compare active-x active-y)))))

(defn waiting-habits-list
  "Renders table with open entries, such as started tasks and open habits."

                      (name fk)])
        entries-list (reaction
                       (let [entries-map @entries-map
                             find-missing (u/find-missing-entry entries-map put-fn)
                             entries (->> @started-tasks
                                          (map (fn [ts] (find-missing ts)))
                                          (filter on-hold-filter)
                                          (filter saga-filter)
                                          (sort task-sorter))
                             conf (merge @cfg @options)]
                         (if (:show-pvt @cfg)
                           entries
