feat: new command `chronometrist-restart-task`

This commit is contained in:
contrapunctus 2021-06-12 01:52:32 +05:30
parent 29c8939a7d
commit de41c158b5
3 changed files with 53 additions and 21 deletions

View File

@ -5,8 +5,10 @@ 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]
### Added
1. New command `chronometrist-restart-task`
### Changed
1. Display graph ranges in `chronometrist-spark` column
2. Display graph ranges in `chronometrist-spark` column
## [0.8.1] - 2021-06-01
### Changed

View File

@ -1319,13 +1319,14 @@ PREFIX is ignored."
(defvar chronometrist-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "RET") #'chronometrist-toggle-task)
(define-key map (kbd "M-RET") #'chronometrist-toggle-task-no-hooks)
(define-key map (kbd "l") #'chronometrist-open-log)
(define-key map (kbd "r") #'chronometrist-report)
(define-key map [mouse-1] #'chronometrist-toggle-task)
(define-key map [mouse-3] #'chronometrist-toggle-task-no-hooks)
(define-key map (kbd "a") #'chronometrist-add-new-task)
(define-key map (kbd "RET") #'chronometrist-toggle-task)
(define-key map (kbd "M-RET") #'chronometrist-toggle-task-no-hooks)
(define-key map (kbd "<C-return>") #'chronometrist-restart-task)
(define-key map (kbd "l") #'chronometrist-open-log)
(define-key map (kbd "r") #'chronometrist-report)
(define-key map [mouse-1] #'chronometrist-toggle-task)
(define-key map [mouse-3] #'chronometrist-toggle-task-no-hooks)
(define-key map (kbd "a") #'chronometrist-add-new-task)
map)
"Keymap used by `chronometrist-mode'.")
@ -1411,8 +1412,8 @@ If INHIBIT-HOOKS is non-nil, the hooks
(defun chronometrist-toggle-task-no-hooks (&optional prefix)
"Like `chronometrist-toggle-task', but don't run hooks.
With numeric prefix argument PREFIX, toggle the Nth task. If there
is no corresponding task, do nothing."
With numeric prefix argument PREFIX, toggle the Nth task. If
there is no corresponding task, do nothing."
(interactive "P")
(chronometrist-toggle-task prefix t))
@ -1421,6 +1422,19 @@ is no corresponding task, do nothing."
(interactive)
(chronometrist-add-new-task-button nil))
(defun chronometrist-restart-task (&optional inhibit-hooks)
"Change the start time of the active task to the current time.
`chronometrist-before-in-functions' and `chronometrist-after-in-functions' are run again, unless INHIBIT-HOOKS is non-nil or prefix argument is suppled."
(interactive "P")
(when (chronometrist-current-task)
(let* ((plist (plist-put (chronometrist-last) :start (chronometrist-format-time-iso8601)))
(task (plist-get plist :name)))
(unless inhibit-hooks
(run-hook-with-args 'chronometrist-before-in-functions task))
(chronometrist-sexp-replace-last plist)
(unless inhibit-hooks
(run-hook-with-args 'chronometrist-after-in-functions task)))))
;;;###autoload
(defun chronometrist (&optional arg)
"Display the user's tasks and the time spent on them today.

View File

@ -2369,21 +2369,22 @@ PREFIX is ignored."
(chronometrist-out)
(run-hook-with-args 'chronometrist-after-out-functions task)))
#+END_SRC
**** chronometrist-mode-map :keymap:
**** chronometrist-mode-map :keymap:
#+BEGIN_SRC emacs-lisp
(defvar chronometrist-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "RET") #'chronometrist-toggle-task)
(define-key map (kbd "M-RET") #'chronometrist-toggle-task-no-hooks)
(define-key map (kbd "l") #'chronometrist-open-log)
(define-key map (kbd "r") #'chronometrist-report)
(define-key map [mouse-1] #'chronometrist-toggle-task)
(define-key map [mouse-3] #'chronometrist-toggle-task-no-hooks)
(define-key map (kbd "a") #'chronometrist-add-new-task)
(define-key map (kbd "RET") #'chronometrist-toggle-task)
(define-key map (kbd "M-RET") #'chronometrist-toggle-task-no-hooks)
(define-key map (kbd "<C-return>") #'chronometrist-restart-task)
(define-key map (kbd "l") #'chronometrist-open-log)
(define-key map (kbd "r") #'chronometrist-report)
(define-key map [mouse-1] #'chronometrist-toggle-task)
(define-key map [mouse-3] #'chronometrist-toggle-task-no-hooks)
(define-key map (kbd "a") #'chronometrist-add-new-task)
map)
"Keymap used by `chronometrist-mode'.")
#+END_SRC
**** chronometrist-mode :major:mode:
**** chronometrist-mode :major:mode:
#+BEGIN_SRC emacs-lisp
(define-derived-mode chronometrist-mode tabulated-list-mode "Chronometrist"
"Major mode for `chronometrist'."
@ -2475,8 +2476,8 @@ If INHIBIT-HOOKS is non-nil, the hooks
(defun chronometrist-toggle-task-no-hooks (&optional prefix)
"Like `chronometrist-toggle-task', but don't run hooks.
With numeric prefix argument PREFIX, toggle the Nth task. If there
is no corresponding task, do nothing."
With numeric prefix argument PREFIX, toggle the Nth task. If
there is no corresponding task, do nothing."
(interactive "P")
(chronometrist-toggle-task prefix t))
#+END_SRC
@ -2487,6 +2488,21 @@ is no corresponding task, do nothing."
(interactive)
(chronometrist-add-new-task-button nil))
#+END_SRC
**** restart-task :command:
#+BEGIN_SRC emacs-lisp
(defun chronometrist-restart-task (&optional inhibit-hooks)
"Change the start time of the active task to the current time.
`chronometrist-before-in-functions' and `chronometrist-after-in-functions' are run again, unless INHIBIT-HOOKS is non-nil or prefix argument is suppled."
(interactive "P")
(when (chronometrist-current-task)
(let* ((plist (plist-put (chronometrist-last) :start (chronometrist-format-time-iso8601)))
(task (plist-get plist :name)))
(unless inhibit-hooks
(run-hook-with-args 'chronometrist-before-in-functions task))
(chronometrist-sexp-replace-last plist)
(unless inhibit-hooks
(run-hook-with-args 'chronometrist-after-in-functions task)))))
#+END_SRC
**** chronometrist :command:
#+BEGIN_SRC emacs-lisp
;;;###autoload