[Timeline] Make filtering when formatting customizable

This commit is contained in:
Daniel - 2018-01-21 19:15:33 +01:00
parent 35c9ccbc4d
commit 50b7cf2653
Signed by: dbo
GPG Key ID: 4F63DB96D45AA9C6
1 changed files with 14 additions and 8 deletions

View File

@ -25,6 +25,14 @@
:group 'timeline-tools :group 'timeline-tools
:type 'integer) :type 'integer)
(defcustom timeline-tools-filter-functions
'(timeline-tools-skip-short-entries
timeline-tools-cluster-same-category)
"List of functions to apply when formatting timelines.
Filter are applied in the order they are given in this list."
:group 'timeline-tools
:type '(list function))
;; Utilities ;; Utilities
@ -208,7 +216,7 @@ Markers to org mode tasks are combined into a list."
(mapcar #'third cluster))) (mapcar #'third cluster)))
new-timeline))) new-timeline)))
(defun timeline-tools-skip-short-entries (threshold timeline) (defun timeline-tools-skip-short-entries (timeline)
"Skip entries shorter than THRESHOLD in TIMELINE. "Skip entries shorter than THRESHOLD in TIMELINE.
A slot is short if it is not longer than THRESHOLD seconds. A slot is short if it is not longer than THRESHOLD seconds.
@ -220,7 +228,7 @@ Resulting gaps are distributed evenly among adjacent slots."
(setq new-timeline (setq new-timeline
(cl-remove-if (lambda (entry) (cl-remove-if (lambda (entry)
(<= (- (second entry) (first entry)) (<= (- (second entry) (first entry))
threshold)) timeline-tools-short-task-threshold))
timeline)) timeline))
;; reset start and end times ;; reset start and end times
@ -250,12 +258,10 @@ When called interactively, START and END are queried with
`org-read-date." `org-read-date."
(interactive (list (org-read-date nil nil nil "Start time: ") (interactive (list (org-read-date nil nil nil "Start time: ")
(org-read-date nil nil nil "End time: "))) (org-read-date nil nil nil "End time: ")))
(let ((timeline (->> (timeline-tools-timeline tstart tend files) (let ((timeline (-reduce-from (lambda (tl f)
;; XXX: make these modifiers customizable (funcall f tl))
timeline-tools-cluster-same-category (timeline-tools-timeline tstart tend files)
(timeline-tools-skip-short-entries timeline-tools-filter-functions)))
timeline-tools-short-task-threshold)
timeline-tools-cluster-same-category)))
(let ((target-buffer (get-buffer-create " *Org Timeline*"))) (let ((target-buffer (get-buffer-create " *Org Timeline*")))
(with-current-buffer target-buffer (with-current-buffer target-buffer
(erase-buffer) (erase-buffer)