Coder Social home page Coder Social logo

websearch's Introduction

Emacs-WebSearch

Query search engines from Emacs.

About

The websearch package allows You to query predefined search engines (websearch-custom-engines) with interactive selection. The query terms can either be extracted form selection, kill-ring or typed on demand.

The websearch function is a interactive entry-point to select both the terms extraction method and search engine provider.

To turn on the global mode enabling a custom key map, activate websearch-mode.

websearch is inspired by engine-mode (https://github.com/hrs/engine-mode), but the differences are big enough for it to be it's own package.

The websearch-define macro helps you to create function to call websearch with a specific engine or tag found in (websearch-custom-engines).

For example if I want to just search github

(websearch-define "github")

That will define the interactive function

(lambda (search-term &optional arg)
  "Search Github for SEARCH-TERM with `websearch'.
SEARCH-TERM is region if region is selected
When called with prefix ARG use `kill-ring' for completions"
  (interactive
   (let* ((arg current-prefix-arg)
          (region (if (use-region-p)
                      (buffer-substring-no-properties
                       (region-beginning)
                       (region-end))))
          (kill (mapcar #'substring-no-properties kill-ring))
          (thing-at-point (if (thing-at-point 'symbol)
                              (progn (substring-no-properties
                                      (thing-at-point 'symbol)))))
          (completions (if arg
                           kill
                         (remove nil (delete-dups
                                      (list region thing-at-point kill))))))
     (list (completing-read "Search term: " completions))))
  (websearch--browse-url search-term "github"))

When executed it will search github for the region or if no region is selected promt for input with completion for your last kill, thing-at-point or custom input.

The macro can also take additional arguments, if called with the query-separator and query-url argument it will add the engine to (websearch-custom-engines) with the tag "generic" or the tag can be changed using the tags argument. Here is an example

(websearch-define "brave"
    :query-separator "+"
    :query-url "search.brave.com/search?q="
    :tags ("text" "generic"))

If you also want to bind it to a key you can call it with the keybinding argument like so.

(websearch-define "emacswiki"
    :query-separator "+"
    :query-url "duckduckgo.com/?q=site%3Aemacswiki.org+"
    :tags ("text" "emacs")
    :keybinding "e") ;; Becomes "C-c C-s e"

The keybinding is applied to the websearch-mode-map and defaults to using the websearch-custom-keymap-prefix (default "C-c C-s").

You can also define a search of the engines by tag e.g. #code-forge

(websearch-define "#code-forge")

;; or with keybinding
(websearch-define "#code-forge"
    :keybinding "C")

Instead of one website a websearch group found in (`websearch-custom-groups') can also be searched like so

(websearch-define-group "google, duckduckgo, yandex"
    :keybinding "d")

It can also be used to add an engine to (websearch-custom-engines') or an engine-group to (websearch-custom-groups') without creating a function

(websearch-define "yahoo"
    :query-separator "+"
    :query-url "search.yahoo.com/search?p="
    :tags ("text" "generic")
    :keybinding "y"  ;; no effect due to :function nil argument
    :function nil)
;; => ("yahoo" "+" "search.yahoo.com/search?p=" ("text" "generic"))
;; added to `websearch-custom-engines'
;; Keybinding "y" not created as there will be no function to call
;; alternativly
(websearch-define "yahoo"
    :query-separator "+"
    :query-url "search.yahoo.com/search?p="
    :tags ("text" "generic")
    :function nil)

;; or as a group
(websearch-define-group "google, yahoo, brave, duckduckgo, yandex"
    :keybinding "A"  ;; no effect due to :function nil argument
    :function nil)
;; => "google, yahoo, brave, duckduckgo, yandex" added to
;; `websearch-custom-groups'

License

Copyright (c) 2022-2023, Maciej Barć [email protected]

Licensed under the GNU GPL v2 License

SPDX-License-Identifier: GPL-2.0-or-later

websearch's People

Contributors

xgqt avatar ypot avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.