From cb985db2f37eabd76b9c2643387b4e94009b3f88 Mon Sep 17 00:00:00 2001 From: fap Date: Fri, 14 Apr 2017 23:57:38 +0200 Subject: Fixes #29 - Provide context menu for discover mode * provides a `discover.el` context menu through mode-hook * moves lambdas from keymap to functions so `discover-my-major` can pick them up --- lisp/mastodon.el | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) (limited to 'lisp/mastodon.el') 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 -- cgit v1.2.3