From 207fb331ff8cc09f869f2f4e83a9fc48b97d21b9 Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Fri, 29 Mar 2019 17:41:30 +0100 Subject: [PATCH] [Timeline] Allow to customize category when formatting timelines --- site-lisp/timeline-tools.el | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/site-lisp/timeline-tools.el b/site-lisp/timeline-tools.el index 15c9092..9c7a7b1 100644 --- a/site-lisp/timeline-tools.el +++ b/site-lisp/timeline-tools.el @@ -57,6 +57,27 @@ Filter are applied in the order they are given in this list." :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 @@ -72,12 +93,6 @@ Filter are applied in the order they are given in this list." (defvar timeline-tools--current-timeline nil "Currently displayed timeline in abstract form.") -(defvar timeline-tools-headline-time-format "%Y-%m-%d %H:%M" - "Format of time used in the headline of a timeline.") - -(defvar timeline-tools-time-format "%Y-%m-%d %H:%M" - "Format of time used inside a timeline.") - (defvar timeline-tools-mode-map (let ((map (make-sparse-keymap))) (define-key map [remap self-insert-command] 'undefined) @@ -125,7 +140,7 @@ MARKER must be a single marker." (timeline-tools-entry-start-time entry)) 60))) -(defun timeline-tools-entry-category (entry) +(defun timeline-tools-entry-category (entry &rest _) "Return ARCHIVE_CATEGORY or CATEGORY at position given by marker of ENTRY. Return whatever is found first." (let ((marker (timeline-tools-entry-marker entry))) @@ -462,7 +477,11 @@ archives." (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"