From 8fb6beda455d535a2982022ef6902f58d129ebd7 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Tue, 13 Dec 2022 07:09:34 -0800 Subject: [PATCH] [oni-browse-url] Open Mastodon URLs with mastodon.el if installed --- oni-browse-url.el | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/oni-browse-url.el b/oni-browse-url.el index 7bd702e..33260d2 100644 --- a/oni-browse-url.el +++ b/oni-browse-url.el @@ -4,7 +4,7 @@ ;; Author: Tom Willemse ;; Keywords: local -;; Version: 2022.0311.230935 +;; Version: 2022.1213.070851 ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by @@ -27,6 +27,8 @@ (require 'browse-url) +(autoload 'mastodon-url-lookup "mastodon") + ;; Ideas: ;; - Split out to different functions for Medium, Twitter, Youtube, etc. ;; - Split the medium one into *.medium.com and also allow arbitrary sites to be added. @@ -73,6 +75,20 @@ before this filter." 'browse-url-default-windows-browser 'browse-url-firefox)) +;; Taken from https://mas.to/@ParetoOptimalDev/109378647927115065 +(defun oni-browse-url-browse-mastodon (url &rest _args) + "Open URL in mastodon." + (mastodon-url-lookup url)) + +(when (package-installed-p 'mastodon) + (add-to-list 'browse-url-handlers + (cons (rx "http" (optional "s") "://" + (minimal-match (one-or-more (not "/"))) + "/@" + (minimal-match (one-or-more (not "/"))) + "/") + #'oni-browse-url-browse-mastodon))) + (advice-add 'browse-url :filter-args #'browse-url-redirect-alternative) (provide 'oni-browse-url)