       (insert "| Category | Start | End | Duration | Task |\n")
       (let ((last-category nil))
         (dolist (line timeline)
-          (when (not (equal last-category (timeline-tools-entry-category line)))
+          (when (not (equal last-category
+                            (funcall timeline-tools-category-function
+                                     line
+                                     timeline-tools--current-time-start
+                                     timeline-tools--current-time-end)))
             (insert "|--|\n")
             (setq last-category (timeline-tools-entry-category line)))
           (insert (format "| %s | %s | %s | %s min | %s | \n"

               (timeline-tools-entry-start-time entry))
            60)))

(defun timeline-tools-entry-category (entry)
  "Return ARCHIVE_CATEGORY or CATEGORY at position given by marker of ENTRY.
Return whatever is found first."
  (let ((marker (timeline-tools-entry-marker entry)))

  :group 'timeline-tools
  :type 'integer)

(defcustom timeline-tools-headline-time-format "%Y-%m-%d %H:%M"
  "Format of time used in the headline of a timeline."
  :group 'timeline-tools
  :type 'string)

(defcustom timeline-tools-time-format "%Y-%m-%d %H:%M"
  "Format of time used inside a timeline."
  :group 'timeline-tools
  :type 'string)

(defcustom timeline-tools-category-function 'timeline-tools-entry-category
  "Function for extracting the category of an entry when formatting a timeline.

This function is supposed to return a string representing the
category of a timeline entry, as it is used when formatting the
timeline with `timeline-tools-redraw-timeline’.  It receives
three arguments, namly the entry itself, the start date, and the
end date of the timeline."
  :group 'timeline-tools
  :type 'function)


;; Mode definition
