aboutsummaryrefslogtreecommitdiff
path: root/lisp/mastodon-tl.el
diff options
context:
space:
mode:
authorJohnson Denen <johnson.denen@gmail.com>2017-04-15 01:07:58 -0400
committerJohnson Denen <johnson.denen@gmail.com>2017-04-15 21:30:48 -0400
commitfe32d705777928c1d7f54f5eee30fbca4500b619 (patch)
treeea228ef7a5919f079252e7a89d9a1a3e2c9089dd /lisp/mastodon-tl.el
parentd1aa39c22b43324751f8400aa303c7d467864665 (diff)
Add `j' and `k' bindings to move to previous/next toot
Diffstat (limited to 'lisp/mastodon-tl.el')
-rw-r--r--lisp/mastodon-tl.el47
1 files changed, 33 insertions, 14 deletions
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index 19e6cd8..10a7ed7 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -67,15 +67,31 @@
"Return value for KEY in TOOT."
(cdr (assoc key toot)))
-(defun mastodon-tl--render-display-name (name)
- (insert
- (propertize (concat name " ")
- 'face 'mastodon-tl-toot-display-name-face)))
+(defun mastodon-tl--goto-toot-pos (find-pos &optional pos)
+ (let* ((npos (funcall find-pos
+ (or pos (point))
+ 'toot-id
+ (current-buffer))))
+ (when npos (if (not (get-text-property npos 'toot-id))
+ (mastodon-tl--goto-toot-pos find-pos npos)
+ (when npos (goto-char npos))))))
+
+(defun mastodon-tl--goto-next-toot ()
+ (interactive)
+ (mastodon-tl--goto-toot-pos 'next-single-property-change))
+
+(defun mastodon-tl--goto-prev-toot ()
+ (interactive)
+ (mastodon-tl--goto-toot-pos 'previous-single-property-change))
-(defun mastodon-tl--render-header (handle name id url)
- (insert "=== ")
- (mastodon-tl--render-display-name name)
- (insert (concat "@" handle "\n")))
+(defun mastodon-tl--header (handle name id)
+ (propertize
+ (concat "=== "
+ (propertize name 'face 'mastodon-tl-toot-display-name-face)
+ " @"
+ handle
+ "\n")
+ 'toot-id id))
(defun mastodon-tl--remove-html (toot)
(let* ((t1 (replace-regexp-in-string "<\/p>" "\n\n" toot))
@@ -83,12 +99,10 @@
(t3 (replace-regexp-in-string "<span class=\"h-card\">" "" t2)))
t3))
-(defun mastodon-tl--render-content (toot)
+(defun mastodon-tl--content (toot)
(let* ((content (mastodon-tl--remove-html toot)))
- (insert
(propertize content
- 'face 'mastodon-tl-toot-text-face))
- (insert "\n")))
+ 'face 'mastodon-tl-toot-text-face)))
(defun mastodon-tl--render-toot (toot)
(let ((id (number-to-string (mastodon-tl--from-toot 'id toot)))
@@ -96,8 +110,13 @@
(name (mastodon-tl--from-toot 'display_name (mastodon-tl--from-toot 'account toot)))
(text (mastodon-tl--from-toot 'content toot))
(url (mastodon-tl--from-toot 'url toot)))
- (mastodon-tl--render-header handle name id url)
- (mastodon-tl--render-content text)))
+ (insert
+ (propertize
+ (concat
+ (mastodon-tl--header handle name id)
+ (mastodon-tl--content text)
+ "\n")
+ 'toot-url url))))
(defun mastodon-tl--render-timeline (buffer json)
(with-output-to-temp-buffer buffer