Add rudimentary tag entry support
This commit is contained in:
parent
160bd98cbc
commit
304486fe9c
1
TODO.org
1
TODO.org
|
@ -11,6 +11,7 @@
|
|||
4. Button actions should accept prefix arguments and behave exactly like their keyboard counterparts.
|
||||
5. mouse-3 should clock-out without asking for reason.
|
||||
6. Some way to ask for the reason just before starting a project. Even when clocking out, the reason is asked /before/ clocking out, which adds time to the project.
|
||||
7. Allow calling chronometrist-in/out from anywhere-within-Emacs (a la timeclock) as well as from the chronometrist buffer.
|
||||
*** Optimization
|
||||
~chronometrist-refresh~ is expensive in CPU, and ~chronometrist-timer~ runs it every 3 seconds by default. :\
|
||||
|
||||
|
|
|
@ -29,6 +29,12 @@
|
|||
(forward-sexp (or arg 1))
|
||||
(delete-region point-1 (point))))
|
||||
|
||||
(defun chronometrist-maybe-string-to-symbol (list)
|
||||
"For each string in LIST, if it has no spaces, convert it to a symbol."
|
||||
(--map (unless (string-match-p "[[:space:]]" it)
|
||||
(make-symbol it))
|
||||
list))
|
||||
|
||||
(defun chronometrist-in (task &optional tags plist)
|
||||
(interactive `(,(completing-read "Task name: "
|
||||
(chronometrist-tasks-from-table)
|
||||
|
@ -52,21 +58,22 @@ this time interval that should be recorded."
|
|||
(when (not (bolp)) (insert "\n"))
|
||||
(plist-pp (append `(:name ,task)
|
||||
(when tags
|
||||
`(:tags ,(--map (unless (string-match-p "[[:space:]]" it)
|
||||
(make-symbol it))
|
||||
tags)))
|
||||
`(:tags ,(chronometrist-maybe-string-to-symbol tags)))
|
||||
(chronometrist-plist-remove plist :tags)
|
||||
`(:start ,(format-time-string "%FT%T%z")))
|
||||
buffer)
|
||||
(save-buffer))))
|
||||
|
||||
;; TODO - implement PLIST arg
|
||||
(defun chronometrist-out (&optional plist)
|
||||
(defun chronometrist-out (&optional tags plist)
|
||||
"Record current moment as stop time to last s-exp in `chronometrist-file'.
|
||||
|
||||
PLIST is a property list containing any other information about
|
||||
this time interval that should be recorded."
|
||||
(interactive)
|
||||
(interactive `(,(completing-read-multiple "Tags (optional): "
|
||||
;; FIXME - use tags, not tasks
|
||||
(chronometrist-tasks-from-table)
|
||||
nil 'confirm nil 'history)))
|
||||
(let ((buffer (find-file-noselect chronometrist-file)))
|
||||
(with-current-buffer buffer
|
||||
(goto-char (point-max))
|
||||
|
@ -74,6 +81,9 @@ this time interval that should be recorded."
|
|||
(backward-list 1)
|
||||
(--> (read buffer)
|
||||
(plist-put it :stop (chronometrist-format-time-iso8601))
|
||||
(when tags (append (-take 2 it)
|
||||
`(:tags ,(chronometrist-maybe-string-to-symbol tags))
|
||||
(-drop 2 it)))
|
||||
(progn
|
||||
(backward-list 1)
|
||||
(chronometrist-delete-list)
|
||||
|
|
|
@ -278,11 +278,11 @@ is the clocked-out project.")
|
|||
(run-hook-with-args 'chronometrist-after-project-stop-functions
|
||||
task))
|
||||
|
||||
(defun chronometrist-run-functions-and-clock-out (task)
|
||||
(defun chronometrist-run-functions-and-clock-out (task tags)
|
||||
"Run hooks and clock out of TASK."
|
||||
(when (run-hook-with-args-until-failure 'chronometrist-before-project-stop-functions
|
||||
task)
|
||||
(chronometrist-out)
|
||||
(chronometrist-out tags)
|
||||
(chronometrist-run-after-project-stop-functions task)))
|
||||
|
||||
;; ## MAJOR-MODE ##
|
||||
|
@ -352,7 +352,11 @@ If there is no project at point, do nothing.
|
|||
|
||||
With numeric prefix argument PREFIX, toggle the Nth project. If
|
||||
there is no corresponding project, do nothing."
|
||||
(interactive "P")
|
||||
(interactive `(,current-prefix-arg
|
||||
,(completing-read-multiple "Tags (optional): "
|
||||
;; FIXME - use tags, not tasks
|
||||
(chronometrist-tasks-from-table)
|
||||
nil 'confirm nil 'history)))
|
||||
(let* ((empty-file (chronometrist-common-file-empty-p chronometrist-file))
|
||||
(nth (when prefix (chronometrist-goto-nth-project prefix)))
|
||||
(at-point (chronometrist-project-at-point))
|
||||
|
@ -366,7 +370,7 @@ there is no corresponding project, do nothing."
|
|||
;; clocked in + target is some other project = clock out, clock in to project
|
||||
;; clocked out = clock in
|
||||
(when current
|
||||
(chronometrist-run-functions-and-clock-out current))
|
||||
(chronometrist-run-functions-and-clock-out current tags))
|
||||
(unless (equal target current)
|
||||
(chronometrist-run-project-start-functions target)
|
||||
(chronometrist-in target))))
|
||||
|
|
Reference in New Issue