From 806894fc5aa8c266e8978d26ea4255d6affb2fd8 Mon Sep 17 00:00:00 2001 From: contrapunctus Date: Tue, 11 Jan 2022 18:27:11 +0530 Subject: [PATCH] Create verify command --- TODO.org | 8 +++++++- elisp/chronometrist.el | 34 +++++++++++++++++++++------------- elisp/chronometrist.org | 34 +++++++++++++++++++++------------- 3 files changed, 49 insertions(+), 27 deletions(-) diff --git a/TODO.org b/TODO.org index 7384fe0..05e2fb0 100644 --- a/TODO.org +++ b/TODO.org @@ -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 =::: : = (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 diff --git a/elisp/chronometrist.el b/elisp/chronometrist.el index 311fe05..54e6ee5 100644 --- a/elisp/chronometrist.el +++ b/elisp/chronometrist.el @@ -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]] diff --git a/elisp/chronometrist.org b/elisp/chronometrist.org index c265efa..bb177ad 100644 --- a/elisp/chronometrist.org +++ b/elisp/chronometrist.org @@ -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