diff --git a/init.example.el b/init.example.el index 1dd29b910..81c6eb7d0 100644 --- a/init.example.el +++ b/init.example.el @@ -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 diff --git a/modules/completion/ivy/config.el b/modules/completion/ivy/config.el index 5217aecef..2c76951d1 100644 --- a/modules/completion/ivy/config.el +++ b/modules/completion/ivy/config.el @@ -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 diff --git a/modules/feature/jump/autoload.el b/modules/feature/jump/autoload.el new file mode 100644 index 000000000..abe27c045 --- /dev/null +++ b/modules/feature/jump/autoload.el @@ -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))))) + diff --git a/modules/feature/jump/config.el b/modules/feature/jump/config.el new file mode 100644 index 000000000..ead7e98d5 --- /dev/null +++ b/modules/feature/jump/config.el @@ -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)) + diff --git a/modules/feature/jump/packages.el b/modules/feature/jump/packages.el new file mode 100644 index 000000000..58ba67eda --- /dev/null +++ b/modules/feature/jump/packages.el @@ -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))) + diff --git a/modules/private/hlissner/+bindings.el b/modules/private/hlissner/+bindings.el index 5a1650484..8d58055fd 100644 --- a/modules/private/hlissner/+bindings.el +++ b/modules/private/hlissner/+bindings.el @@ -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