Add :lookup & rewrite +jump/online
This commit is contained in:
parent
d5d0f26c09
commit
61ad485ae3
3 changed files with 30 additions and 30 deletions
|
@ -2,20 +2,15 @@
|
|||
|
||||
;;;###autoload (autoload '+jump:online "feature/jump/autoload/evil" nil t)
|
||||
(evil-define-command +jump:online (query &optional bang)
|
||||
"Look up QUERY online. You can prefix your queries with a one-letter shortcut
|
||||
key (dictated by `+jump-search-url-alist'), otherwise you will be prompted for
|
||||
what search engine to use."
|
||||
"Look up QUERY online. Will prompt for search engine the first time, then
|
||||
reuse it on consecutive uses of this command. If BANG, always prompt for search
|
||||
engine."
|
||||
(interactive "<a><!>")
|
||||
(let ((query query)
|
||||
(engine (assoc (car-safe (split-string query " " t t))
|
||||
+jump-search-url-alist)))
|
||||
(if engine
|
||||
(setq query (string-join (cdr-safe (split-string query " " t t)) " "))
|
||||
(let ((engine (completing-read "Search on: "
|
||||
(mapcar #'cadr +jump-search-url-alist)
|
||||
nil t)))
|
||||
(setq engine (cl-find-if (lambda (x) (equal (cadr x) engine))
|
||||
+jump-search-url-alist))))
|
||||
(unless engine
|
||||
(error "Search engine couldn't be found"))
|
||||
(setq query (or query (thing-at-point 'symbol t)))
|
||||
(unless query
|
||||
(user-error "The search query is empty"))
|
||||
(let ((engine (or (and (not bang) (bound-and-true-p +jump--online-last))
|
||||
(completing-read (format "Search on (%s): " query)
|
||||
(mapcar #'car +jump-search-url-alist)
|
||||
nil t))))
|
||||
(+jump/online engine query)))
|
||||
|
|
|
@ -72,7 +72,7 @@ Tries `xref-find-references' and falls back to rg/ag."
|
|||
|
||||
(t (error "Couldn't find '%s'" sym)))))
|
||||
|
||||
(defvar +jump--online-last-url nil)
|
||||
(defvar +jump--online-last nil)
|
||||
|
||||
;;;###autoload
|
||||
(defun +jump/online (where search)
|
||||
|
@ -81,18 +81,22 @@ Tries `xref-find-references' and falls back to rg/ag."
|
|||
Interactively, you are prompted to choose a source from
|
||||
`+jump-search-url-alist'."
|
||||
(interactive
|
||||
(list (completing-read "Search on: "
|
||||
(mapcar #'cdr +jump-search-url-alist)
|
||||
nil t)
|
||||
(or (and (not current-prefix-arg)
|
||||
+jump--online-last-url)
|
||||
(thing-at-point 'symbol t))))
|
||||
(let ((url (cdr (assoc where +jump-search-url-alist))))
|
||||
(when (or (functionp url) (symbolp url))
|
||||
(setq url (funcall url)))
|
||||
(cl-assert (stringp url))
|
||||
(cl-assert (not (string-empty-p url)))
|
||||
(cl-assert (not (string-empty-p search)))
|
||||
(setq +jump--online-last-url url)
|
||||
(browse-url (format url (url-encode-url search)))))
|
||||
(list (or (and (not current-prefix-arg)
|
||||
+jump--online-last)
|
||||
(completing-read (format "Search on (%s): " (thing-at-point 'symbol t))
|
||||
(mapcar #'car +jump-search-url-alist)
|
||||
nil t))
|
||||
(thing-at-point 'symbol t)))
|
||||
(condition-case ex
|
||||
(let ((url (cdr (assoc where +jump-search-url-alist))))
|
||||
(unless url
|
||||
(error "'%s' is an invalid search engine" where))
|
||||
(when (or (functionp url) (symbolp url))
|
||||
(setq url (funcall url)))
|
||||
(cl-assert (and (stringp url) (not (string-empty-p url))))
|
||||
(when (string-empty-p search)
|
||||
(user-error "The search query is empty"))
|
||||
(setq +jump--online-last where)
|
||||
(browse-url (format url (url-encode-url search))))
|
||||
('error (setq +jump--online-last nil))))
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
;; TODO (ex! "db" #'doom:db)
|
||||
;; TODO (ex! "dbu[se]" #'doom:db-select)
|
||||
;; TODO (ex! "go[ogle]" #'doom:google-search)
|
||||
(ex! "lo[okup]" #'+jump:online)
|
||||
(ex! "http" #'httpd-start) ; start http server
|
||||
(ex! "repl" #'+eval:repl) ; invoke or send to repl
|
||||
;; TODO (ex! "rx" 'doom:regex) ; open re-builder
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue