+;;; Integrations
+;;
+
+;; Avoid byte compilation warnings.
+(eval-when-compile
+ (declare-function org-link-store-props "ol")
+ (declare-function org-link-set-parameters "ol"))
+
+(defun elpher-org-link-store ()
+ "Store link to an `elpher' page in `org'."
+ (when (eq major-mode 'elpher-mode)
+ (let ((link (concat "elpher:" (elpher-info-current)))
+ (desc (car elpher-current-page)))
+ (org-link-store-props :type "elpher"
+ :link link
+ :description desc)
+ t)))
+
+(defun elpher-org-link-follow (link _args)
+ "Follow an `elpher' LINK in an `org' buffer."
+ (require 'elpher)
+ (message (concat "Got link: " link))
+ (when (or
+ (string-match-p "^gemini://.+" link)
+ (string-match-p "^gopher://.+" link)
+ (string-match-p "^finger://.+" link))
+ (elpher-go (string-remove-prefix "elpher:" link))))
+
+(org-link-set-parameters "elpher"
+ :store #'elpher-org-link-store
+ :follow #'elpher-org-link-follow)
+
+;;;###autoload
+(defun elpher-browse-url-elpher (url &rest _args)
+ "Browse URL using Elpher. This function is used by `browse-url'."
+ (interactive (browse-url-interactive-arg "Elpher URL: "))
+ (elpher-go url))
+
+(add-to-list
+ 'browse-url-default-handlers
+ '("^\\(gopher\\|finger\\|gemini\\)://" . elpher-browse-url-elpher))
+
+;; Register "gemini://" as a URI scheme so `browse-url' does the right thing
+(with-eval-after-load 'thingatpt
+ (add-to-list 'thing-at-point-uri-schemes "gemini://"))
+