Use transformers, define a minor mode
The idea is for chronometrist to not need know about extensions.
This commit is contained in:
parent
c8bb401155
commit
8a46e220b2
|
@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
|
|||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [unreleased]
|
||||
### Changed
|
||||
* Package now defines a minor mode, `chronometrist-goal-minor-mode`
|
||||
|
||||
## [0.2.1] - 2020-07-06
|
||||
### Fixed
|
||||
* Package long description in the package menu
|
||||
|
|
|
@ -7,8 +7,12 @@ You can get `chronometrist-goal` from https://github.com/contrapunctus-1/chronom
|
|||
`chronometrist-goal` requires [alert.el](https://github.com/jwiegley/alert) and, of course, [Chronometrist](https://github.com/contrapunctus-1/chronometrist/)
|
||||
|
||||
## Usage
|
||||
### Define some goals
|
||||
First, define some goals in `chronometrist-goal-list`
|
||||
First, hook `chronometrist-goal` to `chronometrist` -
|
||||
```elisp
|
||||
(add-hook 'chronometrist-mode-hook 'chronometrist-goal-minor-mode)
|
||||
```
|
||||
|
||||
Then, define some goals in `chronometrist-goal-list`
|
||||
```elisp
|
||||
(setq chronometrist-goal-list
|
||||
'((60 "Programming")
|
||||
|
|
|
@ -209,6 +209,37 @@ To use, add this to `chronometrist-after-out-functions', and
|
|||
(unless (plist-get last :stop)
|
||||
(chronometrist-goal-run-alert-timers (plist-get last :name)))))
|
||||
|
||||
;;;; minor mode
|
||||
(defun chronometrist-goal-entry-transformer (entry)
|
||||
"Add goal information to the return value of `chronometrist-entries'.
|
||||
ENTRY must be a valid element in the list specified by
|
||||
`tabulated-list-entries'."
|
||||
(-let* (((task vector) entry)
|
||||
(goal (aif (chronometrist-goal-get task) (format "% 4d" it) "")))
|
||||
(list task (vconcat vector `[,goal]))))
|
||||
|
||||
(defun chronometrist-goal-list-format-transformer (format)
|
||||
"Add a goal column to the return value of `tabulated-list-format'.
|
||||
FORMAT should be a vector (see `tabulated-list-format')."
|
||||
(vconcat format `[("Target" 3 t)]))
|
||||
|
||||
(define-minor-mode chronometrist-goal-minor-mode
|
||||
"Toggle `chronometrist-goal-minor-mode'.
|
||||
With a prefix argument ARG, enable
|
||||
`chronometrist-goal-minor-mode' if ARG is positive, and disable
|
||||
it otherwise. If called from Lisp, enable the mode if ARG is
|
||||
omitted or nil."
|
||||
nil nil nil
|
||||
;; when being enabled/disabled, `chronometrist-goal-minor-mode' will already be t/nil here
|
||||
(if chronometrist-goal-minor-mode
|
||||
(progn
|
||||
(add-to-list 'chronometrist-entry-transformers #'chronometrist-goal-entry-transformer)
|
||||
(add-to-list 'chronometrist-list-format-transformers #'chronometrist-goal-list-format-transformer))
|
||||
(setq chronometrist-entry-transformers
|
||||
(remove #'chronometrist-goal-entry-transformer chronometrist-entry-transformers)
|
||||
chronometrist-list-format-transformers
|
||||
(remove #'chronometrist-goal-list-format-transformer chronometrist-list-format-transformers))))
|
||||
|
||||
(provide 'chronometrist-goal)
|
||||
|
||||
;; Local Variables:
|
||||
|
|
Reference in New Issue