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

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

[nongnu] elpa/engine-mode 2c327f1785 24/71: Set engine-specific browsers


From: ELPA Syncer
Subject: [nongnu] elpa/engine-mode 2c327f1785 24/71: Set engine-specific browsers
Date: Wed, 21 Dec 2022 09:59:08 -0500 (EST)

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

    Set engine-specific browsers
    
    Sometimes we want to the results of a specific engine with a nonstandard
    browser. This provides the `:browser` keyword argument to `defengine`,
    which allows us to override the browser on a per-engine basis.
---
 README.md      | 15 +++++++++++++++
 engine-mode.el | 18 ++++++++++--------
 2 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/README.md b/README.md
index f93b68c69c..1b1d15e06e 100644
--- a/README.md
+++ b/README.md
@@ -60,6 +60,21 @@ contains a comprehensive list of possible browsing 
functions. You can
 get to that by hitting `C-h v browser-url-browser-function <RETURN>`
 and following the link to `browse-url.el`.
 
+## Changing your browser on a per-engine basis
+
+To only change the browser for a single engine, use the `:browser`
+keyword argument when you define the engine. For example, to use `eww`
+only for your GitHub search results, try:
+
+```emacs
+(defengine github
+  "https://github.com/search?ref=simplesearch&q=%s";
+  :browser 'eww-browse-url)
+```
+
+As mentioned about, see the implementation of the
+`browse-url-browser-function` for a definitive list of browsers.
+
 ## Changing the keymap prefix
 
 The default keymap prefix for `engine-mode` is `C-c /`. If you'd like
diff --git a/engine-mode.el b/engine-mode.el
index e5830bfdc0..f48ce9c5b5 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: 2015.05.02
+;; Version: 2015.05.17
 ;; URL: https://github.com/hrs/engine-mode/engine-mode.el
 
 ;; This file is NOT part of GNU Emacs.
@@ -74,12 +74,13 @@
       (buffer-substring (region-beginning) (region-end))
     (engine/prompted-search-term engine-name)))
 
-(defun engine/execute-search (search-engine-url search-term)
+(defun engine/execute-search (search-engine-url browser-function search-term)
   "Display the results of the query."
   (interactive)
-  (browse-url
-   (format search-engine-url
-           (url-hexify-string search-term))))
+  (let ((browse-url-browser-function browser-function))
+    (browse-url
+     (format search-engine-url
+             (url-hexify-string search-term)))))
 
 (defun engine/function-name (engine-name)
   (intern (concat "engine/search-" (downcase (symbol-name engine-name)))))
@@ -97,7 +98,7 @@
     `(define-key engine-mode-map (kbd ,(engine/scope-keybinding keybinding))
        (quote ,(engine/function-name engine-name)))))
 
-(cl-defmacro defengine (engine-name search-engine-url &key keybinding 
docstring (term-transformation-hook 'identity))
+(cl-defmacro defengine (engine-name search-engine-url &key keybinding 
docstring (browser 'browse-url-browser-function) (term-transformation-hook 
'identity))
   "Define a custom search engine.
 
 `engine-name' is a symbol naming the engine.
@@ -106,7 +107,8 @@ standing in for the search term.
 The optional keyword argument `docstring' assigns a docstring to
 the generated function. A reasonably sensible docstring will be
 generated if a custom one isn't provided.
-
+The optional keyword argument `browser` assigns the browser
+function to be used when opening the URL.
 The optional keyword argument `term-transformation-hook' is a
 function that will be applied to the search term before it's
 substituted into `search-engine-url'. For example, if we wanted
@@ -141,7 +143,7 @@ Hitting \"C-c / w\" will be bound to the newly-defined
        ,(or docstring (engine/docstring engine-name))
        (interactive
         (list (engine/get-query ,(symbol-name engine-name))))
-       (engine/execute-search ,search-engine-url (,term-transformation-hook 
search-term)))
+       (engine/execute-search ,search-engine-url ,browser 
(,term-transformation-hook search-term)))
      ,(engine/bind-key engine-name keybinding)))
 
 (provide 'engine-mode)



reply via email to

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