[chronometrist] improve OSM hook function

The new version doesn't just get the details of the latest changeset -
it gets all changesets until the last one saved in the file.
This commit is contained in:
contrapunctus 2021-08-02 21:49:06 +05:30
parent 679d5d7c83
commit 1a4313f02c
1 changed files with 43 additions and 16 deletions

View File

@ -660,26 +660,53 @@ Return nil (and run `magit-status') if the user answers no."
:success
(cl-function
(lambda (&key data &allow-other-keys)
(let* ((latest-changeset (-> data
(esxml-node-children)
(car)))
(comment (->> latest-changeset
(esxml-query "[k=comment]")
(esxml-node-attributes)
(cdr)
(car)
(cdr)))
(id (-> latest-changeset
(esxml-node-attributes)
(car)
(cdr))))
(chronometrist-append-to-last-expr nil
`(:osm-url ,(concat "https://www.openstreetmap.org/changeset/" id)
:osm-comment ,comment)))))))
(-let* (((&plist :changesets saved-changesets)
(chronometrist-loop-file for plist in chronometrist-file
when (equal "OSM" (plist-get plist :name))
return plist))
(((&plist :osm-url last-url))
(last saved-changesets))
((last-id) (last (split-string last-url "/")))
(response-changesets (esxml-node-children data))
(new-changesets
(cl-loop with attributes with id
for changeset in response-changesets do
(setq attributes (esxml-node-attributes changeset)
id (alist-get 'id attributes))
if (equal id last-id)
return
else collect
(list
:osm-url
(concat
"https://www.openstreetmap.org/changeset/" id)
:osm-comment
(->> (esxml-query "[k=comment]"
latest-changeset)
(esxml-node-attributes)
(alist-get 'v))) into changesets
finally return (reverse changesets))))
(chronometrist-sexp-replace-last
(chronometrist-plist-update
(chronometrist-last) `(:changesets ,new-changesets))))))))
(_ (delete-other-windows))))
#+END_SRC
***** display-key-values
Schema I use for plists - values can be -
1. integer
2. ="string"= | =("list" "of" "strings")=
3. =(INTEGER . "string")=
4. mixed alist - elements can be either #1 or #2
5. a plist, or a list of plists
Programming - =:project=, [ =:component=,] =:feature=
What if...
1. =(a b c)= -> ="a, b, c"=
2. =(a . b)= -> ="a b"= (e.g. =(a (b . c) d)= -> ="a, b c, d"=)
3. sublist - recurse
#+BEGIN_SRC emacs-lisp
;; (contrapunctus-objects-to-string " - " nil) => ""
;; (contrapunctus-objects-to-string " - " 1) => "1"