forked from edani/ensime-emacs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ensime-undo.el
97 lines (78 loc) · 2.81 KB
/
ensime-undo.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
;;; ensime-undo.el
;;
;;;; License
;;
;; Copyright (C) 2010 Aemon Cannon
;;
;; 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 2 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, write to the Free
;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
;; MA 02111-1307, USA.
(eval-when-compile
(require 'cl)
(require 'ensime-macros))
(defvar ensime-undo-info-buffer-name "*ENSIME-Undo*")
(defvar ensime-undo-info-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "c") (lambda()(interactive)
(funcall continue-undo)
(ensime-popup-buffer-quit-function)
))
(define-key map (kbd "q") (lambda()(interactive)
(funcall cancel-undo)
(ensime-popup-buffer-quit-function)
))
map)
"Key bindings for the undo confirmation popup.")
(defun ensime-undo-peek ()
"Get rid of an intermediate variable."
(interactive)
(let ((undo (ensime-rpc-peek-undo)))
(destructuring-bind (&key id summary changes) undo
(let ((cont `(lambda ()
(ensime-undo-exec ,id)))
(cancel `(lambda ())))
(ensime-with-popup-buffer
(ensime-undo-info-buffer-name t t)
;; Override ensime-popup-buffer-mode's normal keymap
;; because of "q"
(add-to-list
'minor-mode-overriding-map-alist
(cons 'ensime-popup-buffer-mode ensime-undo-info-map))
(set (make-local-variable 'cancel-undo) cancel)
(set (make-local-variable 'continue-undo) cont)
(ensime-undo-populate-confirmation-buffer
summary changes)
(goto-char (point-min)))))))
(defun ensime-undo-exec (id)
(let* ((result (ensime-rpc-exec-undo id))
(touched (plist-get result :touched-files)))
(ensime-revert-visited-files touched t)))
(defun ensime-undo-populate-confirmation-buffer (summary changes)
(ensime-insert-with-face "Proposed undo of "
'font-lock-constant-face)
(ensime-insert-with-face (concat "\"" summary "\"")
'font-lock-variable-name-face)
(ensime-insert-with-face " would cause the following changes."
'font-lock-constant-face)
(ensime-insert-with-face
" (c to confirm, q to cancel)"
'font-lock-constant-face)
(insert "\n\n\n")
(if (null changes)
(insert "Nothing to be done.")
(ensime-insert-change-list changes))
)
(provide 'ensime-undo)
;; Local Variables:
;; End: