[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ivy-hydra 32c097a 004/395: counsel.el (counsel-search):
From: |
Basil L. Contovounesios |
Subject: |
[elpa] externals/ivy-hydra 32c097a 004/395: counsel.el (counsel-search): Rename from counsel-google and add DDG |
Date: |
Thu, 25 Feb 2021 08:31:18 -0500 (EST) |
branch: externals/ivy-hydra
commit 32c097a07c6691751d6c9efd8dff6c3dfce545bc
Author: Oleh Krehel <ohwoeowho@gmail.com>
Commit: Oleh Krehel <ohwoeowho@gmail.com>
counsel.el (counsel-search): Rename from counsel-google and add DDG
* counsel.el (counsel-search): Require request and json.
Fixes #2281
---
counsel.el | 83 ++++++++++++++++++++++++++++++++++++++++++++------------------
1 file changed, 59 insertions(+), 24 deletions(-)
diff --git a/counsel.el b/counsel.el
index 8e11fd4..3fe9231 100644
--- a/counsel.el
+++ b/counsel.el
@@ -6103,38 +6103,73 @@ Additional actions:\\<ivy-minibuffer-map>
:action #'counsel-M-x-action
:caller 'counsel-major))
-;;* `counsel-google'
+;;* `counsel-search'
(declare-function request "ext:request")
-(defun counsel-google-function (input)
- "Create a request to Google with INPUT.
+
+(defcustom counsel-search-engine 'ddg
+ "The search engine choice in `counsel-search-engines-alist'."
+ :type '(choice
+ (const ddg)
+ (const google)))
+
+(defcustom counsel-search-engines-alist
+ '((google
+ "http://suggestqueries.google.com/complete/search"
+ "https://www.google.com/search?q="
+ #'counsel--search-request-data-google)
+ (ddg
+ "https://duckduckgo.com/ac/"
+ "https://duckduckgo.com/html/?q="
+ #'counsel--search-request-data-ddg))
+ "Search engine parameters for `counsel-search'."
+ :type '(list))
+
+(defun counsel--search-request-data-google (data)
+ (mapcar #'identity (aref data 1)))
+
+(defun counsel--search-request-data-ddg (data)
+ (mapcar #'cdar data))
+
+(defun counsel-search-function (input)
+ "Create a request to a search engine with INPUT.
Return 0 tells `ivy--exhibit' not to update the minibuffer.
We update it in the callback with `ivy-update-candidates'."
(or
(ivy-more-chars)
(progn
- (require 'request)
- (require 'json)
- (request
- "http://suggestqueries.google.com/complete/search"
- :type "GET"
- :params (list
- (cons "client" "firefox")
- (cons "q" input))
- :parser 'json-read
- :success (cl-function
- (lambda (&key data &allow-other-keys)
- (ivy-update-candidates
- (mapcar #'identity (aref data 1))))))
- 0)))
-
-(defun counsel-google ()
- "Ivy interface for Google."
+ (let ((engine (cdr (assoc counsel-search-engine
counsel-search-engines-alist))))
+ (request
+ (nth 0 engine)
+ :type "GET"
+ :params (list
+ (cons "client" "firefox")
+ (cons "q" input))
+ :parser 'json-read
+ :success (cl-function
+ (lambda (&key data &allow-other-keys)
+ (ivy-update-candidates
+ (funcall (nth 2 engine) data)))))
+ 0))))
+
+(defun counsel-search-action (x)
+ "Search for X."
+ (browse-url
+ (concat
+ (nth 2 (assoc counsel-search-engine counsel-search-engines-alist))
+ x)))
+
+(defun counsel-search ()
+ "Ivy interface for dynamically querying a search engine."
(interactive)
- (ivy-read "search: " #'counsel-google-function
- :action (lambda (x)
- (browse-url (concat "https://www.google.com/search?q="
x)))
+ (require 'request)
+ (require 'json)
+ (ivy-read "search: " #'counsel-search-function
+ :action #'counsel-search-action
:dynamic-collection t
- :caller 'counsel-google))
+ :caller 'counsel-search))
+
+(define-obsolete-function-alias 'counsel-google
+ 'counsel-search "<2019-10-17 Thu>")
;;* `counsel-mode'
(defvar counsel-mode-map
- [elpa] branch externals/ivy-hydra created (now 65f5783), Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 8dc7a05 008/395: swiper.el (swiper--remember-search-history): Extract, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra d4e17ee 009/395: Also remember search history when using swiper-isearch, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra c5e162a 013/395: swiper.el (swiper-thing-at-point): Use regexp-quote, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra be231a5 001/395: counsel.el (counsel-kmacro): Add, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 1ad457d 007/395: ivy.el (ivy-read-action-function): Fix type, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra f6b3b29 011/395: counsel.el (counsel-compile-forget-command): Add, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 7b1af79 012/395: counsel.el (counsel--projectile-root): Add, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 32c097a 004/395: counsel.el (counsel-search): Rename from counsel-google and add DDG,
Basil L. Contovounesios <=
- [elpa] externals/ivy-hydra 884dd9e 025/395: counsel.el (counsel--git-grep-occur-cmd): Handle case folding, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 9666820 037/395: swiper.el (swiper--add-overlays): Don't miss highlights when at eol, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra ad00c47 039/395: swiper.el (swiper--re-builder): Treat "\n" in input as a newline, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 64d18d1 002/395: counsel.el (counsel-ag): Respect case sensitivity settings, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra b0029ca 010/395: Make casefold settings for counsel-git-grep work., Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra a2a3263 014/395: ivy.el (ivy-initial-inputs-alist): Add default behavior, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 2fe64cd 036/395: swiper.el (swiper--isearch-highlight): Don't hang on empty match data, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra f50104c 021/395: ivy.el (ivy--cd-maybe): Exit with 'no-update-history, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 3b35b45 015/395: counsel.el (counsel-ack): Fix, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 47e5046 027/395: swiper.el (swiper--isearch-function-1): Don't skip match at eobp, Basil L. Contovounesios, 2021/02/25