-(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'."
+(defun elpher-org-follow-link (link protocol)
+ "Visit a LINK for the given PROTOCOL.
+
+PROTOCOL may be one of gemini, gopher or finger. This method also support old
+paramter elpher, where link is self-contained."
+ (let ((url (if (equal protocol "elpher")
+ (string-remove-prefix "elpher:" link)
+ (format "%s:%s" protocol link))))
+ (elpher-go url)))
+
+;; Avoid byte compilation warnings.
+(declare-function org-link-set-parameters "ol")
+(with-eval-after-load 'org
+ (org-link-set-parameters
+ "elpher"
+ :store #'elpher-org-store-link
+ :export (lambda (link description format _plist)
+ (elpher-org-export-link link description format "elpher"))
+ :follow (lambda (link _arg) (elpher-org-follow-link link "elpher")))
+ (org-link-set-parameters
+ "gemini"
+ :export (lambda (link description format _plist)
+ (elpher-org-export-link link description format "gemini"))
+ :follow (lambda (link _arg) (elpher-org-follow-link link "gemini")))
+ (org-link-set-parameters
+ "gopher"
+ :export (lambda (link description format _plist)
+ (elpher-org-export-link link description format "gopher"))
+ :follow (lambda (link _arg) (elpher-org-follow-link link "gopher")))
+ (org-link-set-parameters
+ "finger"
+ :export (lambda (link description format _plist)
+ (elpher-org-export-link link description format "finger"))
+ :follow (lambda (link _arg) (elpher-org-follow-link link "finger"))))
+
+;;;###autoload
+(defun elpher-browse-url-elpher (url &rest _args)
+ "Browse URL using Elpher. This function is used by `browse-url'."