[Timeline] Allow to customize category when formatting timelines

This commit is contained in:
Daniel - 2019-03-29 17:41:30 +01:00
parent 90445b6c3d
commit 207fb331ff
Signed by: dbo
GPG Key ID: 4F63DB96D45AA9C6
1 changed files with 27 additions and 8 deletions

View File

@ -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"