Add modules/feature/jump (WIP)
This commit is contained in:
parent
8c9269c9a2
commit
9c4ae61476
6 changed files with 127 additions and 4 deletions
|
@ -32,7 +32,7 @@
|
|||
|
||||
(doom! :feature
|
||||
evil ; come to the dark side, we have cookies
|
||||
;; TODO jump ; navigating your code
|
||||
jump ; helping you navigate your code base
|
||||
snippets ; my elves. They type so I don't have to
|
||||
file-templates ; auto-snippets for empty files
|
||||
spellcheck ; tasing you for misspelling mispelling
|
||||
|
|
|
@ -110,9 +110,7 @@
|
|||
(when (eq major-mode 'ivy-occur-grep-mode)
|
||||
(ivy-wgrep-change-to-wgrep-mode)))
|
||||
|
||||
(defun +ivy*recenter (&rest _) (recenter))
|
||||
(advice-add 'counsel-ag-function :override '+ivy*counsel-ag-function)
|
||||
(advice-add 'imenu :after '+ivy*recenter)
|
||||
(map! :map counsel-ag-map
|
||||
[backtab] '+ivy/counsel-ag-occur ; search/replace on results
|
||||
"C-SPC" 'counsel-git-grep-recenter ; preview
|
||||
|
|
49
modules/feature/jump/autoload.el
Normal file
49
modules/feature/jump/autoload.el
Normal file
|
@ -0,0 +1,49 @@
|
|||
;;; feature/jump/autoload.el
|
||||
|
||||
;;;###autoload
|
||||
(defun +jump/definition (&optional other-window)
|
||||
"Find definition, falling back to dumb-jump, then
|
||||
`evil-goto-definition' otherwise."
|
||||
(interactive "p")
|
||||
(let ((orig-pt (point))
|
||||
(orig-file (buffer-file-name))
|
||||
(sym (thing-at-point 'symbol t)))
|
||||
(cond ((ignore-errors (xref-find-definitions sym)
|
||||
t))
|
||||
|
||||
((and (fboundp 'dumb-jump-go)
|
||||
(progn (dumb-jump-go)
|
||||
(and (= orig-pt (point))
|
||||
(equal (file-truename orig-file)
|
||||
(file-truename buffer-file-name))))))
|
||||
|
||||
((fboundp 'counsel-ag)
|
||||
(counsel-ag sym (doom-project-root)))
|
||||
|
||||
(t (error "Couldn't find '%s'" sym)))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +jump/references (&optional other-window)
|
||||
"TODO"
|
||||
(interactive "p")
|
||||
(let ((sym (thing-at-point 'symbol t)))
|
||||
(cond ((progn
|
||||
(ignore-errors (xref-find-references sym)
|
||||
t)))
|
||||
|
||||
((fboundp 'counsel-ag)
|
||||
(counsel-ag sym (doom-project-root)))
|
||||
|
||||
(t (error "Couldn't find '%s'" sym)))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +jump/online (where &optional search)
|
||||
"TODO"
|
||||
(interactive
|
||||
(list (completing-read "Search on: "
|
||||
(mapcar 'car +lookup-search-url-alist)
|
||||
nil t)))
|
||||
(let ((url (cdr (assoc where +lookup-search-url-alist)))
|
||||
(search (or search (read-input "Query: "))))
|
||||
(browse-url (format url (url-encode-url search)))))
|
||||
|
65
modules/feature/jump/config.el
Normal file
65
modules/feature/jump/config.el
Normal file
|
@ -0,0 +1,65 @@
|
|||
;;; feature/jump/config.el
|
||||
|
||||
;; "What am I looking at?"
|
||||
;;
|
||||
;; This module helps you answer that question. It helps you look up whatever
|
||||
;; you're looking at, with:
|
||||
;;
|
||||
;; 1. A dwim Jump-to-definition functionality that "just works", with the help
|
||||
;; of `dumb-jump'.
|
||||
;; 2. A dwim interface to the new (and experimental) xref API built into Emacs.
|
||||
;; Once its API is more stable, backends could be written (or provided by
|
||||
;; plugins) to create universal find-references and find-definition
|
||||
;; functionality. Warning: xref may change drastically in future updates.
|
||||
;; 3. Simple ways to look up the symbol at point in external resources, like
|
||||
;; stackoverflow, devdocs.io or google.
|
||||
;; 4. TODO Automatic and transparent integration with cscope databases and ctags
|
||||
;; files. Databases are optionally isolated to the Emacs environment.
|
||||
|
||||
(defvar +lookup-search-url-alist
|
||||
'(("Google" . "https://google.com/?q=%s")
|
||||
("DuckDuckGo" . "https://duckduckgo.com/?q=%s")
|
||||
("DevDocs.io" . "http://devdocs.io/#q=%s")
|
||||
("StackOverflow" . "https://stackoverflow.com/search?q=%s"))
|
||||
"An alist that maps online resources to their search url.")
|
||||
|
||||
(set! :popup "*xref*" :size 10 :noselect t :autokill t :autoclose t)
|
||||
|
||||
;; Let me control what backends to fall back on
|
||||
(setq-default xref-backend-functions '())
|
||||
|
||||
(def-setting! :xref-backend (mode function)
|
||||
"TODO"
|
||||
`(add-hook! ,mode
|
||||
(add-hook 'xref-backend-functions ',function nil t)))
|
||||
|
||||
;; Recenter after certain jumps
|
||||
(add-hook!
|
||||
'(imenu-after-jump-hook evil-jumps-post-jump-hook)
|
||||
'recenter)
|
||||
|
||||
|
||||
;;
|
||||
;; Packages
|
||||
;;
|
||||
|
||||
(def-package! dumb-jump
|
||||
:commands (dumb-jump-go dumb-jump-quick-look dumb-jump-back)
|
||||
:config
|
||||
(setq dumb-jump-default-project doom-emacs-dir))
|
||||
|
||||
|
||||
;; (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))
|
||||
|
10
modules/feature/jump/packages.el
Normal file
10
modules/feature/jump/packages.el
Normal file
|
@ -0,0 +1,10 @@
|
|||
;; -*- no-byte-compile: t; -*-
|
||||
;;; feature/jump/packages.el
|
||||
|
||||
(package! dumb-jump)
|
||||
;; (package! ggtags)
|
||||
;; (cond ((featurep! :completion ivy)
|
||||
;; (package! counsel-gtags))
|
||||
;; ((featurep! :completion helm)
|
||||
;; (package! helm-gtags)))
|
||||
|
|
@ -205,7 +205,8 @@
|
|||
:m "[t" 'hl-todo-previous
|
||||
;; Navigation
|
||||
:nv "K" 'smart-up
|
||||
:m "gD" '+jump/find-definition
|
||||
:m "gd" '+jump/definition
|
||||
:m "gD" '+jump/references
|
||||
:n "gf" 'find-file-at-point
|
||||
:n "gp" '+evil/reselect-paste
|
||||
:n "gc" 'evil-commentary
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue