aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.org10
-rw-r--r--lisp/mastodon-tl.el21
-rw-r--r--lisp/mastodon.el40
3 files changed, 65 insertions, 6 deletions
diff --git a/README.org b/README.org
index a1d9ba5..82e5267 100644
--- a/README.org
+++ b/README.org
@@ -19,6 +19,14 @@ Then, require it and go.
I'll make mastdon.el available on MELPA when I feel like it's reached a
stable state.
+Mastodon mode provides a overview of it's shortcuts through [[https://github.com/mickeynp/discover.el][Discover mode]].
+To activate Discover mode locally for Mastodon mode buffers add this to your emacs configuration:
+#+BEGIN_SRC emacs-lisp
+ (add-hook 'mastodon-mode-hook 'discover-mode-turn-on)
+#+END_SRC
+
+The context menu is then activated by pressing '?'.
+
** Usage
*** Instance
@@ -55,6 +63,8 @@ Opens a =*mastodon-home*= buffer in the major mode so you can see toots. Keybind
| =T= | Prompt for tag and open its timeline |
|-----+------------------------------------------|
+
+
*** Toot toot
=M-x mastodon-toot=
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index 2d2a588..19e6cd8 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -42,6 +42,27 @@
'((t (:foreground "cyan")))
"Mastodon user handle face.")
+(defun mastodon-tl--get-federated-timeline ()
+ "Opens federated timeline."
+ (interactive)
+ (mastodon-tl--get "public"))
+
+(defun mastodon-tl--get-home-timeline ()
+ "Opens home timeline."
+ (interactive)
+ (mastodon-tl--get "home"))
+
+(defun mastodon-tl--get-local-timeline ()
+ "Opens local timeline."
+ (interactive)
+ (mastodon-tl--get "public?local=true"))
+
+(defun mastodon-tl--get-tag-timeline ()
+ "Prompts for tag and opens its timeline."
+ (interactive)
+ (let ((tag (read-string "Tag: ")))
+ (mastodon-tl--get (concat "tag/" tag))))
+
(defun mastodon-tl--from-toot (key toot)
"Return value for KEY in TOOT."
(cdr (assoc key toot)))
diff --git a/lisp/mastodon.el b/lisp/mastodon.el
index 5fd069d..8511d9e 100644
--- a/lisp/mastodon.el
+++ b/lisp/mastodon.el
@@ -53,6 +53,12 @@
(defvar mastodon--api-version "v1")
+(defcustom mastodon-mode-hook nil
+ "Hook run when entering Mastodon mode."
+ :type 'hook
+ :options '(provide-discover-context-menu)
+ :group 'mastodon)
+
;; FIXME #25
(defun mastodon-version ()
"Message package version."
@@ -88,15 +94,37 @@
"Major mode for Mastodon, the federated microblogging network."
:group 'mastodon
(let ((map mastodon-mode-map))
- (define-key map (kbd "F") (lambda () (interactive) (mastodon-tl--get "public")))
- (define-key map (kbd "H") (lambda () (interactive) (mastodon-tl--get "home")))
- (define-key map (kbd "L") (lambda () (interactive) (mastodon-tl--get "public?local=true")))
+ (define-key map (kbd "F") #'mastodon-tl--get-federated-timeline)
+ (define-key map (kbd "H") #'mastodon-tl--get-home-timeline)
+ (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)
(define-key map (kbd "Q") #'kill-buffer-and-window)
- (define-key map (kbd "T") (lambda () (interactive)
- (let ((tag (read-string "Tag: ")))
- (mastodon-tl--get (concat "tag/" tag)))))))
+ (define-key map (kbd "T") #'mastodon-tl--get-tag-timeline)))
+
+(defun provide-discover-context-menu ()
+ "Provides a shortcut overview through Discover mode.
+Press '?' to activate it."
+ (when (bound-and-true-p discover-mode)
+ (discover-add-context-menu
+ :bind "?"
+ :mode 'mastodon-mode
+ :mode-hook 'mastodon-mode-hook
+ :context-menu '(mastodon
+ (description "Mastodon feed viewer")
+ (actions
+ ("Feed switch"
+ ("F" "Open federated timeline" mastodon-tl--get-federated-timeline)
+ ("H" "Open home timeline" mastodon-tl--get-home-timeline)
+ ("L" "Open local timeline" mastodon-tl--get-local-timeline)
+ ("T" "Prompt for tag and open its timeline" mastodon-tl--get-tag-timeline))
+ ("Toot"
+ ("n" "Switch to 'mastodon-toot' buffer" mastodon-toot))
+ ("Quit"
+ ("q" "Quit mastodon buffer. Leave window open." kill-this-buffer)
+ ("Q" "Quit mastodon buffer and kill window." kill-buffer-and-window)))))))
+
+(add-hook 'mastodon-mode-hook 'provide-discover-context-menu t)
(provide 'mastodon)
;;; mastodon.el ends here