complete-computing-environment/mastodon-emacs.org

3.6 KiB

Mastodon in Emacs

Let's see if this doesn't annoy me. I'm not huge excited about any Mastodon client though.

(use-package request)
(use-package mastodon
  :config
  (require 'mastodon-async)
  <<list-timelines>>
  <<setup-frame>>
  :hook
  (mastodon-mode . visual-line-mode)
  :custom
  (mastodon-tl--show-avatars t)
  (mastodon-instance-url "https://tenforward.social")
  (mastodon-active-user "rrix"))
(provide 'cce/mastodon)

here's a package override for my Emacs home-manager installation which uses a more-up-to-date fork:

mastodon = epkgs.melpaPackages.mastodon.overrideAttrs(old: {
  src = pkgs.callPackage pkgs.lib.pkgVersions.mastodon {};
  propagatedBuildInputs = old.buildInputs ++ [epkgs.request epkgs.persist];
});

List Timelines in Mastodon.el

This uses the Mastodon.el API to fetch the lists, select one, and display it in a buffer.

(defun mastodon-tl--show-list-timeline (&optional list-name)
  (interactive)
  (let* ((options
          (cl-mapcar (lambda (car)
                       (cons (alist-get 'title car)
                             (alist-get 'id car)))
                     (mastodon-http--get-json (mastodon-http--api (format "lists")))))
         (chosen-name (or list-name
                          (completing-read
                           "Which list?"
                           (cl-mapcar #'car options))))
         (chosen-id (alist-get chosen-name options nil nil #'equal)))
    (mastodon-tl--init
     (concat "list-" chosen-name) (concat "timelines/list/" chosen-id) 'mastodon-tl--timeline)))

Configure an Mastodon.el frame

And this configures a frame with my favorite buffers; i wish there was a cleaner way to do this, but alas. I have some scriplets in Emacs Helper Scripts to invoke this from KRunner/WM.

(defun cce/my-mastodon.el-buffers ()
  (interactive)
  (mastodon-tl--show-list-timeline "folks")
  (mastodon-notifications--get)
  (mastodon-tl--get-home-timeline)
  (mastodon-tl--show-list-timeline "neatbots")
  (mastodon-tl--show-list-timeline "Guppies")
  (mastodon-tl--show-tag-timeline "emacs")
  (mastodon-tl--show-tag-timeline "orgmode")
  (mastodon-tl--show-tag-timeline "gunpla")

  (sit-for 5)
  (cce/setup-mastodon-buffers))


(defun cce/setup-mastodon-buffers ()
  (interactive)
  (delete-other-windows)

  (let ((actions                        ; list of buffer names
         '("*mastodon-notifications*"
           "*mastodon-list-folks*"
           "*mastodon-home*"
           "*mastodon-list-neatbots*"
           "*mastodon-list-Guppies*"
           "*mastodon-tag-orgmode*"
           "*mastodon-tag-emacs*"
           "*mastodon-tag-gunpla*"))
        (display-buffer-alist '(("\*mastodon.*" (display-buffer-same-window)))))
    (dotimes (i (- (length actions) 1))
      (split-window-right)
      (balance-windows))
    (dolist (buffer actions)
      (display-buffer buffer)
      (other-window 1))))

NEXT upstream this.