X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?p=elpher.git;a=blobdiff_plain;f=elpher.el;h=f94b33f22c3b42cf6d3540da8a20ce60a2752872;hp=d9046bc730f8ac90afc8446fc506746eab2619df;hb=e3fca3512d458c4a78ef9b3d87b66e952f2b5f94;hpb=a1cc1dd30edbe9629619793ed9e84410fb67e9a5 diff --git a/elpher.el b/elpher.el index d9046bc..f94b33f 100644 --- a/elpher.el +++ b/elpher.el @@ -156,7 +156,7 @@ (defcustom elpher-open-urls-with-eww nil "If non-nil, open URL selectors using eww. -Otherwise, use the system browser via the BROWSE-URL function." +Otherwise, use the system browser via the `browse-url' function." :type '(boolean)) (defcustom elpher-use-header t @@ -1827,8 +1827,8 @@ of gemini, gopher or finger." (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." +PROTOCOL may be one of gemini, gopher or finger. This method also +supports the old protocol elpher, where the link is self-contained." (let ((url (if (equal protocol "elpher") (string-remove-prefix "elpher:" link) (format "%s:%s" protocol link)))) @@ -1870,22 +1870,24 @@ paramter elpher, where link is self-contained." (elpher-go url)) ;; Use elpher to open gopher, finger and gemini links -(with-eval-after-load 'browse-url - ;; For recent version of `browse-url' package - (if (boundp 'browse-url-default-handlers) - (add-to-list - 'browse-url-default-handlers - '("^\\(gopher\\|finger\\|gemini\\)://" . elpher-browse-url-elpher)) - ;; Patch browse-url-default-browser for older ones - (advice-add 'browse-url-default-browser :before-while - (lambda (url &rest _args) - (let ((scheme (downcase (car (split-string url ":" t))))) - (if (member scheme '("gemini" "gopher" "finger")) - ;; `elpher-go' always returns nil, which will stop the - ;; advice chain here in a before-while - (elpher-go url) - ;; chain must continue, then return t. - t)))))) +;; For recent version of `browse-url' package +(if (boundp 'browse-url-default-handlers) + (add-to-list + 'browse-url-default-handlers + '("^\\(gopher\\|finger\\|gemini\\)://" . elpher-browse-url-elpher)) + ;; Patch `browse-url-browser-function' for older ones. The value of + ;; that variable is `browse-url-default-browser' by default, so + ;; that's the function that gets advised. + (advice-add browse-url-browser-function :before-while + (lambda (url &rest _args) + "Handle gemini, gopher, and finger schemes using Elpher." + (let ((scheme (downcase (car (split-string url ":" t))))) + (if (member scheme '("gemini" "gopher" "finger")) + ;; `elpher-go' always returns nil, which will stop the + ;; advice chain here in a before-while + (elpher-go url) + ;; chain must continue, then return t. + t))))) ;; Register "gemini://" as a URI scheme so `browse-url' does the right thing (with-eval-after-load 'thingatpt