Create verify command

This commit is contained in:
contrapunctus 2022-01-11 18:27:11 +05:30
parent 4418bb647a
commit 806894fc5a
3 changed files with 49 additions and 27 deletions

View File

@ -835,7 +835,7 @@ Command to delete the interval currently being recorded. (bind to 'k')
** fix handling of tagged alist group values :bug:
** put each list element on its own line if length of list exceeds fill-column :feature:
* verify command [20%] :feature:
* verify command [16%] :feature:
With different checks, for different levels of speed/thoroughness -
1. [X] (plist group) Sequence of plist group dates
2. [ ] Check that every record (except the last) has a =:stop=
@ -844,6 +844,12 @@ With different checks, for different levels of speed/thoroughness -
5. [ ] (plist group) Midnight spanning interval check (first and last intervals)
6. [ ] (plist group) Check that plist timestamps have the correct date. Only applicable [[dates-in-timestamps][as long as they have a date.]]
There are two approaches I can think of -
1. an interactive Emacs command like =checkdoc=
2. CLI compiler/linter style - emit =<file>:<line>:<column>: <type>: <message>= (GCC-style) output; the user can jump to the error from =compilation-mode=
* Our command dispatches on a backend (CLOS/EIEIO) object; how is one supposed to pass that on the command line? I can think of a few ways (construct an object on the command line, or use the one defined in =chronometrist-backends-alist=), but they are all painful :\
* I don't see a tool like this being used on the command line to begin with...
* format changes
** multiple intervals per record :feature:
#+BEGIN_SRC emacs-lisp

View File

@ -1774,20 +1774,28 @@ Return value is either a list in the form
(with-slots (file hash-table) backend
;; incorrectly ordered groups check
(chronometrist-loop-sexp-file for group in file
with old-date-iso with old-date-unix
with new-date-iso with new-date-unix
with last-plist
;; while (not (bobp))
do (setq new-date-iso (cl-first group)
new-date-unix (parse-iso8601-time-string new-date-iso))
when (and old-date-unix
(time-less-p old-date-unix
new-date-unix))
do (cl-return (format "%s appears before %s on line %s"
new-date-iso old-date-iso (line-number-at-pos)))
else do (setq old-date-iso new-date-iso
old-date-unix new-date-unix)
with old-iso with old-unix with new-iso with new-unix ;; dates
do (setq new-iso (cl-first group)
new-unix (parse-iso8601-time-string new-iso))
when (and old-unix
(time-less-p old-unix new-unix))
do (let ((line (line-number-at-pos)))
(message "%S appears before %S" new-iso old-iso)
(cl-return line))
else do (setq old-iso new-iso old-unix new-unix)
finally return "Yay, no errors! (...that I could find 💀)")))
(defun chronometrist-verify ()
(interactive)
(let* ((backend (chronometrist-active-backend))
(line (chronometrist-verify-backend backend))
(file (chronometrist-backend-file backend))
(buffer (find-file-noselect file)))
(when line
(with-current-buffer buffer
(goto-char (point-min))
(forward-line (1- line)))
(pop-to-buffer buffer))))
;; verify:1 ends here
;; [[file:chronometrist.org::*latest-record][latest-record:1]]

View File

@ -2707,20 +2707,28 @@ Return value is either a list in the form
(with-slots (file hash-table) backend
;; incorrectly ordered groups check
(chronometrist-loop-sexp-file for group in file
with old-date-iso with old-date-unix
with new-date-iso with new-date-unix
with last-plist
;; while (not (bobp))
do (setq new-date-iso (cl-first group)
new-date-unix (parse-iso8601-time-string new-date-iso))
when (and old-date-unix
(time-less-p old-date-unix
new-date-unix))
do (cl-return (format "%s appears before %s on line %s"
new-date-iso old-date-iso (line-number-at-pos)))
else do (setq old-date-iso new-date-iso
old-date-unix new-date-unix)
with old-iso with old-unix with new-iso with new-unix ;; dates
do (setq new-iso (cl-first group)
new-unix (parse-iso8601-time-string new-iso))
when (and old-unix
(time-less-p old-unix new-unix))
do (let ((line (line-number-at-pos)))
(message "%S appears before %S" new-iso old-iso)
(cl-return line))
else do (setq old-iso new-iso old-unix new-unix)
finally return "Yay, no errors! (...that I could find 💀)")))
(defun chronometrist-verify ()
(interactive)
(let* ((backend (chronometrist-active-backend))
(line (chronometrist-verify-backend backend))
(file (chronometrist-backend-file backend))
(buffer (find-file-noselect file)))
(when line
(with-current-buffer buffer
(goto-char (point-min))
(forward-line (1- line)))
(pop-to-buffer buffer))))
#+END_SRC
**** extended protocol