emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/mastodon c8565612b9 22/63: fold long posts, unfolding cmd.


From: ELPA Syncer
Subject: [nongnu] elpa/mastodon c8565612b9 22/63: fold long posts, unfolding cmd. FIX #572.
Date: Sun, 4 Aug 2024 04:00:31 -0400 (EDT)

branch: elpa/mastodon
commit c8565612b95ce09c1d55470943a52c25798c27a1
Author: marty hiatt <martianhiatus@riseup.net>
Commit: marty hiatt <martianhiatus@riseup.net>

    fold long posts, unfolding cmd. FIX #572.
---
 lisp/mastodon-tl.el | 51 +++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 47 insertions(+), 4 deletions(-)

diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index ac3000539a..d87a469cc2 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -979,6 +979,8 @@ the toot)."
 LINK-TYPE is the type of link to produce."
   (let ((help-text (cond ((eq link-type 'content-warning)
                           "Toggle hidden text")
+                         ((eq link-type 'read-more)
+                          "Toggle full post")
                          (t
                           (error "Unknown link type %s" link-type)))))
     (propertize string
@@ -1020,6 +1022,8 @@ Used for hitting RET on a given link."
                         "Search for account returned nothing. Perform URL 
lookup?")
                        (mastodon-url-lookup (get-text-property position 
'shr-url))
                      (message "Unable to find account."))))))))
+          ((eq link-type 'read-more)
+           (mastodon-tl--unfold-post))
           (t
            (error "Unknown link type %s" link-type)))))
 
@@ -1526,12 +1530,13 @@ When DOMAIN, force inclusion of user's domain in their 
handle."
            (concat (mastodon-tl--symbol 'replied)
                    "\n")
          "")
-       (if (and after-reply-status-p thread)
-           (let ((bar (mastodon-tl--symbol 'reply-bar)))
+       (let ((bar (mastodon-tl--symbol 'reply-bar))
+             (body (mastodon-tl--fold-body-maybe body)))
+         (if (and after-reply-status-p thread)
              (propertize body
                          'line-prefix bar
-                         'wrap-prefix bar))
-         body)
+                         'wrap-prefix bar)
+           body))
        " \n"
        ;; byline:
        (mastodon-tl--byline toot author-byline action-byline detailed-p 
domain))
@@ -1551,6 +1556,44 @@ When DOMAIN, force inclusion of user's domain in their 
handle."
     (when mastodon-tl--display-media-p
       (mastodon-media--inline-images start-pos (point)))))
 
+(defun mastodon-tl--fold-body-maybe (body)
+  "Fold toot BODY if it is very long."
+  (if (length> body 500)
+      (let* ((heading (mastodon-search--format-heading
+                       (mastodon-tl--make-link
+                        "READ MORE"
+                        'read-more)))
+             (display (concat (substring body 0 500)
+                              heading)))
+        (propertize display
+                    'read-more body))
+    body))
+
+(defun mastodon-tl--unfold-post ()
+  "Unfold the toot at point if it is folded (read-more)."
+  (interactive)
+  ;; if at byline, must search backwards:
+  (let* ((byline (mastodon-tl--property 'byline :no-move))
+         (range (mastodon-tl--find-property-range
+                 'read-more (point) byline)))
+    (if (not range)
+        (user-error "No folded item at point?")
+      (let* ((inhibit-read-only t)
+             (body (save-excursion
+                     (goto-char (car range))
+                     (mastodon-tl--property 'read-more))))
+        ;; `replace-region-contents' is much to slow, our hack from fedi.el is
+        ;; much simpler and much faster
+        (let ((beg (car range))
+              (end (cdr range)))
+          (save-excursion
+            (goto-char beg)
+            (delete-region beg end)
+            (insert body))
+          ;; move point to line where text formerly ended:
+          (goto-char end)
+          (beginning-of-line))))))
+
 ;; from mastodon-alt.el:
 (defun mastodon-tl--toot-for-stats (&optional toot)
   "Return the TOOT on which we want to extract stats.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]