From c57aff9b81611e078b5b3b050002524393944189 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 29 Dec 2019 19:21:09 -0500 Subject: [PATCH] Change how +lookup/online populates initial input If no selection is active, there is no initial input. If selection is active, use the selection. Also remove helm-google package, as the helm functionality is provided by the core helm package already (and actually works). --- modules/completion/ivy/config.el | 3 +- modules/tools/lookup/autoload/online.el | 48 +++++++++++++++++++------ modules/tools/lookup/config.el | 4 +-- modules/tools/lookup/packages.el | 1 - 4 files changed, 42 insertions(+), 14 deletions(-) diff --git a/modules/completion/ivy/config.el b/modules/completion/ivy/config.el index bf34992c8..84445f621 100644 --- a/modules/completion/ivy/config.el +++ b/modules/completion/ivy/config.el @@ -243,7 +243,8 @@ evil-ex-specific constructs, so we disable it solely in evil-ex." ("L" (lambda (path) (with-ivy-window (insert (format "[[%s]]" path)))) "Insert absolute org-link"))) - ;; `counsel-search' + ;; `counsel-search': use normal page for displaying results, so that we see + ;; custom ddg themes (if one is set). (setf (nth 1 (alist-get 'ddg counsel-search-engines-alist)) "https://duckduckgo.com/?q=") diff --git a/modules/tools/lookup/autoload/online.el b/modules/tools/lookup/autoload/online.el index f5de9b1a0..bdd9639a0 100644 --- a/modules/tools/lookup/autoload/online.el +++ b/modules/tools/lookup/autoload/online.el @@ -25,8 +25,8 @@ argument is non-nil)." (+lookup--online-provider (not current-prefix-arg)))) ;;;###autoload -(defun +lookup/online (arg &optional query provider) - "Looks up QUERY (a string) in you browser using PROVIDER. +(defun +lookup/online (query provider) + "Looks up QUERY (a string) in you browser usin PROVIDER. PROVIDER should be a key of `+lookup-provider-url-alist'. @@ -34,14 +34,13 @@ When used interactively, it will prompt for a query and, for the first time, the provider from `+lookup-provider-url-alist'. On consecutive uses, the last provider will be reused. If the universal argument is supplied, always prompt for the provider." - (interactive "P") - (let* ((provider (or provider (+lookup--online-provider arg))) - (query (or query (+lookup-symbol-or-region))) - (backend (cl-find-if (lambda (x) (or (stringp x) (fboundp x))) - (cdr (assoc provider +lookup-provider-url-alist))))) - (if (and (functionp backend) - (commandp backend)) - (call-interactively backend) + (interactive + (list (if (use-region-p) (+lookup-symbol-or-region)) + (+lookup--online-provider current-prefix-arg))) + (let ((backend (cl-find-if (lambda (x) (or (stringp x) (fboundp x))) + (cdr (assoc provider +lookup-provider-url-alist))))) + (unless (and (functionp backend) + (funcall backend query)) (unless backend (user-error "%S is an invalid query engine backend for %S provider" backend provider)) @@ -69,3 +68,32 @@ for the provider." (interactive) (let ((current-prefix-arg t)) (call-interactively #'+lookup/online))) + + +;; +;;; Special provider frontends + +(defvar ivy-initial-inputs-alist) +(defvar counsel-search-engine) +;;;###autoload +(defun +lookup--online-backend-google (query) + "Search google, starting with QUERY, with live autocompletion." + (cond ((fboundp 'counsel-search) + (let ((ivy-initial-inputs-alist `((t . ,query))) + (counsel-search-engine 'google)) + (call-interactively #'counsel-search) + t)) + ((require 'helm-net nil t) + (helm :sources 'helm-source-google-suggest + :buffer "*helm google*" + :input query) + t))) + +;;;###autoload +(defun +lookup--online-backend-duckduckgo (query) + "Search duckduckgo, starting with QUERY, with live autocompletion." + (cond ((fboundp 'counsel-search) + (let ((ivy-initial-inputs-alist `((t . ,query))) + (counsel-search-engine 'ddg)) + (call-interactively #'counsel-search) + t)))) diff --git a/modules/tools/lookup/config.el b/modules/tools/lookup/config.el index c80e09c52..017619f84 100644 --- a/modules/tools/lookup/config.el +++ b/modules/tools/lookup/config.el @@ -13,11 +13,11 @@ ;; `dumb-jump' to find what you want. (defvar +lookup-provider-url-alist - (append '(("Google" counsel-search helm-google-suggest "https://google.com/search?q=%s") + (append '(("Google" +lookup--online-backend-google "https://google.com/search?q=%s") ("Google images" "https://www.google.com/images?q=%s") ("Google maps" "https://maps.google.com/maps?q=%s") ("Project Gutenberg" "http://www.gutenberg.org/ebooks/search/?query=%s") - ("DuckDuckGo" counsel-search "https://duckduckgo.com/?q=%s") + ("DuckDuckGo" +lookup--online-backend-duckduckgo "https://duckduckgo.com/?q=%s") ("DevDocs.io" "https://devdocs.io/#q=%s") ("StackOverflow" "https://stackoverflow.com/search?q=%s") ("Github" "https://github.com/search?ref=simplesearch&q=%s") diff --git a/modules/tools/lookup/packages.el b/modules/tools/lookup/packages.el index 173350732..6f82a56eb 100644 --- a/modules/tools/lookup/packages.el +++ b/modules/tools/lookup/packages.el @@ -12,7 +12,6 @@ (when (featurep! :completion ivy) (package! ivy-xref)) (when (featurep! :completion helm) - (package! helm-google) (package! helm-xref)) (when (featurep! +docsets)