From 45a17c86ba44294b5d96da1bf371138425bdadf3 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 20 Oct 2019 15:15:03 -0400 Subject: [PATCH] Add +ivy/jump-list & bind 'SPC b j' to it Falls back to evil-show-jumps for non-evil users. --- modules/completion/ivy/autoload/ivy.el | 42 ++++++++++++++++++++++++ modules/completion/ivy/config.el | 3 +- modules/config/default/+evil-bindings.el | 1 + 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/modules/completion/ivy/autoload/ivy.el b/modules/completion/ivy/autoload/ivy.el index 95708acd7..4bbb9aa23 100644 --- a/modules/completion/ivy/autoload/ivy.el +++ b/modules/completion/ivy/autoload/ivy.el @@ -487,3 +487,45 @@ If ALL-FILES-P, search compressed and hidden files as well." "Execute a compile command from the current project's root." (interactive) (counsel-compile (projectile-project-root))) + + +;;;###autoload +(defun +ivy/jump-list () + "Go to an entry in evil's (or better-jumper's) jumplist." + (interactive) + ;; REVIEW Refactor me + (let (buffers) + (unwind-protect + (ivy-read "jumplist: " + (nreverse + (delete-dups + (delq + nil + (mapcar (lambda (mark) + (when mark + (cl-destructuring-bind (path pt _id) mark + (let ((buf (get-file-buffer path))) + (unless buf + (push (setq buf (find-file-noselect path t)) + buffers)) + (with-current-buffer buf + (goto-char pt) + (font-lock-fontify-region (line-beginning-position) (line-end-position)) + (cons (format "%s:%d: %s" + (buffer-name) + (line-number-at-pos) + (string-trim-right (thing-at-point 'line))) + (point-marker))))))) + (cddr (better-jumper-jump-list-struct-ring + (better-jumper-get-jumps (better-jumper--get-current-context)))))))) + :sort nil + :require-match t + :action (lambda (cand) + (let ((mark (cdr cand))) + (delq! (marker-buffer mark) buffers) + (mapc #'kill-buffer buffers) + (setq buffers nil) + (with-current-buffer (switch-to-buffer (marker-buffer mark)) + (goto-char (marker-position mark))))) + :caller '+ivy/jump-list) + (mapc #'kill-buffer buffers)))) diff --git a/modules/completion/ivy/config.el b/modules/completion/ivy/config.el index b520da79f..4103aa421 100644 --- a/modules/completion/ivy/config.el +++ b/modules/completion/ivy/config.el @@ -110,7 +110,8 @@ evil-ex-specific constructs, so we disable it solely in evil-ex." (define-key! ivy-mode-map [remap switch-to-buffer] #'+ivy/switch-buffer [remap switch-to-buffer-other-window] #'+ivy/switch-buffer-other-window - [remap persp-switch-to-buffer] #'+ivy/switch-workspace-buffer) + [remap persp-switch-to-buffer] #'+ivy/switch-workspace-buffer + [remap evil-show-jumps] #'+ivy/jump-list) (define-key ivy-minibuffer-map (kbd "C-c C-e") #'+ivy/woccur) diff --git a/modules/config/default/+evil-bindings.el b/modules/config/default/+evil-bindings.el index 6c9ab0932..c6d096484 100644 --- a/modules/config/default/+evil-bindings.el +++ b/modules/config/default/+evil-bindings.el @@ -598,6 +598,7 @@ :desc "Kill buffer" "d" #'kill-current-buffer :desc "ibuffer" "i" #'ibuffer :desc "Kill buffer" "k" #'kill-current-buffer + :desc "Jumplist" "j" #'evil-show-jumps :desc "Switch to last buffer" "l" #'evil-switch-to-windows-last-buffer :desc "Next buffer" "n" #'next-buffer :desc "New empty buffer" "N" #'evil-buffer-new