                                          (org-entry-get marker "CATEGORY")))
                                      timeline)))
     (mapcar (lambda (cluster)
-              (list (first (first cluster))       ; start of first entry
-                    (second (car (last cluster))) ; end of last entry
+              (list (caar cluster)         ; start of first entry
+                    (cadar (last cluster)) ; end of last entry
                     (mapcar #'third cluster)))
             new-timeline)))
 


;;; Code:

(eval-when-compile
  (require 'cl))
(require 'dash)
(require 'org)
(require 'org-clock)


A slot is short if it is not longer than THRESHOLD seconds.
Resulting gaps are distributed evenly among adjacent slots."
  (let ((start (caar timeline))
        (end (cadar (last timeline)))
        new-timeline)
    ;; remove all slots that are too short
    (setq new-timeline
          (cl-remove-if (lambda (entry)
                          (<= (- (cadr entry) (car entry))
                              timeline-tools-short-task-threshold))
                        timeline))

    ;; reset start and end times
    (setf (caar new-timeline) start)
    (setf (cadar (last new-timeline)) end)

    ;; distribute gaps evenly among adjacent slots
    (cl-do
        ((sub-timeline new-timeline (cdr sub-timeline)))
        ((null (cdr sub-timeline)))
      (let* ((entry-1 (car sub-timeline))
             (entry-2 (cadr sub-timeline))
             (end-1 (cadr entry-1))
             (start-2 (car entry-2)))
        (when (not (= end-1 start-2))
          (let ((middle (/ (+ end-1 start-2) 2)))
            (setf (cadr entry-1) middle)
            (setf (car entry-2) middle)))))
    new-timeline))

;;;###autoload
