emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/engine-mode d99f9b4ab2 63/71: Prevent browse-url-browser-f


From: ELPA Syncer
Subject: [nongnu] elpa/engine-mode d99f9b4ab2 63/71: Prevent browse-url-browser-function shadowing
Date: Wed, 21 Dec 2022 09:59:17 -0500 (EST)

branch: elpa/engine-mode
commit d99f9b4ab266b2b777f3f323f766687970456fa9
Author: Harry R. Schwartz <hello@harryrschwartz.com>
Commit: Harry R. Schwartz <hello@harryrschwartz.com>

    Prevent browse-url-browser-function shadowing
    
    Engines, by default, use the built-in `browse-url-browser-function` to 
decide
    which browser to open for a given search. However, if that function has been
    locally bound to another browser function, it'll use that new function 
instead!
    That's not the intended behavior.
    
    For example, suppose a user defines an engine to search Wikipedia using 
their
    default browser, then tries to invoke it from within an `eww` buffer. They'd
    *expect* their default browser to open, but instead, because `eww` locally
    overwrites `browse-url-browser-function`, their search will be opened in 
`eww`!
    
    This explicitly binds the `engine/browser-function` to
    `browse-url-browser-function`. That ensures that the default browser will 
be set
    at macro-expansion, so future redefinitions of `browse-url-browser-function`
    shouldn't affect engines.
    
    This is technically a breaking change, since users might expect that 
redefining
    `browse-url-browser-function` after defining engines would cause those 
engines
    to use the new default browser. The documentation doesn't *explicitly* 
promise
    that, though, and I tend to think this implementation is slightly less
    surprising.
    
    Users who *do* want to change the default browser on a mode-by-mode basis 
should
    still be able to do so by defining a hook:
    
        (add-hook 'my-favorite-mode-hook
                  (lambda () (setq engine/browser-function 
'my-favorite-browsing-function)))
    
    Fixes #40.
---
 engine-mode.el | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/engine-mode.el b/engine-mode.el
index 8e2a0e4d15..34b7346187 100644
--- a/engine-mode.el
+++ b/engine-mode.el
@@ -1,7 +1,7 @@
 ;;; engine-mode.el --- Define and query search engines from within Emacs.
 
 ;; Author: Harry R. Schwartz <hello@harryrschwartz.com>
-;; Version: 2.1.2
+;; Version: 2.2.0
 ;; URL: https://github.com/hrs/engine-mode
 ;; Package-Requires: ((cl-lib "0.5"))
 
@@ -82,9 +82,9 @@ For example, to use \"C-c s\" instead of the default \"C-x 
/\":
   (define-key engine-mode-map (kbd engine/keybinding-prefix) nil)
   (define-key engine-mode-map prefix-key engine-mode-prefixed-map))
 
-(defcustom engine/browser-function nil
+(defcustom engine/browser-function browse-url-browser-function
   "The default browser function used when opening a URL in an engine.
-Defaults to `nil' which means to go with `browse-url-browser-function'."
+Defaults to `browse-url-browser-function'."
   :group 'engine-mode
   :type 'symbol)
 
@@ -107,8 +107,7 @@ Defaults to `nil' which means to go with 
`browse-url-browser-function'."
 (defun engine/execute-search (search-engine-url browser-function search-term)
   "Display the results of the query."
   (interactive)
-  (let ((browse-url-browser-function (or browser-function
-                                         browse-url-browser-function)))
+  (let ((browse-url-browser-function browser-function))
     (browse-url
      (format-spec search-engine-url
                   (format-spec-make ?s (url-hexify-string search-term))))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]