Run hooks in remaining functions

This commit is contained in:
Kashish Sharma 2018-09-26 22:36:26 +05:30
parent 8f50865e81
commit 000b5882d8

View File

@ -293,26 +293,25 @@ point. If there is no project at point, do nothing.
With a numeric prefix argument, toggle the Nth project. If there
is no corresponding project, do nothing."
(interactive "P")
(let* ((nth-project (when prefix (chronometrist-get-nth-project prefix)))
(project-at-point (chronometrist-project-at-point))
(target-project (or nth-project project-at-point))
(current-project (chronometrist-current-project))
(ask (not no-prompt)))
(cond ((chronometrist-common-file-empty-p timeclock-file)
(timeclock-in nil nil t))
(let* ((empty-file (chronometrist-common-file-empty-p timeclock-file))
(nth (when prefix (chronometrist-get-nth-project prefix)))
(at-point (chronometrist-project-at-point))
(target (or nth at-point))
(current (chronometrist-current-project))
(ask (not no-prompt)))
(cond (empty-file (chronometrist-add-new-project)) ;; do not run hooks - chronometrist-add-new-project will do it
;; What should we do if the user provides an invalid argument? Currently - nothing.
((and prefix (not nth-project)))
(target-project ;; do nothing if there's no project at point
;; If we're clocked in to anything - clock out or change projects
(if current-project
(if (equal target-project current-project)
(timeclock-out nil nil ask)
;; We don't use timeclock-change because it doesn't prompt for the reason
(progn
(timeclock-out nil nil ask)
(timeclock-in nil target-project nil)))
;; Otherwise, run timeclock-in with project at point as default suggestion
(timeclock-in nil target-project nil))))
((and prefix (not nth)))
(target ;; do nothing if there's no project at point
;; clocked in + target is current = clock out
;; clocked in + target is some other project = clock out, clock in to project
;; clocked out = clock in
(when current
(timeclock-out nil nil ask)
(chronometrist-run-project-end-hook current))
(unless (equal target current)
(chronometrist-run-project-start-hook at-point)
(timeclock-in nil target nil))))
(chronometrist-refresh)))
(defun chronometrist-toggle-project-no-reason (&optional prefix)