Byte compiler fixes - prefix cl-lib calls

This commit is contained in:
contrapunctus 2019-11-22 10:01:21 +05:30
parent a0b31ddd47
commit 59226f3a80
6 changed files with 94 additions and 95 deletions

View File

@ -67,10 +67,10 @@ It returns t if the table was modified, else nil."
(let ((split-time (chronometrist-events-midnight-spanning-p (plist-get expr :start)
(plist-get expr :stop))))
(when split-time
(let ((first-start (plist-get (first split-time) :start))
(first-stop (plist-get (first split-time) :stop))
(second-start (plist-get (second split-time) :start))
(second-stop (plist-get (second split-time) :stop)))
(let ((first-start (plist-get (cl-first split-time) :start))
(first-stop (plist-get (cl-first split-time) :stop))
(second-start (plist-get (cl-second split-time) :start))
(second-stop (plist-get (cl-second split-time) :stop)))
(backward-list 1)
(chronometrist-delete-list)
(-> expr
@ -95,14 +95,14 @@ Return a list of two events if EVENT was split, else nil."
(let ((split-time (chronometrist-midnight-spanning-p (plist-get event :start)
(plist-get event :stop))))
(when split-time
(let ((first-start (plist-get (first split-time) :start))
(first-stop (plist-get (first split-time) :stop))
(second-start (plist-get (second split-time) :start))
(second-stop (plist-get (second split-time) :stop))
(let ((first-start (plist-get (cl-first split-time) :start))
(first-stop (plist-get (cl-first split-time) :stop))
(second-start (plist-get (cl-second split-time) :start))
(second-stop (plist-get (cl-second split-time) :stop))
;; plist-put modifies lists in-place. The resulting bugs
;; left me puzzled for a while.
(event-1 (copy-list event))
(event-2 (copy-list event)))
(event-1 (cl-copy-list event))
(event-2 (cl-copy-list event)))
(list (-> event-1
(plist-put :start first-start)
(plist-put :stop first-stop))
@ -143,13 +143,13 @@ were none."
(prog1 pending-expr
(setq pending-expr nil)))
(split-expr
(setq pending-expr (second split-expr))
(first split-expr))
(setq pending-expr (cl-second split-expr))
(cl-first split-expr))
(t expr)))
(new-value-date (->> (plist-get new-value :start)
(s-left 10)))
(existing-value (gethash new-value-date chronometrist-events)))
(unless pending-expr (incf index))
(unless pending-expr (cl-incf index))
(puthash new-value-date
(if existing-value
(append existing-value
@ -166,8 +166,8 @@ were none."
(setq acc (append acc `(,(plist-get event :name)))))
value))
chronometrist-events)
(remove-duplicates (sort acc #'string-lessp)
:test #'equal)))
(cl-remove-duplicates (sort acc #'string-lessp)
:test #'equal)))
;; to be replaced by plist-query
(defun chronometrist-events-subset (start-date end-date)
@ -193,8 +193,8 @@ START-DATE and END-DATE must be dates in the form '(YEAR MONTH DAY)."
(seq-filter #'keywordp specifiers))))
;; When all keys from SPECIFIERS are present...
(cond (spec-only-keywords-p
(->> (loop for key in specifiers
collect (plist-member plist key))
(->> (cl-loop for key in specifiers
collect (plist-member plist key))
(seq-every-p #'identity)))
;; ...or SPECIFIERS has no keywords...
((not keyword-list) t)
@ -251,7 +251,7 @@ EXCEPT will be excluded from the return value."
(->> `(,get-key ,(plist-get plist get-key))
(append acc)
(setq acc))
(incf count)))
(cl-incf count)))
get)
(list acc)))
(t (list plist)))

View File

@ -25,7 +25,7 @@ See `timeclock-log-data' for a description."
(let* ((event-string (buffer-substring-no-properties (point-at-bol)
(point-at-eol)))
(event-list (split-string event-string "[ /:]"))
(code (first event-list))
(code (cl-first event-list))
(date-time (--> event-list
(seq-drop it 1)
(seq-take it 6)
@ -43,7 +43,7 @@ See `timeclock-log-data' for a description."
event-string)))
(pcase code
("i"
(incf key-counter)
(cl-incf key-counter)
(puthash key-counter
`(:name ,project-or-comment :start ,date-time)
chronometrist-migrate-table))

View File

@ -17,7 +17,7 @@ DATE-STRING must be in the form \"YYYY-MM-DD\".
The return value is a vector in the form [HOURS MINUTES SECONDS]"
(let* ((date-string (if date-string date-string (chronometrist-date)))
(task-events (chronometrist-task-events-in-day task date-string))
(last-event (copy-list (car (last task-events))))
(last-event (cl-copy-list (car (last task-events))))
(reversed-events-tail (-> task-events
(reverse)
(cdr))))

View File

@ -115,13 +115,13 @@ be removed."
:name :tags :start :stop))
(new-tags (if old-tags
(-> (append old-tags tags)
(remove-duplicates :test #'equal))
(cl-remove-duplicates :test #'equal))
tags))
(new-kvs (copy-list old-expr))
(new-kvs (cl-copy-list old-expr))
(new-kvs (if plist
(-> (loop for (key val) on plist by #'cddr
do (plist-put new-kvs key val)
finally return new-kvs)
(-> (cl-loop for (key val) on plist by #'cddr
do (plist-put new-kvs key val)
finally return new-kvs)
(chronometrist-plist-remove :name :tags :start :stop))
old-kvs))
(buffer (find-file-noselect chronometrist-file)))
@ -148,29 +148,29 @@ as symbol and/or strings.")
"Add keys and values to `chronometrist-tags-history' by querying `chronometrist-events'."
(let ((table chronometrist-tags-history))
(clrhash table)
(loop for plist in (chronometrist-events-query chronometrist-events :get '(:name :tags))
do (let* ((name (plist-get plist :name))
(tags (plist-get plist :tags))
(existing-tags (gethash name table)))
(when tags
(puthash name
(if existing-tags
(append existing-tags `(,tags))
`(,tags))
table))))
(cl-loop for plist in (chronometrist-events-query chronometrist-events :get '(:name :tags))
do (let* ((name (plist-get plist :name))
(tags (plist-get plist :tags))
(existing-tags (gethash name table)))
(when tags
(puthash name
(if existing-tags
(append existing-tags `(,tags))
`(,tags))
table))))
;; We can't use `chronometrist-ht-history-prep' here, because it uses
;; `-flatten'; `chronometrist-tags-history' holds tag combinations (as lists),
;; not individual tags.
(loop for task being the hash-keys of table
using (hash-values list)
do (puthash task
;; Because remove-duplicates keeps the _last_
;; occurrence, trying to avoid this `reverse' by
;; switching the args in the call to `append'
;; above will not get you the correct behavior!
(-> (remove-duplicates list :test #'equal)
(reverse))
table))))
(cl-loop for task being the hash-keys of table
using (hash-values list)
do (puthash task
;; Because remove-duplicates keeps the _last_
;; occurrence, trying to avoid this `reverse' by
;; switching the args in the call to `append'
;; above will not get you the correct behavior!
(-> (cl-remove-duplicates list :test #'equal)
(reverse))
table))))
(defun chronometrist-tags-history-combination-strings (task)
"Return list of past tag combinations for TASK.
@ -194,11 +194,11 @@ This is used to provide completion for individual tags, in
`completing-read-multiple' in `chronometrist-tags-prompt'."
(--> (gethash task chronometrist-tags-history)
(-flatten it)
(remove-duplicates it :test #'equal)
(loop for elt in it
collect (if (stringp elt)
elt
(symbol-name elt)))))
(cl-remove-duplicates it :test #'equal)
(cl-loop for elt in it
collect (if (stringp elt)
elt
(symbol-name elt)))))
(defun chronometrist-tags-prompt (task &optional initial-input)
"Read one or more tags from the user and return them as a list of strings.
@ -227,7 +227,7 @@ _ARGS are ignored. This function always returns t."
(when input
(-> (append last-tags input)
(reverse)
(remove-duplicates :test #'equal)
(cl-remove-duplicates :test #'equal)
(reverse)
(chronometrist-append-to-last-expr nil)))
t))
@ -261,7 +261,7 @@ reversed and will have duplicate elements removed."
;; placing `reverse' after `remove-duplicates'
;; to get a list in reverse chronological order
(-> (-flatten value)
(remove-duplicates :test #'equal)
(cl-remove-duplicates :test #'equal)
(reverse))
table))
table))
@ -288,16 +288,16 @@ leading \":\" is removed."
(name-ht-value (gethash name chronometrist-key-history))
(keys (->> (chronometrist-plist-remove expr :name :start :stop :tags)
(seq-filter #'keywordp))))
(loop for key in keys
do (when key
(let ((key-string (->> (symbol-name key)
(s-chop-prefix ":")
(list))))
(puthash name
(if name-ht-value
(append name-ht-value key-string)
key-string)
chronometrist-key-history))))))
(cl-loop for key in keys
do (when key
(let ((key-string (->> (symbol-name key)
(s-chop-prefix ":")
(list))))
(puthash name
(if name-ht-value
(append name-ht-value key-string)
key-string)
chronometrist-key-history))))))
(chronometrist-ht-history-prep chronometrist-key-history)))))
;; FIXME - seems to be a little buggy. The latest value for e.g. :song
@ -312,25 +312,24 @@ The values are stored in `chronometrist-value-history'."
user-kvs)
(clrhash table)
(maphash (lambda (_date plist-list)
(loop for plist in plist-list
do (setq user-kvs (chronometrist-plist-remove plist
:name :tags
:start :stop))
(loop for (key1 val1) on user-kvs by #'cddr
do (let* ((key1-string (->> (symbol-name key1)
(s-chop-prefix ":")))
(key1-ht (gethash key1-string table))
(val1 (if (not (stringp val1))
(list
(format "%s" val1))
(list val1))))
(puthash key1-string
(if key1-ht
(append key1-ht val1)
val1)
table)))))
chronometrist-events)
(chronometrist-ht-history-prep table)))
(cl-loop for plist in plist-list
do (setq user-kvs (chronometrist-plist-remove plist
:name :tags
:start :stop))
(cl-loop for (key1 val1) on user-kvs by #'cddr
do (let* ((key1-string (->> (symbol-name key1)
(s-chop-prefix ":")))
(key1-ht (gethash key1-string table))
(val1 (if (not (stringp val1))
(list
(format "%s" val1))
(list val1))))
(puthash key1-string
(if key1-ht
(append key1-ht val1)
val1)
table)))))
(chronometrist-ht-history-prep table))))
;; TODO - refactor this to use `chronometrist-append-to-last-expr'
(defun chronometrist-kv-accept ()
@ -411,12 +410,12 @@ USED-KEYS are keys they have already used in this session."
(chronometrist-kv-completion-quit-key)
" to quit): ")
;; don't suggest keys which have already been used
(loop for used-key in used-keys
do (->> key-suggestions
(seq-remove (lambda (key)
(equal key used-key)))
(setq key-suggestions))
finally return key-suggestions))))
(cl-loop for used-key in used-keys
do (->> key-suggestions
(seq-remove (lambda (key)
(equal key used-key)))
(setq key-suggestions))
finally return key-suggestions))))
(defun chronometrist-value-prompt (key)
"Prompt the user to enter values.

View File

@ -77,7 +77,7 @@ For time value format, see (info \"(elisp)Time of Day\")."
(stop-iso (if stop
(parse-iso8601-time-string stop)
(current-time))))
(incf index)
(cl-incf index)
(setq result (append result `((,start-iso ,stop-iso))))))
result))
@ -159,7 +159,7 @@ reduced to the desired range using
`chronometrist-events-subset'."
(mapcar (lambda (project)
(let* ((active-days (chronometrist-statistics-count-active-days project table))
(active-percent (case (plist-get chronometrist-statistics--ui-state :mode)
(active-percent (cl-case (plist-get chronometrist-statistics--ui-state :mode)
('week (* 100 (/ active-days 7.0)))))
(active-percent (if (zerop active-days)
(format " % 6s" "-")
@ -183,7 +183,7 @@ reduced to the desired range using
"Create entries to be displayed in the buffer created by `chronometrist-statistics'."
;; We assume that all fields in `chronometrist-statistics--ui-state' are set, so they must
;; be changed by the view-changing functions.
(case (plist-get chronometrist-statistics--ui-state :mode)
(cl-case (plist-get chronometrist-statistics--ui-state :mode)
('week
(let* ((start (plist-get chronometrist-statistics--ui-state :start))
(end (plist-get chronometrist-statistics--ui-state :end))
@ -220,7 +220,7 @@ If FIRSTONLY is non-nil, return only the first keybinding found."
(inhibit-read-only t))
(goto-char (point-max))
(insert w)
(insert-text-button (case (plist-get chronometrist-statistics--ui-state :mode)
(insert-text-button (cl-case (plist-get chronometrist-statistics--ui-state :mode)
('week "Weekly view"))
;; 'action #'chronometrist-report-previous-week ;; TODO - make interactive function to accept new mode from user
'follow-link t)
@ -330,7 +330,7 @@ If ARG is a numeric argument, go back that many times."
(end-unix (->> (plist-get chronometrist-statistics--ui-state :end)
(chronometrist-iso-date->timestamp)
(parse-iso8601-time-string))))
(case (plist-get chronometrist-statistics--ui-state :mode)
(cl-case (plist-get chronometrist-statistics--ui-state :mode)
('week
(let* ((new-start (time-subtract start-unix
(* 7 chronometrist-seconds-in-day arg)))
@ -360,7 +360,7 @@ If ARG is a numeric argument, go forward that many times."
(end-unix (->> (plist-get chronometrist-statistics--ui-state :end)
(chronometrist-iso-date->timestamp)
(parse-iso8601-time-string))))
(case (plist-get chronometrist-statistics--ui-state :mode)
(cl-case (plist-get chronometrist-statistics--ui-state :mode)
('week
(let* ((new-start (time-add start-unix
(* 7 chronometrist-seconds-in-day arg)))

View File

@ -404,7 +404,7 @@ If numeric argument ARG is 2, run `chronometrist-statistics'."
(let ((buffer (get-buffer-create chronometrist-buffer-name))
(w (get-buffer-window chronometrist-buffer-name t)))
(cond
(arg (case arg
(arg (cl-case arg
(1 (chronometrist-report))
(2 (chronometrist-statistics))))
(w (with-current-buffer buffer