doomemacs/modules/feature/jump/config.el

120 lines
4.4 KiB
EmacsLisp
Raw Normal View History

;;; feature/jump/config.el -*- lexical-binding: t; -*-
2017-03-15 22:44:42 -04:00
;; "What am I looking at?"
;;
;; This module helps you answer that question. It helps you look up whatever
2017-05-21 15:06:15 +02:00
;; you're looking at.
2017-03-15 22:44:42 -04:00
;;
2017-05-21 15:06:15 +02:00
;; + `+jump/definition': a jump-to-definition that should 'just work'
;; + `+jump/references': find a symbol's references in the current project
;; + `+jump/online'; look up a symbol on online resources, like stackoverflow,
;; devdocs.io or google.
;;
;; This module uses `xref', an experimental new library in Emacs. It may change
;; in the future. When xref can't be depended on it will fall back to
;; `dumb-jump' to find what you want.
2017-03-15 22:44:42 -04:00
(defvar +jump-search-provider-alist
2017-09-28 18:05:43 +02:00
'(("Google" . "https://google.com/search?q=%s")
("Google images" . "https://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" . "https://duckduckgo.com/?q=%s")
("DevDocs.io" . "http://devdocs.io/#q=%s")
("StackOverflow" . "https://stackoverflow.com/search?q=%s")
("Github" . "https://github.com/search?ref=simplesearch&q=%s")
("Youtube" . "https://youtube.com/results?aq=f&oq=&search_query=%s")
("Wolfram alpha" . "https://wolframalpha.com/input/?i=%s")
("Wikipedia" . "https://wikipedia.org/search-redirect.php?language=en&go=Go&search=%s"))
2017-05-21 15:06:15 +02:00
"An alist that maps online resources to their search url or a function that
produces an url. Used by `+jump/online'.")
2017-03-15 22:44:42 -04:00
2017-09-28 18:06:07 +02:00
(defconst +jump-search-browser-fn #'browse-url
"Function to use to open search urls.")
(defvar +jump-function-alist nil
2017-09-28 18:08:20 +02:00
"An alist mapping major modes to jump function plists, describing what to do
with `+jump/definition', `+jump/references' and `+jump/documentation' are
called.")
2017-03-15 22:44:42 -04:00
(defvar-local +jump-current-functions nil
2017-09-28 18:08:20 +02:00
"The enabled jump functions for the current buffer.")
(def-setting! :jump (modes &rest plist)
2017-07-18 11:57:51 +02:00
"Definies a jump target for major MODES. PLIST accepts the following
properties:
:definition FN
Run when jumping to a symbol's definition.
Used by `+jump/definition'.
:references FN
Run when looking for usage references of a symbol in the current project.
Used by `+jump/references'.
:documentation FN
Run when looking up documentation for a symbol.
Used by `+jump/documentation'."
`(dolist (mode (doom-enlist ,modes))
(push (cons mode (list ,@plist)) +jump-function-alist)))
2017-05-21 15:06:15 +02:00
;; Let me control what backends to fall back on
(setq-default xref-backend-functions '(t))
(set! :popup "*xref*" :noselect t :autokill t :autoclose t)
2017-03-15 22:44:42 -04:00
;; Recenter after certain jumps
(add-hook!
2017-05-26 11:47:10 +02:00
'(imenu-after-jump-hook evil-jumps-post-jump-hook
counsel-grep-post-action-hook dumb-jump-after-jump-hook)
2017-06-05 00:47:56 +02:00
#'recenter)
2017-03-15 22:44:42 -04:00
(defun +jump|init ()
"Initialize `+jump-current-functions', used by `+jump/definition',
`+jump/references' and `+jump/documentation'."
(when-let* ((plist (cdr (assq major-mode +jump-function-alist))))
(when-let* ((backend (plist-get plist :xref-backend)))
(make-variable-buffer-local 'xref-backend-functions)
(cl-pushnew backend xref-backend-functions :test #'eq))
(setq-local +jump-current-functions plist)))
(add-hook 'after-change-major-mode-hook #'+jump|init)
2017-03-15 22:44:42 -04:00
;;
;; Packages
;;
(def-package! dumb-jump
:commands (dumb-jump-go dumb-jump-quick-look
dumb-jump-back dumb-jump-result-follow)
2017-03-15 22:44:42 -04:00
:config
2017-05-21 15:06:15 +02:00
(setq dumb-jump-default-project doom-emacs-dir
2017-05-23 21:32:07 +02:00
dumb-jump-aggressive nil
2017-05-21 15:06:15 +02:00
dumb-jump-selector (cond ((featurep! :completion ivy) 'ivy)
((featurep! :completion helm) 'helm)
(t 'popup))))
2017-05-21 14:11:52 +02:00
(def-package! gxref
:commands (gxref-xref-backend
gxref-create-db
gxref-update-db
gxref-single-update-db
gxref-set-project-dir)
:init
(setq-default xref-backend-functions '(gxref-xref-backend t)))
2017-03-15 22:44:42 -04:00
;; (def-package! ggtags
;; :commands (ggtags-find-tag-dwim
;; ggtags-find-tag-mouse
;; ggtags-find-definition
;; ggtags-find-reference
;; ggtags-find-other-symbol
;; ggtags-find-tag-regexp
;; ggtags-idutils-query
;; ggtags-grep
;; ggtags-find-file
;; ggtags-query-replace
;; ggtags-delete-tags
;; ggtags-explain-tags))