search-query

Define web search engines for EWW
git clone https://git.git.jamzattack.xyz/search-query
Log | Files | Refs | LICENSE

ModeNameSize
-rw-r--r--.gitignore5L
-rw-r--r--LICENSE674L
-rw-r--r--README.org107L
-rw-r--r--search-query.el144L
Search-query.el – Define web search engines for EWW

Search-query.el – Define web search engines for EWW

This library provides a macro to define search engines consistently and easily. It also provides a few of such search engines that I use regularly.

Installation

package.el

Download search-query.el, and use M-x package-install-file RET path/to/search-query.el.

straight.el

Use the following recipe:

(search-query :type git
              :flavor melpa
              :repo "https://git.jamzattack.xyz/search-query")

Manual installation

  1. Download search-query.el
  2. Stick it in load-path
  3. Update autoloads
  4. (optionally) byte-compile it

Defining a search engine

The macro search-query-create defines a new search engine.

A simple example

In the simplest case, it requires three arguments – name, format-string, and docstring.

For example, the definition of search-archwiki:

(search-query-create archwiki
  "https://wiki.archlinux.org/index.php?search=%s"
  "Search Arch wiki for QUERY.")

This expands to:

(defun search-archwiki (query)
  "Search Arch wiki for QUERY."
  (interactive "sArchwiki: ")
  (search-query-eww
   (url-encode-url
    (format "https://wiki.archlinux.org/index.php?search=%s" query))
   "*eww archwiki*"))

More complicated search engines

For more complicated searches, keyword arguments are supported:

:args the arguments of the function to be defined
:format-args the arguments for the format string
:interactive the interactive spec of the function to be defined

See search-wikipedia as an example, which has an optional language argument:

(search-query-create wikipedia
  "https://%s.wikipedia.org/wiki/Special:Search?search=%s"
  "Search wikipedia for QUERY.
With prefix arg, prompt for LANGUAGE."
  :args (query &optional lang)
  :format-args ((or lang "en") query)
  :interactive (list (read-string "Wikipedia: ")
                     (when current-prefix-arg
                       (read-string "Language: "))))

This expands to:

(defun search-wikipedia (query &optional lang)
  "Search wikipedia for QUERY.
With prefix arg, prompt for LANGUAGE."
  (interactive (list
                (read-string "Wikipedia: ")
                (when current-prefix-arg
                  (read-string "Language: "))))
  (search-query-eww
   (url-encode-url
    (format "https://%s.wikipedia.org/wiki/Special:Search?search=%s"
            (or lang "en")
            query))
   "*eww wikipedia*"))

Here, all three additional keyword arguments are used.

License

GPL3+