2017-03-15 22:44:42 -04:00
|
|
|
;;; feature/jump/autoload.el
|
|
|
|
|
2017-05-21 12:16:25 +02:00
|
|
|
(defvar +jump--rg-installed-p (executable-find "rg"))
|
|
|
|
(defvar +jump--ag-installed-p (executable-find "ag"))
|
|
|
|
|
2017-03-15 22:44:42 -04:00
|
|
|
;;;###autoload
|
|
|
|
(defun +jump/definition (&optional other-window)
|
2017-05-21 12:16:25 +02:00
|
|
|
"Find definition of the symbol at point.
|
|
|
|
|
|
|
|
Tries xref and falls back to `dumb-jump', then rg/ag."
|
|
|
|
(interactive "P")
|
|
|
|
(let ((sym (thing-at-point 'symbol t))
|
|
|
|
successful)
|
|
|
|
(cond ((null sym)
|
|
|
|
(user-error "Nothing under point"))
|
|
|
|
|
|
|
|
((ignore-errors (if other-window
|
|
|
|
(xref-find-definitions-other-window sym)
|
|
|
|
(xref-find-definitions sym))
|
2017-03-15 22:44:42 -04:00
|
|
|
t))
|
|
|
|
|
|
|
|
((and (fboundp 'dumb-jump-go)
|
2017-05-21 12:16:25 +02:00
|
|
|
;; dumb-jump doesn't tell us if it succeeded or not
|
|
|
|
(cl-letf (((symbol-function 'dumb-jump-result-follow)
|
|
|
|
`(lambda (result &optional use-tooltip proj)
|
|
|
|
(setq successful t)
|
|
|
|
(,(symbol-function 'dumb-jump-result-follow)
|
|
|
|
result use-tooltip proj))))
|
|
|
|
(if other-window
|
|
|
|
(dumb-jump-go-other-window)
|
|
|
|
(dumb-jump-go))
|
|
|
|
successful)))
|
2017-03-15 22:44:42 -04:00
|
|
|
|
2017-05-21 12:16:25 +02:00
|
|
|
((and sym
|
|
|
|
(featurep 'counsel)
|
|
|
|
(let ((regex (rxt-quote-pcre sym)))
|
|
|
|
(or (and +jump--rg-installed-p
|
|
|
|
(counsel-rg regex (doom-project-root)))
|
|
|
|
(and +jump--ag-installed-p
|
|
|
|
(counsel-ag regex (doom-project-root)))))))
|
2017-03-15 22:44:42 -04:00
|
|
|
|
2017-05-21 12:16:25 +02:00
|
|
|
((and (featurep 'evil)
|
|
|
|
evil-mode
|
|
|
|
(let ((bounds (bounds-of-thing-at-point 'symbol))
|
|
|
|
(orig-pt (point)))
|
|
|
|
(evil-goto-definition)
|
|
|
|
(let ((pt (point)))
|
|
|
|
(not (and (>= pt (car bounds))
|
|
|
|
(< pt (cdr bounds))))))))
|
|
|
|
|
|
|
|
(t (user-error "Couldn't find '%s'" sym)))))
|
2017-03-15 22:44:42 -04:00
|
|
|
|
|
|
|
;;;###autoload
|
2017-05-21 12:16:25 +02:00
|
|
|
(defun +jump/references ()
|
2017-03-15 22:44:42 -04:00
|
|
|
"TODO"
|
2017-05-21 12:16:25 +02:00
|
|
|
(interactive)
|
2017-03-15 22:44:42 -04:00
|
|
|
(let ((sym (thing-at-point 'symbol t)))
|
|
|
|
(cond ((progn
|
|
|
|
(ignore-errors (xref-find-references sym)
|
|
|
|
t)))
|
|
|
|
|
2017-05-21 12:16:25 +02:00
|
|
|
((and sym
|
|
|
|
(featurep 'counsel)
|
|
|
|
(let ((regex (rxt-quote-pcre sym)))
|
|
|
|
(or (and (executable-find "rg")
|
|
|
|
(counsel-rg regex (doom-project-root)))
|
|
|
|
(and (executable-find "ag")
|
|
|
|
(counsel-ag regex (doom-project-root)))))))
|
2017-03-15 22:44:42 -04:00
|
|
|
|
|
|
|
(t (error "Couldn't find '%s'" sym)))))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +jump/online (where &optional search)
|
|
|
|
"TODO"
|
|
|
|
(interactive
|
|
|
|
(list (completing-read "Search on: "
|
2017-05-15 20:44:08 +02:00
|
|
|
(mapcar #'car +jump-search-url-alist)
|
2017-03-15 22:44:42 -04:00
|
|
|
nil t)))
|
2017-05-15 20:44:08 +02:00
|
|
|
(let ((url (cdr (assoc where +jump-search-url-alist)))
|
2017-04-17 02:19:20 -04:00
|
|
|
(search (or search (read-string "Query: "))))
|
2017-03-15 22:44:42 -04:00
|
|
|
(browse-url (format url (url-encode-url search)))))
|
|
|
|
|