Merge remote-tracking branch 'upstream/patch_integrate_with_browse_url' into main
authorAlex Schroeder <alex@gnu.org>
Sun, 27 Jun 2021 19:44:02 +0000 (21:44 +0200)
committerAlex Schroeder <alex@gnu.org>
Sun, 27 Jun 2021 19:44:02 +0000 (21:44 +0200)
1  2 
elpher.el

diff --cc elpher.el
+++ b/elpher.el
@@@ -1703,35 -1666,18 +1703,47 @@@ If ADDRESS is already bookmarked, updat
  ;;; Integrations
  ;;
  
 +(defun elpher-org-link-store ()
 +  "Store link to an `elpher' page in org-mode."
 +  (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))))
 +
 +(with-eval-after-load "org"
 +  ;; Use `org-link-set-parameters' if defined (org-mode 9+)
 +  (if (fboundp 'org-link-set-parameters)
 +      (org-link-set-parameters "elpher"
 +                               :store #'elpher-org-link-store
 +                               :follow #'elpher-org-link-follow)
 +    (org-add-link-type "mu4e" 'elpher-org-link-follow)
 +    (add-hook 'org-store-link-functions 'elpher-org-link-store)))
 +
+ (defun browse-url-elpher (url &rest _args)
+   "Browse URL. This function is used by `browse-url'."
+   (interactive (browse-url-interactive-arg "Elpher URL: "))
+   (elpher-go url))
+ (with-eval-after-load "browse-url"
+   ;; Use elpher to open gopher, finger and gemini links
+   (add-to-list 'browse-url-default-handlers
+                '("^\\(gopher\\|finger\\|gemini\\)://" . browse-url-elpher))
+   ;; Register "gemini://" as a URI scheme so `browse-url' does the right thing
+   (add-to-list 'thing-at-point-uri-schemes "gemini://"))
  ;;; Interactive procedures
  ;;