[vim] add evil-better-jumper layer

https://github.com/gilbertw1/better-jumper
This commit is contained in:
Thanh Vuong 2020-09-21 12:52:18 -06:00 committed by Maximilian Wolff
parent d2e9730acb
commit 72807f3ef2
3 changed files with 125 additions and 0 deletions

View File

@ -0,0 +1,31 @@
#+TITLE: evil-better-jumper layer
#+TAGS: layer|vim
* Table of Contents :TOC_4_gh:noexport:
- [[#description][Description]]
- [[#features][Features:]]
- [[#install][Install]]
- [[#key-bindings][Key bindings]]
* Description
This layer adds support for [[https://github.com/gilbertw1/better-jumper][better-jumper]]. A configurable jump list
implementation for Emacs that can be used to easily jump back to previous
locations.
** Features:
- jump back and forth
* Install
To use this configuration layer, add it to your =~/.spacemacs=. You will need to
add =evil-better-jumper= to the existing =dotspacemacs-configuration-layers=
list in this file.
* Key bindings
| Key Binding | Description |
|-------------+-----------------------------|
| ~C-o~ | better-jumper-jump-backward |
| ~C-i~ | better-jumper-jump-forward |

View File

@ -0,0 +1,49 @@
;;; funcs.el --- evil-better-jumper Layer Functions File for spacemacs
;;
;; Copyright (c) 2012-2021 Sylvain Benner & Contributors
;;
;; Author: Thanh Vuong <thanh@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(defun evil-better-jumper/set-jump-a (orig-fn &rest args)
"Set a jump point and ensure ORIG-FN doesn't set any new jump points."
(better-jumper-set-jump (if (markerp (car args)) (car args)))
(let ((evil--jumps-jumping t)
(better-jumper--jumping t))
(apply orig-fn args)))
(defun evil-better-jumper/set-jump-maybe-a (orig-fn &rest args)
"Set a jump point if ORIG-FN returns non-nil."
(let ((origin (point-marker))
(result
(let* ((evil--jumps-jumping t)
(better-jumper--jumping t))
(apply orig-fn args))))
(unless result
(with-current-buffer (marker-buffer origin)
(better-jumper-set-jump
(if (markerp (car args))
(car args)
origin))))
result))
(defun evil-better-jumper/set-jump-h ()
"Run `better-jumper-set-jump' but return nil, for short-circuiting hooks."
(better-jumper-set-jump)
nil)

View File

@ -0,0 +1,45 @@
;;; packages.el --- evil-better-jumper Layer Packages File for Spacemacs.
;;
;; Copyright (c) 2012-2021 Sylvain Benner & Contributors
;;
;; Author: Thanh Vuong <thanh@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(defconst evil-better-jumper-packages
'(better-jumper)
"The list of Lisp packages required by the evil-better-jumper layer.")
(defun evil-better-jumper/init-better-jumper ()
(use-package better-jumper
:init
(global-set-key [remap evil-jump-forward] #'better-jumper-jump-forward)
(global-set-key [remap evil-jump-backward] #'better-jumper-jump-backward)
(global-set-key [remap xref-pop-marker-stack] #'better-jumper-jump-backward)
:config
(better-jumper-mode 1)
(spacemacs|hide-lighter better-jumper-mode)
(spacemacs|hide-lighter better-jumper-local-mode))
;; Creates a jump point before killing a buffer. This allows you to undo
;; killing a buffer easily (only works with file buffers though; it's not
;; possible to resurrect special buffers).
(advice-add #'kill-current-buffer :around #'evil-better-jumper/set-jump-a)
;; Create a jump point before jumping with imenu.
(advice-add #'imenu :around #'evil-better-jumper/set-jump-a))