-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypewriter.el
44 lines (39 loc) · 1.46 KB
/
typewriter.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
(defvar tw-ignored-commands '(mouse-drag-region
mouse-set-region
mouse-set-point
widget-button-click
scroll-bar-toolkit-scroll)
"After these commands recentering is ignored.
This is to prevent unintentional jumping (especially when mouse
clicking). Following commands (except the ignored ones) will
cause an animated recentering to give a feedback and not just
jumping to the center."
)
(defun tw-ignored-command-p ()
"Check if the last command was one listed in TW-IGNORED-COMMANDS."
(member this-command tw-ignored-commands))
(defun tw-mouse-drag-movement-p ()
"Check if the last input event corresponded to a mouse drag event."
(mouse-movement-p last-command-event))
(defvar tw-inhibit-centering-when '(tw-ignored-command-p
tw-mouse-drag-movement-p))
(defun line-change ()
(unless (seq-some #'funcall tw-inhibit-centering-when)
(recenter)))
(define-minor-mode typewriter-mode
"Makes the cursor stay vertically in a defined
position (usually centered). Remaps mouse wheel
to C-n and C-p which makes scrolling through visual
lines a breeze."
:init-value nil
:lighter " ☯"
:keymap
'(
([wheel-up] . previous-line)
([wheel-down] . next-line))
(cond
(typewriter-mode
(add-hook 'post-command-hook 'line-change t t))
(t
(remove-hook 'post-command-hook 'line-change t))))
(provide 'typewriter-mode)