diff options
author | marty hiatt <martianhiatus@riseup.net> | 2024-08-06 17:53:47 +0200 |
---|---|---|
committer | marty hiatt <martianhiatus@riseup.net> | 2024-08-06 17:53:47 +0200 |
commit | 994b4e9a938d17d35462a8da3929fea267563c70 (patch) | |
tree | ad8e7d6365f1210229ad582a30987d11cb4f24e6 /lisp | |
parent | 20d0f4ae848a2b8bc3bf8a63c409871d0e7991ff (diff) |
re-write all (if x y "") clauses as (when x y), if poss.
we can use when inside concat, but not inside insert, nor in strings/args headed for
format or propertize.
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/mastodon-media.el | 5 | ||||
-rw-r--r-- | lisp/mastodon-notifications.el | 9 | ||||
-rw-r--r-- | lisp/mastodon-profile.el | 14 | ||||
-rw-r--r-- | lisp/mastodon-search.el | 7 | ||||
-rw-r--r-- | lisp/mastodon-tl.el | 59 | ||||
-rw-r--r-- | lisp/mastodon-toot.el | 10 |
6 files changed, 47 insertions, 57 deletions
diff --git a/lisp/mastodon-media.el b/lisp/mastodon-media.el index 9dc8517..8f8937c 100644 --- a/lisp/mastodon-media.el +++ b/lisp/mastodon-media.el @@ -500,9 +500,8 @@ SENSITIVE is a flag from the item's JSON data." (substitute-command-keys (concat "\\`RET'/\\`i': load full image (prefix: copy URL), \\`+'/\\`-': zoom,\ \\`r': rotate, \\`o': save preview" - (if (not (eq sensitive :json-false)) - ", \\`S': toggle sensitive media" - "")))) + (when (not (eq sensitive :json-false)) + ", \\`S': toggle sensitive media")))) (help-echo (if caption (concat help-echo-base "\n\"" caption "\"") diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index eca520b..070d23f 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -243,11 +243,10 @@ Status notifications are given when (format "You have a follow request from... %s" follower) 'face 'default) - (if mastodon-notifications--profile-note-in-foll-reqs - (concat - ":\n" - (mastodon-notifications--comment-note-text body)) - "")))) + (when mastodon-notifications--profile-note-in-foll-reqs + (concat + ":\n" + (mastodon-notifications--comment-note-text body)))))) ((or (eq type 'favourite) (eq type 'boost)) (mastodon-notifications--comment-note-text body)) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 8249641..0a17a25 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -681,18 +681,16 @@ MAX-ID is a flag to include the max_id pagination parameter." (mastodon-profile--render-roles .roles))) "\n" (propertize (concat "@" .acct) 'face 'default) - (if (eq .locked t) - (concat " " (mastodon-tl--symbol 'locked)) - "") + (when (eq .locked t) + (concat " " (mastodon-tl--symbol 'locked))) "\n " mastodon-tl--horiz-bar "\n" ;; profile note: (mastodon-tl--render-text .note account) ; account = tab-stops in profile ;; meta fields: - (if fields - (concat "\n" (mastodon-tl--set-face - (mastodon-profile--fields-insert fields) - 'success)) - "") + (when fields + (concat "\n" (mastodon-tl--set-face + (mastodon-profile--fields-insert fields) + 'success))) "\n" ;; Joined date: (propertize diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index 00681c6..b54e8f3 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -134,7 +134,7 @@ Optionally add string TYPE after HEADING." (mastodon-tl--set-face (concat "\n " mastodon-tl--horiz-bar "\n " (upcase str) " " - (if type (upcase type) "") "\n" + (when type (upcase type)) "\n" " " mastodon-tl--horiz-bar (unless no-newline "\n")) 'success)) @@ -266,9 +266,8 @@ If NOTE is non-nil, include user's profile note. This is also 'mastodon-handle (concat "@" (cadr user)) 'help-echo (concat "Browse user profile of @" (cadr user))) " : \n" - (if note - (mastodon-tl--render-text (cadddr user) acct) - "") + (when note + (mastodon-tl--render-text (cadddr user) acct)) "\n") 'item-json acct))) ; for compat w other processing functions diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 5e56dc3..6607bbd 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -614,11 +614,10 @@ When DOMAIN, force inclusion of user's domain in their handle." ;; handle: " (" (propertize (concat "@" .account.acct - (if domain - (concat "@" - (url-host - (url-generic-parse-url .account.url))) - "")) + (when domain + (concat "@" + (url-host + (url-generic-parse-url .account.url))))) 'face 'mastodon-handle-face 'mouse-face 'highlight 'mastodon-tab-stop 'user-handle @@ -788,26 +787,24 @@ When DOMAIN, force inclusion of user's domain in their handle." 'shr-url app-url 'help-echo app-url 'keymap mastodon-tl--shr-map-replacement))))) - (if edited-time - (concat - " " - (mastodon-tl--symbol 'edited) - " " - (propertize - (format-time-string mastodon-toot-timestamp-format - edited-parsed) - 'face 'font-lock-comment-face - 'timestamp edited-parsed - 'display (if mastodon-tl--enable-relative-timestamps - (mastodon-tl--relative-time-description edited-parsed) - edited-parsed))) - "") + (when edited-time + (concat + " " + (mastodon-tl--symbol 'edited) + " " + (propertize + (format-time-string mastodon-toot-timestamp-format + edited-parsed) + 'face 'font-lock-comment-face + 'timestamp edited-parsed + 'display (if mastodon-tl--enable-relative-timestamps + (mastodon-tl--relative-time-description edited-parsed) + edited-parsed)))) (propertize (concat "\n " mastodon-tl--horiz-bar) 'face 'default) - (if (and mastodon-tl--show-stats - (not (member type '("follow" "follow_request")))) - (mastodon-tl--toot-stats toot) - "") + (when (and mastodon-tl--show-stats + (not (member type '("follow" "follow_request")))) + (mastodon-tl--toot-stats toot)) "\n") 'favourited-p faved 'boosted-p boosted @@ -1149,7 +1146,8 @@ message is a link which unhides/hides the main body." ;;; MEDIA (defun mastodon-tl--media (toot) - "Retrieve a media attachment link for TOOT if one exists." + "Retrieve a media attachment link for TOOT if one exists. +Else return an empty string." (let* ((media-attachments (mastodon-tl--field 'media_attachments toot)) (sensitive (mastodon-tl--field 'sensitive toot)) (media-string (mapconcat @@ -1291,8 +1289,7 @@ LENGTH is of the longest option, for formatting." (format "%s people | " .voters_count))) (.vote_count (format "%s votes | " .vote_count)) - (t - "")) + (t "")) 'face 'font-lock-comment-face) (let ((str (if (eq .expired :json-false) (if (eq .expires_at nil) @@ -1547,10 +1544,9 @@ NO-BYLINE means just insert toot body, used for folding." (concat "\n" ;; relpy symbol (broken): - (if (and after-reply-status-p thread) - (concat (mastodon-tl--symbol 'replied) - "\n") - "") + (when (and after-reply-status-p thread) + (concat (mastodon-tl--symbol 'replied) + "\n")) ;; actual body: (let ((bar (mastodon-tl--symbol 'reply-bar)) (body (if (and toot-foldable (not unfolded)) @@ -1564,8 +1560,7 @@ NO-BYLINE means just insert toot body, used for folding." 'toot-body t) ;; includes newlines etc. for folding ;; byline: "\n" - (if no-byline - "" + (unless no-byline (mastodon-tl--byline toot author-byline action-byline detailed-p domain base-toot))) 'item-type 'toot diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index ae88d68..2232cc8 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -1659,11 +1659,10 @@ REPLY-TEXT is the text of the toot being replied to." (propertize "None " 'toot-attachments t) "\n" - (if reply-text - (propertize - (mastodon-toot--format-reply-in-compose reply-text) - 'toot-reply t) - "") + (when reply-text + (propertize + (mastodon-toot--format-reply-in-compose reply-text) + 'toot-reply t)) divider) 'face 'mastodon-toot-docs-face 'read-only "Edit your message below." @@ -1757,6 +1756,7 @@ REPLY-REGION is a string to be injected into the buffer." (if (equal "private" mastodon-toot--visibility) "followers-only" mastodon-toot--visibility))) + ;; WHEN clauses don't work here, we need "" as display arg: (mastodon-toot--apply-fields-props lang-region (if mastodon-toot--language |