Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make undo-tree an optional dependency #1360

Merged
merged 8 commits into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cask
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
(files "*.el")

;; (depends-on "goto-chg" "0.6.3")
;; (depends-on "undo-tree" "1.6")
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ file.

* Evil requires Emacs 24.1 or later.

* Evil requires [undo-tree.el](http://www.emacswiki.org/emacs/UndoTree) in the
`load-path` for linear undo and undo branches.
* Evil requires any of the following for `C-r`:
** `undo-redo` from Emacs 28
** The [undo-tree](http://www.emacswiki.org/emacs/UndoTree) package
** The [undo-fu](https://gitlab.com/ideasman42/emacs-undo-fu) package

* For the motions `g;` `g,` and for the last-change-register `.`, Evil requires the
[goto-chg.el](https://github.com/emacs-evil/goto-chg) package,
Expand Down
2 changes: 1 addition & 1 deletion doc/build/texinfo/evil.texi
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ Finally, add the following lines to your Emacs init file:
@section Manual installation


First, install @cite{undo-tree}, @cite{goto-chg} and @cite{cl-lib}. If you have an
First, install @cite{goto-chg} and @cite{cl-lib}. If you have an
Emacs version of 24.3 or newer, you should already have @cite{cl-lib}.

Evil lives in a git repository. To download Evil, do:
Expand Down
4 changes: 2 additions & 2 deletions doc/source/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ Finally, add the following lines to your Emacs init file:
Manual installation
-------------------

First, install `undo-tree`, `goto-chg` and `cl-lib`. If you have an
Emacs version of 24.3 or newer, you should already have `cl-lib`.
First, install `goto-chg` and `cl-lib`. If you have an Emacs version
of 24.3 or newer, you should already have `cl-lib`.

Evil lives in a git repository. To download Evil, do::

Expand Down
18 changes: 18 additions & 0 deletions evil-commands.el
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
(require 'evil-types)
(require 'evil-command-window)
(require 'evil-jumps)
(require 'evil-vars)
(require 'flyspell)
(require 'cl-lib)
(require 'reveal)
Expand Down Expand Up @@ -1620,6 +1621,23 @@ of the block."
(when (evil-visual-state-p)
(move-marker evil-visual-point (point)))))

(defun evil--check-undo-system ()
(when (and (eq evil-undo-system 'undo-tree)
(not (bound-and-true-p undo-tree-mode)))
(user-error "Enable `global-undo-tree-mode' to use undo-tree commands.")))

(evil-define-command evil-undo (count)
"Undo COUNT changes in buffer using `evil-undo-function'."
(interactive "*p")
(evil--check-undo-system)
(funcall evil-undo-function count))

(evil-define-command evil-redo (count)
"Undo COUNT changes in buffer using `evil-redo-function'."
(interactive "*p")
(evil--check-undo-system)
(funcall evil-redo-function count))

(evil-define-operator evil-substitute (beg end type register)
"Change a character."
:motion evil-forward-char
Expand Down
15 changes: 0 additions & 15 deletions evil-integration.el
Original file line number Diff line number Diff line change
Expand Up @@ -139,23 +139,8 @@
(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.
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
Expand Down
6 changes: 4 additions & 2 deletions evil-maps.el
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@
(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)
(define-key evil-normal-state-map "u" 'evil-undo)
(define-key evil-normal-state-map "\C-r" 'evil-redo)

;; window commands
(define-prefix-command 'evil-window-map)
Expand Down Expand Up @@ -517,6 +517,8 @@ included in `evil-insert-state-bindings' by default."
(evil-ex-define-cmd "show-digraphs" 'evil-ex-show-digraphs)
(evil-ex-define-cmd "sor[t]" 'evil-ex-sort)
(evil-ex-define-cmd "res[ize]" 'evil-ex-resize)
(evil-ex-define-cmd "u[ndo]" 'evil-undo)
(evil-ex-define-cmd "red[o]" 'evil-redo)

(when (featurep 'tab-bar)
(evil-ex-define-cmd "tabnew" 'tab-bar-new-tab)
Expand Down
1 change: 0 additions & 1 deletion evil-pkg.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
"1.14.0"
"Extensible Vi layer for Emacs."
'((emacs "24.1")
(undo-tree "0.7.4")
(goto-chg "1.6")
(cl-lib "0.5")))
1 change: 0 additions & 1 deletion evil-test-helpers.el
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ raised. Remaining forms are evaluated as-is.
;; necessary for keyboard macros to work
(switch-to-buffer-other-window (current-buffer))
(buffer-enable-undo)
(undo-tree-mode 1)
;; parse remaining forms
,@(mapcar
#'(lambda (form)
Expand Down
40 changes: 40 additions & 0 deletions evil-vars.el
Original file line number Diff line number Diff line change
Expand Up @@ -1971,6 +1971,46 @@ This variable must be set before evil is loaded."
(add-hook 'minibuffer-setup-hook 'evil-initialize)
(remove-hook 'minibuffer-setup-hook 'evil-initialize))))

(defun evil--redo-placeholder (_count)
(user-error "Customize `evil-undo-system' for redo functionality."))

(defvar evil-undo-function 'undo
"Function to be used by `evil-undo'.
Customized via `evil-undo-system'.")

(defvar evil-redo-function 'evil--redo-placeholder
"Function to be used by 'evil-redo'.
Customized via `evil-undo-system'.")

(defun evil-set-undo-system (system)
"Set `evil-undo-function' and `evil-redo-function` by SYSTEM."
(cond
((not system)
(setq evil-undo-function 'undo
evil-redo-function 'evil--redo-placeholder))
((eq system 'undo-redo)
(setq evil-undo-function 'undo-only
evil-redo-function 'undo-redo))
((eq system 'undo-tree)
(setq evil-undo-function 'undo-tree-undo
evil-redo-function 'undo-tree-redo))
((eq system 'undo-fu)
(setq evil-undo-function 'undo-fu-only-undo
evil-redo-function 'undo-fu-only-redo))
(t
(error "Unknown undo system %s" system))))

(defcustom evil-undo-system nil
"Undo system Evil should use."
:type '(choice (const :tag "Vanilla undo" nil)
(const undo-redo)
(const undo-tree)
(const undo-fu))
:group 'evil
:set #'(lambda (sym value)
(evil-set-undo-system value)
(set-default sym value)))

(defun evil-version ()
(interactive)
(message "Evil version %s" evil-version))
Expand Down
7 changes: 2 additions & 5 deletions evil.el
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,8 @@
;; (require 'evil)
;; (evil-mode 1)
;;
;; Evil requires undo-tree.el for linear undo and undo branches:
;;
;; http://www.emacswiki.org/emacs/UndoTree
;;
;; Otherwise, Evil uses regular Emacs undo.
;; Evil requires undo-redo (Emacs 28), undo-fu or undo-tree for redo
;; functionality. Otherwise, Evil uses regular Emacs undo.
;;
;; Evil requires `goto-last-change' and `goto-last-change-reverse'
;; function for the corresponding motions g; g, as well as the
Expand Down
Loading