aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarty hiatt <martianhiatus@disroot.org>2024-11-02 15:37:32 +0100
committermarty hiatt <martianhiatus@disroot.org>2024-11-02 15:37:32 +0100
commitebab9b20a161d2ac1cb083f2d39de3bc1cda5faa (patch)
treeb5b4ce4ccba0af2c5a669b8fb8982b933729ecc5
parent7af46336f2dd2ed17b3aba7b0c58b029b49767cc (diff)
refactor a read-more-or-less heading
-rw-r--r--lisp/mastodon-tl.el30
1 files changed, 18 insertions, 12 deletions
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index 87fd710..51abb6e 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -1699,11 +1699,8 @@ NO-BYLINE means just insert toot body, used for folding."
'wrap-prefix bar)
body))
(if (and toot-foldable unfolded cw-expanded)
- (propertize (mastodon-search--format-heading
- (mastodon-tl--make-link "READ LESS" 'read-less)
- nil :no-newline)
- 'mastodon-content-warning-body cw-p
- 'invisible (not cw-expanded))
+ (mastodon-tl--read-more-or-less
+ "LESS" cw-p (not cw-expanded))
""))
'toot-body t) ;; includes newlines etc. for folding
;; byline:
@@ -1817,17 +1814,26 @@ NO-BYLINE means just insert toot body, used for folding."
;;; FOLDING
+(defun mastodon-tl--read-more-or-less (str cw invis)
+ "Return a read more or read less heading.
+The heading is a link to toggle the fold status of the toot.
+CW and INVIS are boolean values for the properties invisible and
+mastodon-content-warning-body."
+ (let ((type (if (string= str "MORE") 'read-more 'read-less)))
+ (propertize
+ (mastodon-search--format-heading
+ (mastodon-tl--make-link (format "READ %s" str) type)
+ nil :no-newline)
+ 'mastodon-content-warning-body cw
+ 'invisible invis)))
+
(defun mastodon-tl--fold-body (body)
"Fold toot BODY if it is very long.
Folding decided by `mastodon-tl--fold-toots-at-length'."
(let* ((invis (get-text-property (1- (length body)) 'invisible body))
- (spoiler (get-text-property (1- (length body))
- 'mastodon-content-warning-body body))
- (heading (propertize (mastodon-search--format-heading
- (mastodon-tl--make-link "READ MORE" 'read-more)
- nil :no-newline)
- 'mastodon-content-warning-body spoiler
- 'invisible invis))
+ (cw (get-text-property (1- (length body))
+ 'mastodon-content-warning-body body))
+ (heading (mastodon-tl--read-more-or-less "MORE" cw invis))
(display (concat (substring body 0
mastodon-tl--fold-toots-at-length)
heading)))