Skip to content

Commit 1e69067

Browse files
author
DogLooksGood
committed
Add shim code for diff-hl
1 parent 1994d6b commit 1e69067

File tree

1 file changed

+51
-42
lines changed

1 file changed

+51
-42
lines changed

meow-shims.el

Lines changed: 51 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@
3131
(declare-function meow-motion-mode "meow")
3232
(declare-function meow-insert-exit "meow-command")
3333

34+
(defun meow--switch-to-motion (&rest _ignore)
35+
"Switch to motion state, used for advice.
36+
Optional argument IGNORE ignored."
37+
(meow--switch-state 'motion))
38+
39+
(defun meow--switch-to-normal (&rest _ignore)
40+
"Switch to normal state, used for advice.
41+
Optional argument IGNORE ignored."
42+
(meow--switch-state 'normal))
43+
3444
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3545
;; undo-tree
3646

@@ -95,22 +105,29 @@ Argument ENABLE non-nil means turn on."
95105
(add-hook 'meow-insert-exit-hook #'meow--company-maybe-abort-advice)
96106
(remove-hook 'meow-insert-exit-hook #'meow--company-maybe-abort-advice)))
97107

108+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
109+
;; repeat-map
110+
111+
(defvar meow--diff-hl-setup nil
112+
"Whether already setup diff-hl.")
113+
114+
(defun meow--setup-diff-hl (enable)
115+
"Setup diff-hl."
116+
(if enable
117+
(progn
118+
(advice-add 'diff-hl-show-hunk-inline-popup :before 'meow--switch-to-motion)
119+
(advice-add 'diff-hl-show-hunk-posframe :before 'meow--switch-to-motion)
120+
(advice-add 'diff-hl-show-hunk-hide :after 'meow--switch-to-normal))
121+
(advice-remove diff-hl-show-hunk-inline-popup 'meow--switch-to-motion)
122+
(advice-remove diff-hl-show-hunk-posframe 'meow--switch-to-motion)
123+
(advice-remove diff-hl-show-hunk-hide 'meow--switch-to-normal)))
124+
98125
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
99126
;; wgrep
100127

101128
(defvar meow--wgrep-setup nil
102129
"Whether already setup wgrep.")
103130

104-
(defun meow--wgrep-to-normal (&rest _ignore)
105-
"Switch to normal state, used in advice for wgrep.
106-
Optional argument IGNORE ignored."
107-
(meow--switch-state 'normal))
108-
109-
(defun meow--wgrep-to-motion (&rest _ignore)
110-
"Switch to motion state, used in advice for wgrep.
111-
Optional argument IGNORE ignored."
112-
(meow--switch-state 'motion))
113-
114131
(defun meow--setup-wgrep (enable)
115132
"Setup wgrep.
116133
@@ -119,14 +136,14 @@ Argument ENABLE non-nil means turn on."
119136
(setq meow--wgrep-setup enable)
120137
(if enable
121138
(progn
122-
(advice-add 'wgrep-change-to-wgrep-mode :after #'meow--wgrep-to-normal)
123-
(advice-add 'wgrep-exit :after #'meow--wgrep-to-motion)
124-
(advice-add 'wgrep-finish-edit :after #'meow--wgrep-to-motion)
125-
(advice-add 'wgrep-save-all-buffers :after #'meow--wgrep-to-motion))
126-
(advice-remove 'wgrep-change-to-wgrep-mode #'meow--wgrep-to-normal)
127-
(advice-remove 'wgrep-exit #'meow--wgrep-to-motion)
128-
(advice-remove 'wgrep-finish-edit #'meow--wgrep-to-motion)
129-
(advice-remove 'wgrep-save-all-buffers #'meow--wgrep-to-motion)))
139+
(advice-add 'wgrep-change-to-wgrep-mode :after #'meow--switch-to-normal)
140+
(advice-add 'wgrep-exit :after #'meow--switch-to-motion)
141+
(advice-add 'wgrep-finish-edit :after #'meow--switch-to-motion)
142+
(advice-add 'wgrep-save-all-buffers :after #'meow--switch-to-motion))
143+
(advice-remove 'wgrep-change-to-wgrep-mode #'meow--switch-to-normal)
144+
(advice-remove 'wgrep-exit #'meow--switch-to-motion)
145+
(advice-remove 'wgrep-finish-edit #'meow--switch-to-motion)
146+
(advice-remove 'wgrep-save-all-buffers #'meow--switch-to-motion)))
130147

131148
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
132149
;; wdired
@@ -140,31 +157,21 @@ Argument ENABLE non-nil means turn on."
140157
(declare-function wdired-finish-edit "wgrep")
141158
(declare-function wdired-abort-changes "wgrep")
142159

143-
(defun meow--wdired-enter (&rest _ignore)
144-
"Switch to normal state, used in hook for wdired.
145-
Optional argument IGNORE ignored."
146-
(meow--switch-state 'normal))
147-
148-
(defun meow--wdired-exit (&rest _ignore)
149-
"Switch to motion state, used in advice for wdired.
150-
Optional argument IGNORE ignored."
151-
(meow--switch-state 'motion))
152-
153160
(defun meow--setup-wdired (enable)
154161
"Setup wdired.
155162
156163
Argument ENABLE non-nil means turn on."
157164
(setq meow--wdired-setup enable)
158165
(if enable
159166
(progn
160-
(add-hook 'wdired-mode-hook #'meow--wdired-enter)
161-
(advice-add #'wdired-exit :after #'meow--wdired-exit)
162-
(advice-add #'wdired-abort-changes :after #'meow--wdired-exit)
163-
(advice-add #'wdired-finish-edit :after #'meow--wdired-exit))
164-
(remove-hook 'wdired-mode-hook #'meow--wdired-enter)
165-
(advice-remove #'wdired-exit #'meow--wdired-exit)
166-
(advice-remove #'wdired-abort-changes #'meow--wdired-exit)
167-
(advice-remove #'wdired-finish-edit #'meow--wdired-exit)))
167+
(add-hook 'wdired-mode-hook #'meow--switch-to-normal)
168+
(advice-add #'wdired-exit :after #'meow--switch-to-motion)
169+
(advice-add #'wdired-abort-changes :after #'meow--switch-to-motion)
170+
(advice-add #'wdired-finish-edit :after #'meow--switch-to-motion))
171+
(remove-hook 'wdired-mode-hook #'meow--switch-to-normal)
172+
(advice-remove #'wdired-exit #'meow--switch-to-motion)
173+
(advice-remove #'wdired-abort-changes #'meow--switch-to-motion)
174+
(advice-remove #'wdired-finish-edit #'meow--switch-to-motion)))
168175

169176
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
170177
;; rectangle-mark-mode
@@ -194,8 +201,8 @@ Argument ENABLE non-nil means turn on."
194201
(defun meow--edebug-hook-function ()
195202
"Switch meow state when entering/leaving edebug."
196203
(if (bound-and-true-p edebug-mode)
197-
(meow--switch-state 'motion)
198-
(meow--switch-state 'normal)))
204+
(meow--switch-to-motion)
205+
(meow--switch-to-normal)))
199206

200207
(defun meow--setup-edebug (enable)
201208
"Setup edebug.
@@ -213,8 +220,8 @@ Argument ENABLE non-nil means turn on."
213220
(defun meow--cider-debug-hook-function ()
214221
"Switch meow state when entering/leaving cider debug."
215222
(if (bound-and-true-p cider--debug-mode)
216-
(meow--switch-state 'motion)
217-
(meow--switch-state 'normal)))
223+
(meow--switch-to-motion)
224+
(meow--switch-to-normal)))
218225

219226
(defun meow--setup-cider (enable)
220227
"Setup cider.
@@ -284,7 +291,8 @@ Argument ENABLE non-nil means turn on."
284291
(eval-after-load "polymode" (lambda () (meow--setup-polymode t)))
285292
(eval-after-load "cider" (lambda () (meow--setup-cider t)))
286293
(eval-after-load "which-key" (lambda () (meow--setup-which-key t)))
287-
(eval-after-load "undo-tree" (lambda () (meow--setup-undo-tree t))))
294+
(eval-after-load "undo-tree" (lambda () (meow--setup-undo-tree t)))
295+
(eval-after-load "diff-hl" (lambda () (meow--setup-diff-hl t))))
288296

289297
(defun meow--disable-shims ()
290298
"Remove shim setups."
@@ -297,7 +305,8 @@ Argument ENABLE non-nil means turn on."
297305
(when meow--wgrep-setup (meow--setup-wgrep nil))
298306
(when meow--polymode-setup (meow--setup-polymode nil))
299307
(when meow--cider-setup (meow--setup-cider nil))
300-
(when meow--which-key-setup (meow--setup-which-key nil)))
308+
(when meow--which-key-setup (meow--setup-which-key nil))
309+
(when meow--diff-hl-setup (meow--setup-diff-hl nil)))
301310

302311
;;; meow-shims.el ends here
303312
(provide 'meow-shims)

0 commit comments

Comments
 (0)