From: Étienne Deparis Date: Wed, 30 Jun 2021 07:54:02 +0000 (+0200) Subject: Fix browse-url for not up-to-date Emacs version X-Git-Tag: v3.0.0~22^2~13 X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=f4e62a878412258f1f84c2115f6af90d4f8a9963;p=elpher.git Fix browse-url for not up-to-date Emacs version On archlinux, even with Emacs 27.2, browse-url package still does not have browse-url-default-handlers variable. --- diff --git a/elpher.el b/elpher.el index c003248..867868e 100644 --- a/elpher.el +++ b/elpher.el @@ -1857,9 +1857,21 @@ paramter elpher, where link is self-contained." ;; Use elpher to open gopher, finger and gemini links (with-eval-after-load 'browse-url - (add-to-list - 'browse-url-default-handlers - '("^\\(gopher\\|finger\\|gemini\\)://" . elpher-browse-url-elpher))) + ;; 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)))))) ;; Avoid byte compilation warnings. (eval-when-compile