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).
This commit is contained in:
Henrik Lissner 2019-12-29 19:21:09 -05:00
parent b63ce98731
commit c57aff9b81
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
4 changed files with 42 additions and 14 deletions

View file

@ -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)))) ("L" (lambda (path) (with-ivy-window (insert (format "[[%s]]" path))))
"Insert absolute org-link"))) "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)) (setf (nth 1 (alist-get 'ddg counsel-search-engines-alist))
"https://duckduckgo.com/?q=") "https://duckduckgo.com/?q=")

View file

@ -25,8 +25,8 @@ argument is non-nil)."
(+lookup--online-provider (not current-prefix-arg)))) (+lookup--online-provider (not current-prefix-arg))))
;;;###autoload ;;;###autoload
(defun +lookup/online (arg &optional query provider) (defun +lookup/online (query provider)
"Looks up QUERY (a string) in you browser using PROVIDER. "Looks up QUERY (a string) in you browser usin PROVIDER.
PROVIDER should be a key of `+lookup-provider-url-alist'. 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 from `+lookup-provider-url-alist'. On consecutive uses, the last
provider will be reused. If the universal argument is supplied, always prompt provider will be reused. If the universal argument is supplied, always prompt
for the provider." for the provider."
(interactive "P") (interactive
(let* ((provider (or provider (+lookup--online-provider arg))) (list (if (use-region-p) (+lookup-symbol-or-region))
(query (or query (+lookup-symbol-or-region))) (+lookup--online-provider current-prefix-arg)))
(backend (cl-find-if (lambda (x) (or (stringp x) (fboundp x))) (let ((backend (cl-find-if (lambda (x) (or (stringp x) (fboundp x)))
(cdr (assoc provider +lookup-provider-url-alist))))) (cdr (assoc provider +lookup-provider-url-alist)))))
(if (and (functionp backend) (unless (and (functionp backend)
(commandp backend)) (funcall backend query))
(call-interactively backend)
(unless backend (unless backend
(user-error "%S is an invalid query engine backend for %S provider" (user-error "%S is an invalid query engine backend for %S provider"
backend provider)) backend provider))
@ -69,3 +68,32 @@ for the provider."
(interactive) (interactive)
(let ((current-prefix-arg t)) (let ((current-prefix-arg t))
(call-interactively #'+lookup/online))) (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))))

View file

@ -13,11 +13,11 @@
;; `dumb-jump' to find what you want. ;; `dumb-jump' to find what you want.
(defvar +lookup-provider-url-alist (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 images" "https://www.google.com/images?q=%s")
("Google maps" "https://maps.google.com/maps?q=%s") ("Google maps" "https://maps.google.com/maps?q=%s")
("Project Gutenberg" "http://www.gutenberg.org/ebooks/search/?query=%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") ("DevDocs.io" "https://devdocs.io/#q=%s")
("StackOverflow" "https://stackoverflow.com/search?q=%s") ("StackOverflow" "https://stackoverflow.com/search?q=%s")
("Github" "https://github.com/search?ref=simplesearch&q=%s") ("Github" "https://github.com/search?ref=simplesearch&q=%s")

View file

@ -12,7 +12,6 @@
(when (featurep! :completion ivy) (when (featurep! :completion ivy)
(package! ivy-xref)) (package! ivy-xref))
(when (featurep! :completion helm) (when (featurep! :completion helm)
(package! helm-google)
(package! helm-xref)) (package! helm-xref))
(when (featurep! +docsets) (when (featurep! +docsets)