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