From: Alex Schroeder Date: Sat, 11 Sep 2021 20:38:55 +0000 (+0200) Subject: Maybe skip advice of browse-url-browser-function X-Git-Tag: v3.3.0~7 X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=fbf5fbcd3e0d82c9d7de7d4db5166620dbb31791;p=elpher.git Maybe skip advice of browse-url-browser-function If the value of browse-url-browser-function is an alist instead of a symbol, we're probably better off not advising it. Thus, check the value of browse-url-browser-function before doing anything. Only advise it if it is a function, i.e. fboundp. --- diff --git a/elpher.el b/elpher.el index 7df595d..6bb36b3 100644 --- a/elpher.el +++ b/elpher.el @@ -2104,17 +2104,19 @@ supports the old protocol elpher, where the link is self-contained." '("^\\(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))))) + ;; that's the function that gets advised. If the value is an alist, + ;; however, we don't know what to do. Better not interfere? + (when (fboundp browse-url-browser-function) + (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