From 3bb7635c3e9d8df3fa546a0009de2fe2ed5b7a53 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Sun, 27 Aug 2023 22:37:15 -0400 Subject: * lisp/mastodon.el: Remove `ts` from `Package-Requires:` This is/was the main hurdle to be able to include `mastodon.el` into (Non)GNU ELPA since `ts` is/was not in (Non)GNU ELPA. Also I think the replacement function is more flexible and gives better results :-) * lisp/mastodon-tl.el: Don't require `ts`. (mastodon-tl--time-units): New const. (mastodon-tl--human-duration): New function. (mastodon-tl--format-poll-expiry): Rewrite using it. --- lisp/mastodon-tl.el | 52 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 18 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 1d672a5..1b53460 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -32,7 +32,6 @@ ;;; Code: (require 'shr) -(require 'ts) (require 'thingatpt) ; for word-at-point (require 'time-date) (require 'cl-lib) @@ -710,6 +709,7 @@ The descriptive string is a human readable version relative to the current time while the next change timestamp give the first time that this description will change in the future. TIMESTAMP is assumed to be in the past." + ;; FIXME: Use `mastodon-tl--human-duration'! (let* ((now (or current-time (current-time))) (time-difference (time-subtract now timestamp)) (seconds-difference (float-time time-difference)) @@ -1145,25 +1145,41 @@ LONGEST-OPTION is the option whose length determines the formatting." (propertize str 'face 'font-lock-comment-face)) "\n")))) +(defconst mastodon-tl--time-units + '("sec" 60.0 ;Use a float to convert `n' to float. + "min" 60 + "hour" 24 + "day" 7 + "week" 4.345 + "month" 12 + "year")) + (defun mastodon-tl--format-poll-expiry (timestamp) "Convert poll expiry TIMESTAMP into a descriptive string." - (let ((parsed (ts-human-duration - (ts-diff (ts-parse timestamp) (ts-now))))) - (cond ((> (plist-get parsed :days) 0) - (format "%s days, %s hours left" - (plist-get parsed :days) - (plist-get parsed :hours))) - ((> (plist-get parsed :hours) 0) - (format "%s hours, %s minutes left" - (plist-get parsed :hours) - (plist-get parsed :minutes))) - ((> (plist-get parsed :minutes) 0) - (format "%s minutes left" (plist-get parsed :minutes))) - (t ; we failed to guess: - (format "%s days, %s hours, %s minutes left" - (plist-get parsed :days) - (plist-get parsed :hours) - (plist-get parsed :minutes)))))) + ;; FIXME: Could we document the format of TIMESTAMP here? + (let* ((ts (encode-time (parse-time-string timestamp))) + (seconds (time-to-seconds (time-subtract ts nil)))) + (concat (mastodon-tl--human-duration (max 0 seconds)) " left"))) + +(defun mastodon-tl--human-duration (seconds) + "Return a string describing SECONDS in a more human-friendly way." + (cl-assert (>= seconds 0)) + (let* ((units mastodon-tl--time-units) + (n1 seconds) (unit1 (pop units)) n2 unit2 + next) + (while (and units (> (truncate (setq next (/ n1 (car units)))) 0)) + (setq unit2 unit1) + (setq n2 (- n1 (* (car units) (truncate n1 (car units))))) + (setq n1 next) + (pop units) + (setq unit1 (pop units))) + (setq n1 (truncate n1)) + (if n2 (setq n2 (truncate n2))) + (if (memq n2 '(nil 0)) + (format "%d %s%s" n1 unit1 (if (> n1 1) "s" "")) + (format "%d %s%s, %d %s%s" + n1 unit1 (if (> n1 1) "s" "") + n2 unit2 (if (> n2 1) "s" ""))))) (defun mastodon-tl--read-poll-option () "Read a poll option to vote on a poll." -- cgit v1.2.3 From 3212f5dd0b5716e1bb4db60fb65bd950c08ec12a Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Sun, 27 Aug 2023 22:39:45 -0400 Subject: Simplify calls to `alist-get` * lisp/mastodon-toot.el (mastodon-toot--set-toot-language): * lisp/mastodon-tl.el (mastodon-tl--read-rules-ids): * lisp/mastodon-profile.el (mastodon-profile--remove-from-followers-list): * lisp/mastodon-auth.el (mastodon-auth--access-token): * lisp/mastodon-views.el (mastodon-views--add-account-to-list) (mastodon-views--remove-account-from-list): Remove redundant optional arg to `alist-get` (`equal` is already the default). --- lisp/mastodon-auth.el | 6 ++---- lisp/mastodon-profile.el | 2 +- lisp/mastodon-tl.el | 2 +- lisp/mastodon-toot.el | 2 +- lisp/mastodon-views.el | 4 ++-- 5 files changed, 7 insertions(+), 9 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index eb57368..5069271 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -172,15 +172,13 @@ When ASK is absent return nil." Generate/save token if none known yet." (cond (mastodon-auth--token-alist ;; user variables are known and initialised. - (alist-get mastodon-instance-url mastodon-auth--token-alist - nil nil 'equal)) + (alist-get mastodon-instance-url mastodon-auth--token-alist)) ((plist-get (mastodon-client--active-user) :access_token) ;; user variables need to be read from plstore. (push (cons mastodon-instance-url (plist-get (mastodon-client--active-user) :access_token)) mastodon-auth--token-alist) - (alist-get mastodon-instance-url mastodon-auth--token-alist - nil nil 'equal)) + (alist-get mastodon-instance-url mastodon-auth--token-alist)) ((null mastodon-active-user) ;; user not aware of 2FA-related changes and has not set ;; `mastodon-active-user'. Make user aware and error out. diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index a5abe5a..658c371 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -827,7 +827,7 @@ Currently limited to 100 handles. If not found, try (response (mastodon-http--get-json url `(("limit" . "100")))) (handles (mastodon-tl--map-alist-vals-to-alist 'acct 'id response)) (choice (completing-read "Remove from followers: " handles)) - (id (alist-get choice handles nil nil 'equal))) + (id (alist-get choice handles))) (mastodon-profile--remove-user-from-followers id))) (defun mastodon-profile--add-private-note-to-account () diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 1b53460..de26853 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2207,7 +2207,7 @@ report the account for spam." "rules [TAB for options, | to separate]: " alist nil t))) (mapcar (lambda (x) - (alist-get x alist nil nil 'equal)) + (alist-get x alist)) choices))) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 14b9d68..f14aec3 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -1130,7 +1130,7 @@ Return its two letter ISO 639 1 code." (let* ((choice (completing-read "Language for this toot: " mastodon-iso-639-1))) (setq mastodon-toot--language - (alist-get choice mastodon-iso-639-1 nil nil 'equal)) + (alist-get choice mastodon-iso-639-1)) (message "Language set to %s" choice) (mastodon-toot--update-status-fields))) diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index a40603d..00b9467 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -391,7 +391,7 @@ If ACCOUNT-ID and HANDLE are provided use them rather than prompting." (handles (mastodon-tl--map-alist-vals-to-alist 'acct 'id followings)) (account (or handle (completing-read "Account to add: " handles nil t))) - (account-id (or account-id (alist-get account handles nil nil 'equal))) + (account-id (or account-id (alist-get account handles))) (url (mastodon-http--api (format "lists/%s/accounts" list-id))) (response (mastodon-http--post url `(("account_ids[]" . ,account-id))))) (mastodon-views--list-action-triage @@ -425,7 +425,7 @@ If ID is provided, use that list." (handles (mastodon-tl--map-alist-vals-to-alist 'acct 'id accounts)) (account (completing-read "Account to remove: " handles nil t)) - (account-id (alist-get account handles nil nil 'equal)) + (account-id (alist-get account handles)) (url (mastodon-http--api (format "lists/%s/accounts" list-id))) (args (mastodon-http--build-array-params-alist "account_ids[]" `(,account-id))) (response (mastodon-http--delete url args))) -- cgit v1.2.3 From 1818aeffdc95b099fe22d2b3d444e6cdcdc28b28 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Sun, 27 Aug 2023 22:46:33 -0400 Subject: Don't refer to obsolete font-lock face variables * lisp/mastodon-profile.el (mastodon-profile--update-user-profile-note): * lisp/mastodon-tl.el (mastodon-tl--byline, mastodon-tl--toot-stats): * lisp/mastodon-toot.el (mastodon-toot--view-toot-edits): * lisp/mastodon-views.el (mastodon-views--minor-view): Quote face names. --- lisp/mastodon-profile.el | 4 ++-- lisp/mastodon-tl.el | 12 ++++++------ lisp/mastodon-toot.el | 4 ++-- lisp/mastodon-views.el | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 658c371..0a3a236 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -250,14 +250,14 @@ NO-REBLOGS means do not display boosts in statuses." (mastodon-tl--set-buffer-spec (buffer-name buffer) "accounts/verify_credentials" nil) (setq-local header-line-format (propertize msg-str - 'face font-lock-comment-face)) + 'face 'font-lock-comment-face)) (mastodon-profile-update-mode t) (insert (propertize (concat (propertize "0" 'note-counter t 'display nil) "/500 characters") 'read-only t - 'face font-lock-comment-face + 'face 'font-lock-comment-face 'note-header t) "\n") (make-local-variable 'after-change-functions) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index de26853..5f26d82 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -677,7 +677,7 @@ this just means displaying toot client." (propertize (format-time-string mastodon-toot-timestamp-format edited-parsed) - 'face font-lock-comment-face + 'face 'font-lock-comment-face 'timestamp edited-parsed 'display (if mastodon-tl--enable-relative-timestamps (mastodon-tl--relative-time-description edited-parsed) @@ -1377,19 +1377,19 @@ To disable showing the stats, customize 'favourited-p (eq 't .favourited) 'favourites-field t 'help-echo (format "%s favourites" .favourites_count) - 'face font-lock-comment-face) - (propertize " | " 'face font-lock-comment-face) + 'face 'font-lock-comment-face) + (propertize " | " 'face 'font-lock-comment-face) (propertize boosts 'boosted-p (eq 't .reblogged) 'boosts-field t 'help-echo (format "%s boosts" .reblogs_count) - 'face font-lock-comment-face) - (propertize " | " 'face font-lock-comment-face) + 'face 'font-lock-comment-face) + (propertize " | " 'face 'font-lock-comment-face) (propertize replies 'replies-field t 'replies-count .replies_count 'help-echo (format "%s replies" .replies_count) - 'face font-lock-comment-face))) + 'face 'font-lock-comment-face))) (status (concat (propertize " " diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index f14aec3..8170110 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -905,7 +905,7 @@ instance to edit a toot." (insert (propertize (if (= count 1) (format "%s [original]:\n" count) (format "%s:\n" count)) - 'face font-lock-comment-face) + 'face 'font-lock-comment-face) (mastodon-toot--insert-toot-iter x) "\n") (cl-incf count)) @@ -915,7 +915,7 @@ instance to edit a toot." (format "Edits to toot by %s:" (alist-get 'username (alist-get 'account (car history)))) - 'face font-lock-comment-face)) + 'face 'font-lock-comment-face)) (mastodon-tl--set-buffer-spec (buffer-name (current-buffer)) (format "statuses/%s/history" id) nil)))) diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index 00b9467..ad36664 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -177,7 +177,7 @@ provides the JSON data." (if (seq-empty-p data) (insert (propertize (format "Looks like you have no %s for now." view-name) - 'face font-lock-comment-face + 'face 'font-lock-comment-face 'byline t 'toot-id "0")) ; so point can move here when no item (funcall insert-fun data) -- cgit v1.2.3 From db685c21edcb2eb7f686a9e38e204d3e333f902b Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Sun, 27 Aug 2023 22:52:11 -0400 Subject: Misc minor cosmetic changes Prefer # to quote function names. Remove some redundant `:group` arguments. Properly newline-terminate text files. Fix some ' warnings in docstrings. --- .gitignore | 2 +- lisp/mastodon-tl.el | 8 ++++---- lisp/mastodon-toot.el | 8 ++++---- lisp/mastodon.el | 4 +--- 4 files changed, 10 insertions(+), 12 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/.gitignore b/.gitignore index ad98902..be78d26 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,4 @@ dist/ /lisp/mastodon-autoloads.el # ELSA files -/lisp/.elsa/ \ No newline at end of file +/lisp/.elsa/ diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 5f26d82..c921ba9 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -203,8 +203,8 @@ If nil `(point-min)' is used instead.") (defvar mastodon-tl--link-keymap (let ((map (make-sparse-keymap))) - (define-key map [return] 'mastodon-tl--do-link-action-at-point) - (define-key map [mouse-2] 'mastodon-tl--do-link-action) + (define-key map [return] #'mastodon-tl--do-link-action-at-point) + (define-key map [mouse-2] #'mastodon-tl--do-link-action) (define-key map [follow-link] 'mouse-face) map) "The keymap for link-like things in buffer (except for shr.el generate links). @@ -1600,7 +1600,7 @@ This includes the update profile note buffer, but not the preferences one." (string-prefix-p "accounts" (mastodon-tl--endpoint nil :no-error))) (defun mastodon-tl--timeline-proper-p () - "Return non-nil if the current buffer is a 'proper' timeline. + "Return non-nil if the current buffer is a \"proper\" timeline. A proper timeline excludes notifications, threads, profiles, and other toot buffers that aren't strictly mastodon timelines." (let ((timeline-buffers @@ -2290,7 +2290,7 @@ when showing followers or accounts followed." (defun mastodon-tl--get-link-header-from-response (headers) "Get http Link header from list of http HEADERS." ;; pleroma uses "link", so case-insensitive match required: - (when-let ((link-headers (alist-get "Link" headers nil nil 'cl-equalp))) + (when-let ((link-headers (alist-get "Link" headers nil nil #'cl-equalp))) (split-string link-headers ", "))) (defun mastodon-tl--more () diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 8170110..d974e04 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -222,7 +222,7 @@ Takes its form from `window-configuration-to-register'.") (persist-defvar mastodon-toot-draft-toots-list nil "A list of toots that have been saved as drafts. For the moment we just put all composed toots in here, as we want -to also capture toots that are 'sent' but that don't successfully +to also capture toots that are \"sent\" but that don't successfully send.") @@ -687,7 +687,7 @@ TEXT-ONLY means don't check for attachments or polls." ;;; EMOJIS (defalias 'mastodon-toot--insert-emoji - 'emojify-insert-emoji + #'emojify-insert-emoji "Prompt to insert an emoji.") (defun mastodon-toot--emoji-dir () @@ -1623,7 +1623,7 @@ Added to `after-change-functions' in new toot buffers." mastodon-toot-draft-toots-list nil t))) (setq mastodon-toot-draft-toots-list - (cl-delete draft mastodon-toot-draft-toots-list :test 'equal)) + (cl-delete draft mastodon-toot-draft-toots-list :test #'equal)) (message "Draft deleted!")) (message "No drafts to delete."))) @@ -1773,7 +1773,7 @@ Only text that is not one of these faces will be spell-checked." (add-hook 'mastodon-toot-mode-hook (lambda () (setq flyspell-generic-check-word-predicate - 'mastodon-toot-mode-flyspell-verify))) + #'mastodon-toot-mode-flyspell-verify))) ;;;###autoload (add-hook 'mastodon-toot-mode-hook diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 1c5e0d5..af16579 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -224,8 +224,7 @@ Use. e.g. \"%c\" for your locale's date and time format." (defcustom mastodon-mode-hook nil "Hook run when entering Mastodon mode." :type 'hook - :options '(provide-discover-context-menu) - :group 'mastodon) + :options '(provide-discover-context-menu)) (defface mastodon-handle-face '((t :inherit default)) @@ -427,7 +426,6 @@ Calls `mastodon-tl--get-buffer-type', which see." (define-derived-mode mastodon-mode special-mode "Mastodon" "Major mode for Mastodon, the federated microblogging network." - :group 'mastodon (read-only-mode 1)) (provide 'mastodon) -- cgit v1.2.3