mirror of
https://github.com/vale981/ement.el
synced 2025-03-05 09:21:37 -05:00
Change: Remove ts dependency
...since ts is not (yet?) in ELPA, which would prevent Ement from going into it. Also, this should be slightly more efficient, since we won't allocate ts structs for these calculations.
This commit is contained in:
parent
84ac8f9130
commit
a5ea0827d3
5 changed files with 51 additions and 8 deletions
43
ement-lib.el
43
ement-lib.el
|
@ -1088,6 +1088,49 @@ slots, and puts them on ROOM's `members' table."
|
|||
(funcall then data))))
|
||||
(message "Ement: Getting joined members in %s..." (ement--format-room room))))
|
||||
|
||||
(cl-defun ement--human-format-duration (seconds &optional abbreviate)
|
||||
"Return human-formatted string describing duration SECONDS.
|
||||
If SECONDS is less than 1, returns \"0 seconds\". If ABBREVIATE
|
||||
is non-nil, return a shorter version, without spaces. This is a
|
||||
simple calculation that does not account for leap years, leap
|
||||
seconds, etc."
|
||||
;; Copied from `ts-human-format-duration' (same author).
|
||||
(if (< seconds 1)
|
||||
(if abbreviate "0s" "0 seconds")
|
||||
(cl-macrolet ((format> (place)
|
||||
;; When PLACE is greater than 0, return formatted string using its symbol name.
|
||||
`(when (> ,place 0)
|
||||
(format "%d%s%s" ,place
|
||||
(if abbreviate "" " ")
|
||||
(if abbreviate
|
||||
,(substring (symbol-name place) 0 1)
|
||||
,(symbol-name place)))))
|
||||
(join-places (&rest places)
|
||||
;; Return string joining the names and values of PLACES.
|
||||
`(string-join (delq nil
|
||||
(list ,@(cl-loop for place in places
|
||||
collect `(format> ,place))))
|
||||
(if abbreviate "" ", "))))
|
||||
(pcase-let ((`(,years ,days ,hours ,minutes ,seconds) (ement--human-duration seconds)))
|
||||
(join-places years days hours minutes seconds)))))
|
||||
|
||||
(defun ement--human-duration (seconds)
|
||||
"Return list describing duration SECONDS.
|
||||
List includes years, days, hours, minutes, and seconds. This is
|
||||
a simple calculation that does not account for leap years, leap
|
||||
seconds, etc."
|
||||
;; Copied from `ts-human-format-duration' (same author).
|
||||
(cl-macrolet ((dividef (place divisor)
|
||||
;; Divide PLACE by DIVISOR, set PLACE to the remainder, and return the quotient.
|
||||
`(prog1 (/ ,place ,divisor)
|
||||
(setf ,place (% ,place ,divisor)))))
|
||||
(let* ((seconds (floor seconds))
|
||||
(years (dividef seconds 31536000))
|
||||
(days (dividef seconds 86400))
|
||||
(hours (dividef seconds 3600))
|
||||
(minutes (dividef seconds 60)))
|
||||
(list years days hours minutes seconds))))
|
||||
|
||||
;;; Footer
|
||||
|
||||
(provide 'ement-lib)
|
||||
|
|
|
@ -360,7 +360,7 @@ To be called in `ement-sync-callback-hook'."
|
|||
(replace-regexp-in-string "\n" "" topic t t)
|
||||
""))
|
||||
(formatted-timestamp (if latest-ts
|
||||
(ts-human-format-duration (- (ts-unix (ts-now)) (/ latest-ts 1000))
|
||||
(ement--human-format-duration (- (time-convert nil 'integer) (/ latest-ts 1000))
|
||||
t)
|
||||
""))
|
||||
(latest-face (when latest-ts
|
||||
|
|
|
@ -2005,11 +2005,11 @@ For use as `imenu-create-index-function'."
|
|||
ement-ewoc (lambda (node)
|
||||
(pcase (ewoc-data node)
|
||||
(`(ts . ,_) t)))))
|
||||
(ts-format (string-trim ement-room-timestamp-header-with-date-format)))
|
||||
(timestamp-format (string-trim ement-room-timestamp-header-with-date-format)))
|
||||
(cl-loop for node in timestamp-nodes
|
||||
collect (pcase-let*
|
||||
((`(ts ,timestamp) (ewoc-data node))
|
||||
(formatted (format-time-string ts-format timestamp)))
|
||||
(formatted (format-time-string timestamp-format timestamp)))
|
||||
(cons formatted (ewoc-location node))))))
|
||||
|
||||
;;;;; Occur
|
||||
|
|
|
@ -152,7 +152,7 @@
|
|||
((cl-struct ement-room latest-ts) room)
|
||||
(age))
|
||||
(when latest-ts
|
||||
(setf age (ts-diff (ts-now) (make-ts :unix (/ latest-ts 1000))))
|
||||
(setf age (- (time-convert nil 'integer) (/ latest-ts 1000)))
|
||||
(cond (newer-than
|
||||
(when (<= age newer-than)
|
||||
(or name (format "Newer than %s seconds" newer-than))))
|
||||
|
@ -174,7 +174,7 @@
|
|||
((cl-struct ement-room latest-ts) room)
|
||||
(age))
|
||||
(when latest-ts
|
||||
(setf age (- (ts-unix (ts-now)) (/ latest-ts 1000)))
|
||||
(setf age (- (time-convert nil 'integer) (/ latest-ts 1000)))
|
||||
(or (alist-get age intervals nil nil #'>)
|
||||
"Older than a year"))))
|
||||
|
||||
|
@ -319,7 +319,7 @@
|
|||
(min (/ (length ement-room-list-timestamp-colors) 2)
|
||||
(+ 24 (truncate (/ difference-seconds 86400 7)))))))
|
||||
(face (list :foreground (elt ement-room-list-timestamp-colors n)))
|
||||
(formatted-ts (ts-human-format-duration difference-seconds 'abbreviate)))
|
||||
(formatted-ts (ement--human-format-duration difference-seconds 'abbreviate)))
|
||||
(string-match (rx (1+ digit) (repeat 1 alpha)) formatted-ts)
|
||||
(propertize (match-string 0 formatted-ts) 'face face
|
||||
'help-echo formatted-ts))
|
||||
|
|
2
ement.el
2
ement.el
|
@ -6,7 +6,7 @@
|
|||
;; Keywords: comm
|
||||
;; URL: https://github.com/alphapapa/ement.el
|
||||
;; Package-Version: 0.1-pre
|
||||
;; Package-Requires: ((emacs "27.1") (map "2.1") (plz "0.1-pre") (taxy "0.9") (taxy-magit-section "0.9") (svg-lib "0.2.5") (transient "0.3.7") (ts "0.2.1"))
|
||||
;; Package-Requires: ((emacs "27.1") (map "2.1") (plz "0.1-pre") (taxy "0.9") (taxy-magit-section "0.9") (svg-lib "0.2.5") (transient "0.3.7"))
|
||||
|
||||
;; This program is free software; you can redistribute it and/or modify
|
||||
;; it under the terms of the GNU General Public License as published by
|
||||
|
|
Loading…
Add table
Reference in a new issue