aboutsummaryrefslogtreecommitdiff
path: root/lisp
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
parentd1aa39c22b43324751f8400aa303c7d467864665 (diff)
Add `j' and `k' bindings to move to previous/next toot
Diffstat (limited to 'lisp')
-rw-r--r--lisp/mastodon-tl.el47
-rw-r--r--lisp/mastodon.el5
2 files changed, 38 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
diff --git a/lisp/mastodon.el b/lisp/mastodon.el
index edc1d03..3bddf55 100644
--- a/lisp/mastodon.el
+++ b/lisp/mastodon.el
@@ -96,6 +96,8 @@
(let ((map mastodon-mode-map))
(define-key map (kbd "F") #'mastodon-tl--get-federated-timeline)
(define-key map (kbd "H") #'mastodon-tl--get-home-timeline)
+ (define-key map (kbd "j") #'mastodon-tl--goto-next-toot)
+ (define-key map (kbd "k") #'mastodon-tl--goto-prev-toot)
(define-key map (kbd "L") #'mastodon-tl--get-local-timeline)
(define-key map (kbd "n") #'mastodon-toot)
(define-key map (kbd "q") #'kill-this-buffer)
@@ -111,6 +113,9 @@
:context-menu '(mastodon
(description "Mastodon feed viewer")
(actions
+ ("Navigation"
+ ("j" "Go to next toot" mastodon-tl--goto-next-toot)
+ ("k" "Go to previous toot" mastodon-tl--goto-prev-toot))
("Feed switch"
("F" "Open federated timeline" mastodon-tl--get-federated-timeline)
("H" "Open home timeline" mastodon-tl--get-home-timeline)