Add :gblame & :grevert ex commands

This commit is contained in:
Henrik Lissner 2017-05-21 15:06:15 +02:00
parent 546c672f8a
commit d5d0f26c09
5 changed files with 70 additions and 30 deletions

View file

@ -418,6 +418,8 @@ In modules, checks modules/*/autoload.el and modules/*/autoload/*.el.
Rerun this whenever init.el is modified. You can also use `make autoloads` from Rerun this whenever init.el is modified. You can also use `make autoloads` from
the commandline." the commandline."
(interactive) (interactive)
;; This function must not use `cl-lib', autoloaded functions or external
;; dependencies. It must assume nothing is set up!
(doom-initialize-packages (not noninteractive)) (doom-initialize-packages (not noninteractive))
(let ((generated-autoload-file doom-autoload-file) (let ((generated-autoload-file doom-autoload-file)
(autoload-files (autoload-files

View file

@ -0,0 +1,21 @@
;;; feature/jump/autoload/evil.el
;;;###autoload (autoload '+jump:online "feature/jump/autoload/evil" nil t)
(evil-define-command +jump:online (query &optional bang)
"Look up QUERY online. You can prefix your queries with a one-letter shortcut
key (dictated by `+jump-search-url-alist'), otherwise you will be prompted for
what search engine to use."
(interactive "<a><!>")
(let ((query query)
(engine (assoc (car-safe (split-string query " " t t))
+jump-search-url-alist)))
(if engine
(setq query (string-join (cdr-safe (split-string query " " t t)) " "))
(let ((engine (completing-read "Search on: "
(mapcar #'cadr +jump-search-url-alist)
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)))

View file

@ -5,9 +5,10 @@
;;;###autoload ;;;###autoload
(defun +jump/definition (&optional other-window) (defun +jump/definition (&optional other-window)
"Find definition of the symbol at point. "Jump to the definition of the symbol at point.
Tries xref and falls back to `dumb-jump', then rg/ag." Tries xref and falls back to `dumb-jump', then rg/ag, then
`evil-goto-definition' (if evil is active)."
(interactive "P") (interactive "P")
(let ((sym (thing-at-point 'symbol t)) (let ((sym (thing-at-point 'symbol t))
successful) successful)
@ -52,7 +53,9 @@ Tries xref and falls back to `dumb-jump', then rg/ag."
;;;###autoload ;;;###autoload
(defun +jump/references () (defun +jump/references ()
"TODO" "Show a list of references to the symbol at point.
Tries `xref-find-references' and falls back to rg/ag."
(interactive) (interactive)
(let ((sym (thing-at-point 'symbol t))) (let ((sym (thing-at-point 'symbol t)))
(cond ((progn (cond ((progn
@ -69,14 +72,27 @@ Tries xref and falls back to `dumb-jump', then rg/ag."
(t (error "Couldn't find '%s'" sym))))) (t (error "Couldn't find '%s'" sym)))))
(defvar +jump--online-last-url nil)
;;;###autoload ;;;###autoload
(defun +jump/online (where &optional search) (defun +jump/online (where search)
"TODO" "Looks up SEARCH online, in you browser, as dictated by WHERE.
Interactively, you are prompted to choose a source from
`+jump-search-url-alist'."
(interactive (interactive
(list (completing-read "Search on: " (list (completing-read "Search on: "
(mapcar #'car +jump-search-url-alist) (mapcar #'cdr +jump-search-url-alist)
nil t))) nil t)
(let ((url (cdr (assoc where +jump-search-url-alist))) (or (and (not current-prefix-arg)
(search (or search (read-string "Query: ")))) +jump--online-last-url)
(thing-at-point 'symbol t))))
(let ((url (cdr (assoc where +jump-search-url-alist))))
(when (or (functionp url) (symbolp url))
(setq url (funcall url)))
(cl-assert (stringp url))
(cl-assert (not (string-empty-p url)))
(cl-assert (not (string-empty-p search)))
(setq +jump--online-last-url url)
(browse-url (format url (url-encode-url search))))) (browse-url (format url (url-encode-url search)))))

View file

@ -3,37 +3,35 @@
;; "What am I looking at?" ;; "What am I looking at?"
;; ;;
;; This module helps you answer that question. It helps you look up whatever ;; This module helps you answer that question. It helps you look up whatever
;; you're looking at, with: ;; you're looking at.
;; ;;
;; 1. A dwim Jump-to-definition functionality that "just works", with the help ;; + `+jump/definition': a jump-to-definition that should 'just work'
;; of `dumb-jump' and `xref'. ;; + `+jump/references': find a symbol's references in the current project
;; 2. A dwim interface to the new (and experimental) xref API built into Emacs. ;; + `+jump/online'; look up a symbol on online resources, like stackoverflow,
;; Once its API is more stable, backends could be written (or provided by ;; devdocs.io or google.
;; plugins) to create universal find-references and find-definition ;;
;; functionality. Warning: xref may change drastically in future updates. ;; This module uses `xref', an experimental new library in Emacs. It may change
;; 3. Simple ways to look up the symbol at point in external resources, like ;; in the future. When xref can't be depended on it will fall back to
;; stackoverflow, devdocs.io or google. See `+jump/online' (TODO Test me!) ;; `dumb-jump' to find what you want.
;; 4. TODO Automatic & transparent integration with cscope dbs + ctags.
;; Databases are optionally isolated to the Emacs environment.
(defvar +jump-search-url-alist (defvar +jump-search-url-alist
'(("Google" . "https://google.com/search?q=%s") '(("Google" . "https://google.com/search?q=%s")
("DuckDuckGo" . "https://duckduckgo.com/?q=%s") ("DuckDuckGo" . "https://duckduckgo.com/?q=%s")
("DevDocs.io" . "http://devdocs.io/#q=%s") ("DevDocs.io" . "http://devdocs.io/#q=%s")
("StackOverflow" . "https://stackoverflow.com/search?q=%s")) ("StackOverflow" . "https://stackoverflow.com/search?q=%s"))
"An alist that maps online resources to their search url. Used by "An alist that maps online resources to their search url or a function that
`+jump/online'.") produces an url. Used by `+jump/online'.")
(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) (def-setting! :xref-backend (mode function)
"TODO" "TODO"
`(add-hook! ,mode `(add-hook! ,mode
(add-hook 'xref-backend-functions #',function nil t))) (add-hook 'xref-backend-functions #',function nil t)))
(set! :popup "*xref*" :noselect t :autokill t :autoclose t)
;; Let me control what backends to fall back on
(setq-default xref-backend-functions '(t))
;; Recenter after certain jumps ;; Recenter after certain jumps
(add-hook! (add-hook!
'(imenu-after-jump-hook evil-jumps-post-jump-hook counsel-grep-post-action-hook) '(imenu-after-jump-hook evil-jumps-post-jump-hook counsel-grep-post-action-hook)
@ -47,6 +45,10 @@
(def-package! dumb-jump (def-package! dumb-jump
:commands (dumb-jump-go dumb-jump-quick-look dumb-jump-back) :commands (dumb-jump-go dumb-jump-quick-look dumb-jump-back)
:config :config
(setq dumb-jump-default-project doom-emacs-dir
dumb-jump-selector (cond ((featurep! :completion ivy) 'ivy)
((featurep! :completion helm) 'helm)
(t 'popup))))
(def-package! gxref (def-package! gxref

View file

@ -38,9 +38,8 @@
(ex! "git" #'magit-status) ; open magit status window (ex! "git" #'magit-status) ; open magit status window
(ex! "gstage" #'magit-stage) (ex! "gstage" #'magit-stage)
(ex! "gunstage" #'magit-unstage) (ex! "gunstage" #'magit-unstage)
;; TODO :gblame (ex! "gblame" #'magit-blame)
;; TODO :grevert (ex! "grevert" #'git-gutter:revert-hunk)
;; TODO :gblame
;; Dealing with buffers ;; Dealing with buffers
(ex! "clean[up]" #'doom/cleanup-buffers) (ex! "clean[up]" #'doom/cleanup-buffers)