Skip to content

Commit

Permalink
Add option to switch to undo-fu
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBB committed Dec 30, 2019
1 parent 30e951f commit 54278f2
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 48 deletions.
92 changes: 46 additions & 46 deletions evil-integration.el
Original file line number Diff line number Diff line change
Expand Up @@ -139,55 +139,55 @@
(when (overlayp ov) (delete-overlay ov))))))))

;;; Undo tree
(when (and (require 'undo-tree nil t)
(fboundp 'global-undo-tree-mode))
(global-undo-tree-mode 1))

(eval-after-load 'undo-tree
'(with-no-warnings
(defun evil-turn-on-undo-tree-mode ()
"Enable `undo-tree-mode' if evil is enabled.
(when (eq 'undo-tree evil-undo-provider)
(when (and (require 'undo-tree nil t)
(fboundp 'global-undo-tree-mode))
(global-undo-tree-mode 1))
(eval-after-load 'undo-tree
'(with-no-warnings
(defun evil-turn-on-undo-tree-mode ()
"Enable `undo-tree-mode' if evil is enabled.
This function enables `undo-tree-mode' when Evil is activated in
some buffer, but only if `global-undo-tree-mode' is also
activated."
(when (and (boundp 'global-undo-tree-mode)
global-undo-tree-mode)
(turn-on-undo-tree-mode)))

(add-hook 'evil-local-mode-hook #'evil-turn-on-undo-tree-mode)

(defadvice undo-tree-visualize (after evil activate)
"Initialize Evil in the visualization buffer."
(when evil-local-mode
(evil-initialize-state)))

(when (fboundp 'undo-tree-visualize)
(evil-ex-define-cmd "undol[ist]" 'undo-tree-visualize)
(evil-ex-define-cmd "ul" 'undo-tree-visualize))

(when (boundp 'undo-tree-visualizer-mode-map)
(define-key undo-tree-visualizer-mode-map
[remap evil-backward-char] 'undo-tree-visualize-switch-branch-left)
(define-key undo-tree-visualizer-mode-map
[remap evil-forward-char] 'undo-tree-visualize-switch-branch-right)
(define-key undo-tree-visualizer-mode-map
[remap evil-next-line] 'undo-tree-visualize-redo)
(define-key undo-tree-visualizer-mode-map
[remap evil-previous-line] 'undo-tree-visualize-undo)
(define-key undo-tree-visualizer-mode-map
[remap evil-ret] 'undo-tree-visualizer-set))

(when (boundp 'undo-tree-visualizer-selection-mode-map)
(define-key undo-tree-visualizer-selection-mode-map
[remap evil-backward-char] 'undo-tree-visualizer-select-left)
(define-key undo-tree-visualizer-selection-mode-map
[remap evil-forward-char] 'undo-tree-visualizer-select-right)
(define-key undo-tree-visualizer-selection-mode-map
[remap evil-next-line] 'undo-tree-visualizer-select-next)
(define-key undo-tree-visualizer-selection-mode-map
[remap evil-previous-line] 'undo-tree-visualizer-select-previous)
(define-key undo-tree-visualizer-selection-mode-map
[remap evil-ret] 'undo-tree-visualizer-set))))
(when (and (boundp 'global-undo-tree-mode)
global-undo-tree-mode)
(turn-on-undo-tree-mode)))

(add-hook 'evil-local-mode-hook #'evil-turn-on-undo-tree-mode)

(defadvice undo-tree-visualize (after evil activate)
"Initialize Evil in the visualization buffer."
(when evil-local-mode
(evil-initialize-state)))

(when (fboundp 'undo-tree-visualize)
(evil-ex-define-cmd "undol[ist]" 'undo-tree-visualize)
(evil-ex-define-cmd "ul" 'undo-tree-visualize))

(when (boundp 'undo-tree-visualizer-mode-map)
(define-key undo-tree-visualizer-mode-map
[remap evil-backward-char] 'undo-tree-visualize-switch-branch-left)
(define-key undo-tree-visualizer-mode-map
[remap evil-forward-char] 'undo-tree-visualize-switch-branch-right)
(define-key undo-tree-visualizer-mode-map
[remap evil-next-line] 'undo-tree-visualize-redo)
(define-key undo-tree-visualizer-mode-map
[remap evil-previous-line] 'undo-tree-visualize-undo)
(define-key undo-tree-visualizer-mode-map
[remap evil-ret] 'undo-tree-visualizer-set))

(when (boundp 'undo-tree-visualizer-selection-mode-map)
(define-key undo-tree-visualizer-selection-mode-map
[remap evil-backward-char] 'undo-tree-visualizer-select-left)
(define-key undo-tree-visualizer-selection-mode-map
[remap evil-forward-char] 'undo-tree-visualizer-select-right)
(define-key undo-tree-visualizer-selection-mode-map
[remap evil-next-line] 'undo-tree-visualizer-select-next)
(define-key undo-tree-visualizer-selection-mode-map
[remap evil-previous-line] 'undo-tree-visualizer-select-previous)
(define-key undo-tree-visualizer-selection-mode-map
[remap evil-ret] 'undo-tree-visualizer-set)))))

;;; Auto-complete
(eval-after-load 'auto-complete
Expand Down
10 changes: 8 additions & 2 deletions evil-maps.el
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
(define-key evil-normal-state-map [remap cua-paste-pop] 'evil-paste-pop)
(define-key evil-normal-state-map [remap yank-pop] 'evil-paste-pop)


(when (featurep 'tab-bar)
(define-key evil-normal-state-map "gt" 'tab-bar-switch-to-next-tab)
(define-key evil-normal-state-map "gT" 'tab-bar-switch-to-prev-tab))
Expand All @@ -111,8 +112,13 @@
(define-key evil-normal-state-map "g," 'goto-last-change-reverse)

;; undo
(define-key evil-normal-state-map "u" 'undo)
(define-key evil-normal-state-map "\C-r" 'redo)
(if (eq 'undo-fu evil-undo-provider)
(progn
(require 'undo-fu)
(define-key evil-normal-state-map "u" 'undo-fu-only-undo)
(define-key evil-normal-state-map (kbd "C-r") 'undo-fu-only-redo))
(define-key evil-normal-state-map "u" 'undo)
(define-key evil-normal-state-map "\C-r" 'redo))

;; window commands
(define-prefix-command 'evil-window-map)
Expand Down
6 changes: 6 additions & 0 deletions evil-vars.el
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,12 @@ work consistently."
(const :tag "Yes" :value t))
:group 'evil)

(defcustom evil-undo-provider 'undo-tree
"Which package should provide undo functionality.
Should be either `undo-tree' or `undo-fu'."
:type '(radio (const :tag "Undo-tree" :value undo-tree)
(const :tag "Undo-fu" :value undo-fu)))

(defcustom evil-regexp-search t
"Whether to use regular expressions for searching in \\[/] and \\[?]."
:type 'boolean
Expand Down

0 comments on commit 54278f2

Please sign in to comment.