Store and follow elpher links in org-mode
authorJens Östlund <jostlund@gmail.com>
Sat, 8 May 2021 18:42:20 +0000 (20:42 +0200)
committerJens Östlund <jostlund@gmail.com>
Sat, 8 May 2021 18:42:20 +0000 (20:42 +0200)
Store an elpher page org link by executing `org-store-link` and follow
an elpher link within an org-mode buffer by executing
`org-open-at-point`.

Supports gopher, gemini and finger links.

elpher.el

index 4c34f52..21aa9d0 100644 (file)
--- a/elpher.el
+++ b/elpher.el
@@ -1663,6 +1663,38 @@ If ADDRESS is already bookmarked, update the label only."
                    (not (equal (elpher-bookmark-url bookmark) url)))
                  (elpher-load-bookmarks)))))
 
+;;; 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)))
+
 ;;; Interactive procedures
 ;;