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:
parent
b63ce98731
commit
c57aff9b81
4 changed files with 42 additions and 14 deletions
|
@ -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=")
|
||||
|
||||
|
|
|
@ -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))))
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
(when (featurep! :completion ivy)
|
||||
(package! ivy-xref))
|
||||
(when (featurep! :completion helm)
|
||||
(package! helm-google)
|
||||
(package! helm-xref))
|
||||
|
||||
(when (featurep! +docsets)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue