aboutsummaryrefslogtreecommitdiffstats
path: root/oni-browse-url.el
diff options
context:
space:
mode:
authorGravatar Tom Willemse2022-12-13 07:09:34 -0800
committerGravatar Tom Willemse2022-12-13 07:09:34 -0800
commit8fb6beda455d535a2982022ef6902f58d129ebd7 (patch)
tree1229d8602923f793743ecf887799f431e23e350a /oni-browse-url.el
parentcd94e63543dc9599febc5892d82fcaeaff4cdc16 (diff)
downloademacs-config-8fb6beda455d535a2982022ef6902f58d129ebd7.tar.gz
emacs-config-8fb6beda455d535a2982022ef6902f58d129ebd7.zip
[oni-browse-url] Open Mastodon URLs with mastodon.el if installed
Diffstat (limited to 'oni-browse-url.el')
-rw-r--r--oni-browse-url.el18
1 files changed, 17 insertions, 1 deletions
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 <tom@ryuslash.org>
;; 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)