From ae3a9bcfb51499cdda854c7ef6cf5f7f1bb4401b Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 28 Apr 2023 15:59:05 +0200 Subject: v rough thread replies chain --- lisp/mastodon-tl.el | 53 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 14 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 92ca02a..e76380f 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -140,7 +140,8 @@ nil." (locked . ("🔒" . "[locked]")) (private . ("🔒" . "[followers]")) (direct . ("✉" . "[direct]")) - (edited . ("✍" . "[edited]"))) + (edited . ("✍" . "[edited]")) + (replied . ("⬇" . "[replied]"))) "A set of symbols (and fallback strings) to be used in timeline. If a symbol does not look right (tofu), it means your font settings do not support it." @@ -1264,8 +1265,20 @@ Runs `mastodon-tl--render-text' and fetches poll or media." (mastodon-tl--get-poll toot)) (mastodon-tl--media toot)))) +(defun mastodon-tl--prev-toot-id () + (let ((prev-pos (1- (save-excursion + (previous-single-property-change + (point) + 'base-toot-id))))) + (get-text-property prev-pos 'base-toot-id))) + +(defun mastodon-tl--after-reply-status (reply-to-id) + "" + (let ((prev-id (mastodon-tl--prev-toot-id))) + (string= reply-to-id prev-id))) + (defun mastodon-tl--insert-status (toot body author-byline action-byline - &optional id base-toot detailed-p) + &optional id base-toot detailed-p thread) "Display the content and byline of timeline element TOOT. BODY will form the section of the toot above the byline. AUTHOR-BYLINE is an optional function for adding the author @@ -1281,13 +1294,21 @@ status is a favourite or boost notification, BASE-TOOT is the JSON of the toot responded to. DETAILED-P means display more detailed info. For now this just means displaying toot client." - (let ((start-pos (point))) + (let* ((start-pos (point)) + (reply-to-id (alist-get 'in_reply_to_id toot)) + (after-reply-status-p + (when (and thread reply-to-id) + (mastodon-tl--after-reply-status reply-to-id)))) (insert (propertize - (concat "\n" - body - " \n" - (mastodon-tl--byline toot author-byline action-byline detailed-p)) + (concat + (if (and after-reply-status-p thread) + (concat (mastodon-tl--symbol 'replied) + "\n") + "") + body + " \n" + (mastodon-tl--byline toot author-byline action-byline detailed-p)) 'toot-id (or id ; notification's own id (alist-get 'id toot)) ; toot id 'base-toot-id (mastodon-tl--toot-id @@ -1363,7 +1384,7 @@ To disable showing the stats, customize (and (null (mastodon-tl--field 'in_reply_to_id toot)) (not (mastodon-tl--field 'rebloged toot)))) -(defun mastodon-tl--toot (toot &optional detailed-p) +(defun mastodon-tl--toot (toot &optional detailed-p thread) "Format TOOT and insert it into the buffer. DETAILED-P means display more detailed info. For now this just means displaying toot client." @@ -1377,12 +1398,14 @@ this just means displaying toot client." 'mastodon-tl--byline-boosted nil nil - detailed-p)) + detailed-p + thread)) -(defun mastodon-tl--timeline (toots) +(defun mastodon-tl--timeline (toots &optional thread) "Display each toot in TOOTS. This function removes replies if user required." - (mapc #'mastodon-tl--toot + (mapc (lambda (toot) + (mastodon-tl--toot toot nil thread)) ;; hack to *not* filter replies on profiles: (if (eq (mastodon-tl--get-buffer-type) 'profile-statuses) toots @@ -1739,12 +1762,14 @@ view all branches of a thread." (mastodon-tl--set-buffer-spec buffer endpoint #'mastodon-tl--thread) - (mastodon-tl--timeline (alist-get 'ancestors context)) + (mastodon-tl--timeline (alist-get 'ancestors context) + :thread) (goto-char (point-max)) (move-marker marker (point)) ;; print re-fetched toot: - (mastodon-tl--toot toot :detailed-p) - (mastodon-tl--timeline (alist-get 'descendants context)) + (mastodon-tl--toot toot :detailed-p :thread) + (mastodon-tl--timeline (alist-get 'descendants context) + :thread) ;; put point at the toot: (goto-char (marker-position marker)) (mastodon-tl--goto-next-toot)))) -- cgit v1.2.3 From 00cb199457d2bd83ed16b296d5c858b291b900c3 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 28 Apr 2023 17:06:47 +0200 Subject: docstrings --- lisp/mastodon-tl.el | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index e76380f..7b979d1 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1266,6 +1266,7 @@ Runs `mastodon-tl--render-text' and fetches poll or media." (mastodon-tl--media toot)))) (defun mastodon-tl--prev-toot-id () + "Return the id of the last toot inserted into the buffer." (let ((prev-pos (1- (save-excursion (previous-single-property-change (point) @@ -1273,7 +1274,7 @@ Runs `mastodon-tl--render-text' and fetches poll or media." (get-text-property prev-pos 'base-toot-id))) (defun mastodon-tl--after-reply-status (reply-to-id) - "" + "T if REPLY-TO-ID is equal to that of the last toot inserted in the bufer." (let ((prev-id (mastodon-tl--prev-toot-id))) (string= reply-to-id prev-id))) @@ -1293,7 +1294,8 @@ attached as a `toot-id' property if provided. If the status is a favourite or boost notification, BASE-TOOT is the JSON of the toot responded to. DETAILED-P means display more detailed info. For now -this just means displaying toot client." +this just means displaying toot client. +THREAD means the status will be displayed in a thread view." (let* ((start-pos (point)) (reply-to-id (alist-get 'in_reply_to_id toot)) (after-reply-status-p @@ -1387,7 +1389,8 @@ To disable showing the stats, customize (defun mastodon-tl--toot (toot &optional detailed-p thread) "Format TOOT and insert it into the buffer. DETAILED-P means display more detailed info. For now -this just means displaying toot client." +this just means displaying toot client. +THREAD means the status will be displayed in a thread view." (mastodon-tl--insert-status toot (mastodon-tl--clean-tabs-and-nl @@ -1403,7 +1406,8 @@ this just means displaying toot client." (defun mastodon-tl--timeline (toots &optional thread) "Display each toot in TOOTS. -This function removes replies if user required." +This function removes replies if user required. +THREAD means the status will be displayed in a thread view." (mapc (lambda (toot) (mastodon-tl--toot toot nil thread)) ;; hack to *not* filter replies on profiles: @@ -1770,7 +1774,7 @@ view all branches of a thread." (mastodon-tl--toot toot :detailed-p :thread) (mastodon-tl--timeline (alist-get 'descendants context) :thread) - ;; put point at the toot: + ;; put point at the toot: (goto-char (marker-position marker)) (mastodon-tl--goto-next-toot)))) ;; else just print the lone toot: @@ -2123,7 +2127,8 @@ PREFIX is sent to `mastodon-tl--show-tag-timeline', which see." (defun mastodon-tl--some-followed-tags-timeline (&optional prefix) "Prompt for some tags, and open a timeline for them. -The suggestions are from followed tags, but any other tags are also allowed." +The suggestions are from followed tags, but any other tags are also allowed. +PREFIX us sent to `mastodon-tl--show-tag-timeline', which see." (interactive "p") (let* ((followed-tags-json (mastodon-tl--followed-tags)) (tags (mastodon-tl--map-alist 'name followed-tags-json)) -- cgit v1.2.3 From b4f463aaed526f637f9bd5d6aa494b9f195272c5 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 28 Apr 2023 17:06:53 +0200 Subject: no quasi-quotes for let-alist dots --- lisp/mastodon-tl.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 7b979d1..4082905 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2206,9 +2206,10 @@ report the account for spam." (defvar crm-separator) (defun mastodon-tl--map-rules-alist (rules) + "Return an alist of the text and id fields of RULES." (mapcar (lambda (x) (let-alist x - `(,.text . ,.id))) + (cons .text .id))) rules)) (defun mastodon-tl--read-rules-ids () -- cgit v1.2.3 From a3b2fcdc726874ff7e3e65db7a8d45f687017e18 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 28 Apr 2023 18:29:56 +0200 Subject: add commented example use of line-prefix prop --- lisp/mastodon-tl.el | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 4082905..ce16f87 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1308,6 +1308,10 @@ THREAD means the status will be displayed in a thread view." (concat (mastodon-tl--symbol 'replied) "\n") "") + ;; (if (and after-reply-status-p thread) + ;; (propertize body + ;; 'line-prefix "|") + ;; body) body " \n" (mastodon-tl--byline toot author-byline action-byline detailed-p)) -- cgit v1.2.3 From 9257595153a2fc9046f571cea3e88fb509936314 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 29 Apr 2023 13:33:10 +0200 Subject: add line-prefix and wrap-prefix, ajust shr render width too --- lisp/mastodon-tl.el | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index ce16f87..249e344 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -141,7 +141,8 @@ nil." (private . ("🔒" . "[followers]")) (direct . ("✉" . "[direct]")) (edited . ("✍" . "[edited]")) - (replied . ("⬇" . "[replied]"))) + (replied . ("⬇" . "↓")) + (reply-bar . ("┃" . "|"))) "A set of symbols (and fallback strings) to be used in timeline. If a symbol does not look right (tofu), it means your font settings do not support it." @@ -750,7 +751,7 @@ links in the text. If TOOT is nil no parsing occurs." (insert string) (let ((shr-use-fonts mastodon-tl--enable-proportional-fonts) (shr-width (when mastodon-tl--enable-proportional-fonts - (- (window-width) 1)))) + (- (window-width) 3)))) (shr-render-region (point-min) (point-max))) ;; Make all links a tab stop recognized by our own logic, make things point ;; to our own logic (e.g. hashtags), and update keymaps where needed: @@ -1308,11 +1309,13 @@ THREAD means the status will be displayed in a thread view." (concat (mastodon-tl--symbol 'replied) "\n") "") - ;; (if (and after-reply-status-p thread) - ;; (propertize body - ;; 'line-prefix "|") - ;; body) - body + (if (and after-reply-status-p thread) + (let ((bar (mastodon-tl--symbol 'reply-bar))) + (propertize body + 'line-prefix bar + 'wrap-prefix bar)) + body) + ;; body " \n" (mastodon-tl--byline toot author-byline action-byline detailed-p)) 'toot-id (or id ; notification's own id -- cgit v1.2.3 From 5e8774d67fff65bd7fd3e9caa4ca887690afcc92 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 30 Apr 2023 11:42:19 +0200 Subject: tl--insert-status: restore initial \n --- lisp/mastodon-tl.el | 1 + 1 file changed, 1 insertion(+) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 249e344..ac15f7b 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1305,6 +1305,7 @@ THREAD means the status will be displayed in a thread view." (insert (propertize (concat + "\n" (if (and after-reply-status-p thread) (concat (mastodon-tl--symbol 'replied) "\n") -- cgit v1.2.3